A Stack Overflow self-answer, where I discover that the callback based handlers
module.exports = function(event, context, callback) {
//..
callback(null, 'my response')
}
do not return immediately upon calling the callback. In fact, the callback has nothing to do with when these functions will return.
When AWS Lambda runs your function it
- Runs the code in your handler
- Waits until everything’s been processed in the event loop
- And then sends a response to whatever wanted to invoke the Lambda
The tricky part is “everything” might be actually be everything. Any unref
ed callback isn’t considered, which can create some confusing scenarios.