assertible / lambda-cloudwatch-slack

Send AWS CloudWatch notifications to a Slack channel using Lambda
https://assertible.com/blog/npm-package-lambda-cloudwatch-slack
MIT License
482 stars 249 forks source link

Invoke Error #55

Closed 23ewrdtf closed 4 years ago

23ewrdtf commented 4 years ago

Hi,

When I run the npm run deploy I got below error:

message: The runtime parameter of nodejs8.10 is no longer supported for creating or updating AWS Lambda functions. We recommend you use the new runtime (nodejs12.x) while creating or updating functions.

So I run npm install node-lambda@latest and deploy was successful.

Now when I send a test message to subscription I get below error in Lambda:

2020-04-01T10:46:49.840Z    xxxxxxxxxxxxxxxxxxxxx   INFO    sns received:
{
    "Records": [
        {
            "EventSource": "aws:sns",
            "EventVersion": "1.0",
            "EventSubscriptionArn": "xxx",
            "Sns": {
                "Type": "Notification",
                "MessageId": "xxxxx",
                "TopicArn": "xxx",
                "Subject": "test",
                "Message": "test",
                "Timestamp": "2020-04-01T10:43:53.616Z",
                "SignatureVersion": "1",
                "Signature": "xxxxxx",
                "SigningCertUrl": "xxx",
                "UnsubscribeUrl": "xxx",
                "MessageAttributes": {}
            }
        }
    ]
}
2020-04-01T10:46:49.841Z    xxxxx   ERROR   Invoke Error    
{
    "errorType": "SyntaxError",
    "errorMessage": "Unexpected token e in JSON at position 1",
    "stack": [
        "SyntaxError: Unexpected token e in JSON at position 1",
        "    at JSON.parse (<anonymous>)",
        "    at handleCatchAll (/var/task/index.js:319:24)",
        "    at processEvent (/var/task/index.js:395:20)",
        "    at Runtime.exports.handler (/var/task/index.js:415:5)",
        "    at Runtime.handleOnce (/var/runtime/Runtime.js:66:25)"
    ]
}
mvillumsen commented 4 years ago

I just ran into the same error while testing the function. The stack trace tells you, that the error occurs in index.js:319 (see https://github.com/assertible/lambda-cloudwatch-slack/blob/master/index.js#L319)

The code tried to parse the message as json but what you are sending is text. Try sending a test message in valid json instead.