On the first line after your functions module definition, add the following line
context.callbackWaitsForEmptyEventLoop = false;
callbackWaitsForEmptyEventLoop
- The default value is true
- Useful only to modify the default behavior of the callback.
You can set this property to false to request AWS Lambda to freeze the process soon after the callback is called, even if there are events in the event loop. AWS Lambda will freeze the process, any state data and the events in the Node.js event loop (any remaining events in the event loop processed when the Lambda function is called next and if AWS Lambda chooses to use the frozen process)
More details read this article