Why does AWS Lambda function return null?

Question:

My AWS Lambda function sends an email through SNS, but the response is null in the Lambda console. I used a blueprint provided by AWS and put the code in a Lambda handler using Node.js 10.x.

https://github.com/awsdocs/aws-doc-sdk-examples/blob/master/javascript/example_code/sns/sns_publishtotopic.js

I am not that experienced in the use of promises in node.js and my research on Stack Overflow seems to indicate that could be the problem here.

The result is that I receive the email message inconsistently and see a null response in the Lambda console. Here is a sample log result:

Answer:

Your lambda is exiting before completing the promise. To circumvent this you can use async-await:

OR, You can return the promise, return publishTextPromise.then(...).catch(...)

Leave a Reply