Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: record.Sns.Message is not necessarily an object #38

Open
gabauer opened this issue Mar 7, 2019 · 0 comments
Open

Bug: record.Sns.Message is not necessarily an object #38

gabauer opened this issue Mar 7, 2019 · 0 comments

Comments

@gabauer
Copy link

gabauer commented Mar 7, 2019

How to produces:

Goto AWS SNS -> Topic -> public a message

The message looks like:

{
    "Records": [
        {
            "EventSource": "aws:sns",
            "EventVersion": "1.0",
            "EventSubscriptionArn": "arn:aws:sns:XXXXXXXXXXXXXXX-monitoring:9b9asdff5-be7f-safa-958a-000000000000",
            "Sns": {
                "Type": "Notification",
                "MessageId": "318b60f7-fae6sdfd-5fasd93-ae63-XXXXXXXXXX",
                "TopicArn": "arn:aws:sns:XXXXXXXXXXXXXX-monitoring",
                "Subject": "Test - AWS Cloudwatch - Lamda",
                "Message": "Test - AWS Cloudwatch - Lamda",
                "Timestamp": "2019-03-07T07:00:50.306Z",
                "SignatureVersion": "1",
                "Signature": "Kmdfh5Lr5LpBeTXgZJRdPHohmHRdQn6NmXXXXXXXXXXXXXXXXXXXXXXXXXxthnjHorUS+BNbW9892imFRcH==",
                "SigningCertUrl": "https://sns.XXXXXXXXXXX.pem",
                "UnsubscribeUrl": "https://sns.XXXXXXXXXXX958a-a3sd12jf4l3ka4s8d",
                "MessageAttributes": {}
            }
        }
    ]
}

Records[0].Sns.Message is no object in this case and JSON.parse fails here:

index.js:319  var message = JSON.parse(record.Sns.Message)

How to fix (one way):

Check if Records[0].Sns.Message is a object:

index.js:319 var message = typeof record.Sns.Message === 'object' 
index.js:320                ? JSON.parse(record.Sns.Message)
index.js:321                : { message: record.Sns.Message}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant