Recent Posts


Returning from a Callback Based AWS Lambda Handler


Frustrated by Magento? Then you’ll love Commerce Bug, the must have debugging extension for anyone using Magento. Whether you’re just starting out or you’re a seasoned pro, Commerce Bug will save you and your team hours everyday. Grab a copy and start working with Magento instead of against it.

Updated for Magento 2! No Frills Magento Layout is the only Magento front end book you'll ever need. Get your copy today!

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

  1. Runs the code in your handler
  2. Waits until everything’s been processed in the event loop
  3. And then sends a response to whatever wanted to invoke the Lambda

The tricky part is “everything” might be actually be everything. Any unrefed callback isn’t considered, which can create some confusing scenarios.

Copyright © Alan Storm 1975 – 2023 All Rights Reserved

Originally Posted: 23rd July 2021