You have a typo:

context.callbackWaitsForEmtpyEventLoop = false;

should be:

context.callbackWaitsForEmptyEventLoop = false;

Here's what the documentation says about the behavior of callbackWaitsForEmptyEventLoop:

callbackWaitsForEmptyEventLoop

The default value is true. This property is useful only to modify the default behavior of the callback. By default, the callback will wait until the Node.js runtime event loop is empty before freezing the process and returning the results to the caller. 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). For more information about callback, see Using the Callback Parameter.

Minimal example:

// Times out due to typo
exports.function1 = (event, context, callback) => {
    setInterval(() => console.log('Long wait'), 100000);
    context.callbackWaitsForEmtpyEventLoop = false;
    callback(null, 'Hello from Lambda');
};

// Returns successfully
exports.function2 = (event, context, callback) => {
    setInterval(() => console.log('Long wait'), 100000);
    context.callbackWaitsForEmptyEventLoop = false;
    callback(null, 'Hello from Lambda');
};
Answer from wjordan on Stack Overflow
🌐
Amazon Web Services
docs.aws.amazon.com › aws lambda › developer guide › building lambda functions with typescript › using the lambda context object to retrieve typescript function information
Using the Lambda context object to retrieve TypeScript function information - AWS Lambda
callbackWaitsForEmptyEventLoop – By default (true), when using a callback-based function handler, Lambda waits for the event loop to be empty after the callback runs before ending the function invoke. Set to false to send the response and end the invoke immediately after the callback runs ...
🌐
Serverless Forums
forum.serverless.com › serverless architectures
callbackWaitsForEmptyEventLoop and cached connections/pools? - Serverless Architectures - Serverless Forums
April 27, 2018 - I read a few articles on calling rds from lambdas and how to use ‘context.callbackWaitsForEmptyEventLoop = false’ in order to try to hand on to cached connections in warm lambdas. I have read some that advise to use a c…
Discussions

node.js - Why does AWS Lambda function always time out? - Stack Overflow
Just curious.. What is the java equivalent for callbackWaitsForEmptyEventLoop? More on stackoverflow.com
🌐 stackoverflow.com
callbackWaitsForEmptyEventLoop has no effect
Take the following function: export const scrap: APIGatewayProxyHandler = async (_event, ctx) => { ctx.callbackWaitsForEmptyEventLoop = false setTimeout(() => {}, 10000) return { statusCode: ... More on github.com
🌐 github.com
0
February 11, 2021
How can I specify "context.callbackWaitsForEmptyEventLoop = false" for low latency DocDB / Mongo calls ?
Describe the bug If context.callbackWaitsForEmptyEventLoop = false is specified, a DB connection can be maintained in a global variable in the lambda's container, resulting in connection times ... More on github.com
🌐 github.com
11
April 5, 2019
Resolved Lambda Issue Regarding Async Callbacks
Since I saw the line, context.callbackWaitsForEmptyEventLoop = false inside of the lambda code, I thought to myself, "Hm, I don't need to add that, cool!". After deploying it, I found that any othe... More on github.com
🌐 github.com
15
January 4, 2019
🌐
Durgadas Kamath
durgadas.in › improve-the-speed-of-your-aws-lambda-api-dad0548a7b37
Improve the speed of your AWS lambda API (NodeJS) with these two easy techniques
January 21, 2023 - If this property (callbackWaitsForEmptyEventLoop) is set to false, the callback will immediately return the response, and any outstanding events will run on next invocation.
🌐
Medium
medium.com › radient-tech-blog › aws-lambda-and-the-node-js-event-loop-864e48fba49
AWS Lambda and the Node.js Event Loop | by Daniël Illouz | Radient Tech Blog | Medium
September 14, 2018 - Lets see if we can find more and search for lambda + callback + empty + event loop. Top result is about the context Object. Looking through it there’s actually a property called callbackWaitsForEmptyEventLoop.
🌐
Amazon Web Services
docs.aws.amazon.com › aws lambda › developer guide › building lambda functions with node.js › using the lambda context object to retrieve node.js function information
Using the Lambda context object to retrieve Node.js function information - AWS Lambda
callbackWaitsForEmptyEventLoop – By default (true), when using a callback-based function handler, Lambda waits for the event loop to be empty after the callback runs before ending the function invoke. Set to false to send the response and end the invoke immediately after the callback runs ...
Top answer
1 of 3
53

You have a typo:

context.callbackWaitsForEmtpyEventLoop = false;

should be:

context.callbackWaitsForEmptyEventLoop = false;

Here's what the documentation says about the behavior of callbackWaitsForEmptyEventLoop:

callbackWaitsForEmptyEventLoop

The default value is true. This property is useful only to modify the default behavior of the callback. By default, the callback will wait until the Node.js runtime event loop is empty before freezing the process and returning the results to the caller. 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). For more information about callback, see Using the Callback Parameter.

Minimal example:

// Times out due to typo
exports.function1 = (event, context, callback) => {
    setInterval(() => console.log('Long wait'), 100000);
    context.callbackWaitsForEmtpyEventLoop = false;
    callback(null, 'Hello from Lambda');
};

// Returns successfully
exports.function2 = (event, context, callback) => {
    setInterval(() => console.log('Long wait'), 100000);
    context.callbackWaitsForEmptyEventLoop = false;
    callback(null, 'Hello from Lambda');
};
2 of 3
10

If anybody was confused like I was with how to add callbackWaitsForEmptyEventLoop to new Alexa projects that look like this:

const skillBuilder = Alexa.SkillBuilders.custom();

exports.handler = skillBuilder
  .addRequestHandlers(
      GetNewFactHandler,
      HelpHandler,
      ExitHandler,
      FallbackHandler,
      SessionEndedRequestHandler,
  )
  .addRequestInterceptors(LocalizationInterceptor)
  .addErrorHandlers(ErrorHandler)
  .lambda();

Example project found here: https://github.com/alexa/skill-sample-nodejs-fact/blob/master/lambda/custom/index.js

This solution worked for me:

// create a custom skill builder
const skillBuilder = Alexa.SkillBuilders.custom();

exports.handler = (event, context, callback) => {
  // we need this so that async stuff will work better
  context.callbackWaitsForEmptyEventLoop = false

  // set up the skill with the new context
  return skillBuilder
    .addRequestHandlers(
      GetNewFactHandler,
      HelpHandler,
      ExitHandler,
      FallbackHandler,
      SessionEndedRequestHandler,
    )
    .addRequestInterceptors(LocalizationInterceptor)
    .addErrorHandlers(ErrorHandler)
    .lambda()(event, context, callback);
}
🌐
GitHub
github.com › sst › sst › issues › 93
callbackWaitsForEmptyEventLoop has no effect · Issue #93 · sst/sst
February 11, 2021 - export const scrap: APIGatewayProxyHandler = async (_event, ctx) => { ctx.callbackWaitsForEmptyEventLoop = false setTimeout(() => {}, 10000) return { statusCode: 200, body: "ok", } } This will error because the setTimeout is stuck in the event loop.
Author   thdxr
Find elsewhere
🌐
DEV Community
dev.to › dvddpl › event-loops-and-idle-connections-why-is-my-lambda-not-returning-and-then-timing-out-2oo7
Event loops and idle connections: why is my lambda not returning and then timing out? - DEV Community
November 16, 2021 - One of our developers though, found out a parameter in the Lambda nodejs context that would solve the issue: callbackWaitsForEmptyEventLoop.
🌐
Ed4becky
ed4becky.org › clearing-up-settimeout-misconceptions-in-aws-lambdas
Clearing Up setTimeout Misconceptions in AWS Lambda’s – Thank You for Your Patience
The default setting for callbackWaitsForEmptyEventLoop is true, so the handler will not exit before the shorter of API Gateway timeout, Lambda timeout, or the Promise is resolved.
🌐
GitHub
github.com › architect › architect › issues › 346
How can I specify "context.callbackWaitsForEmptyEventLoop = false" for low latency DocDB / Mongo calls ? · Issue #346 · architect/architect
April 5, 2019 - Describe the bug If context.callbackWaitsForEmptyEventLoop = false is specified, a DB connection can be maintained in a global variable in the lambda's container, resulting in connection times ...
Author   mikemaccana
🌐
GitHub
github.com › dherault › serverless-offline › issues › 1531
Missing documentation on callbackWaitsForEmptyEventLoop and run modes · Issue #1531 · dherault/serverless-offline
August 5, 2022 - It should be clear that callbackWaitsForEmptyEventLoop is not handled at all by serverless-offline with these impacts: in worker-threads mode: lambdas are terminated after an idle timeout without waiting for an empty event loop => ressou...
🌐
The Burning Monk
theburningmonk.com › home › how to log timed out lambda invocations
How to log timed out Lambda invocations | theburningmonk.com
September 5, 2020 - const Promise = require('bluebird') const Log = require('@perform/lambda-powertools-logger') module.exports = () => { let isTimedOut = undefined let promise = undefined const resetPromise = () => { if (promise) { promise.cancel() promise = undefined } } return { before: (handler, next) => { const timeLeft = handler.context.getRemainingTimeInMillis() handler.context.callbackWaitsForEmptyEventLoop = false isTimedOut = undefined promise = Promise.delay(timeLeft - 10).then(() => { if (isTimedOut !== false) { const awsRequestId = handler.context.awsRequestId const invocationEvent = JSON.stringify(handler.event) Log.error('invocation timed out', { awsRequestId, invocationEvent }) } }) next() }, after: (handler, next) => { isTimedOut = false resetPromise() next() }, onError: (handler, next) => { isTimedOut = false resetPromise() next(handler.error) } } }
🌐
GitHub
github.com › apollographql › apollo-server › issues › 2156
Resolved Lambda Issue Regarding Async Callbacks · Issue #2156 · apollographql/apollo-server
January 4, 2019 - const apolloHandler: lambda.APIGatewayProxyHandler = server.createHandler({ cors: { origin: true, credentials: true }); export const handler: lambda.APIGatewayProxyHandler = ( event: lambda.APIGatewayProxyEvent, context: lambda.Context, callback: lambda.APIGatewayProxyCallback ) => { context.callbackWaitsForEmptyEventLoop = false; return apolloHandler(event, context, callback); };
Author   j
🌐
Sequelize
sequelize.org › other topics › using sequelize in aws lambda
Using sequelize in AWS Lambda | Sequelize
// no callback invoked module.exports.handler = function () { // Lambda finishes AFTER `doSomething()` is invoked setTimeout(() => doSomething(), 1000); }; // callback invoked module.exports.handler = function (event, context, callback) { // Lambda finishes AFTER `doSomething()` is invoked setTimeout(() => doSomething(), 1000); callback(null, 'Hello World!'); }; // callback invoked, context.callbackWaitsForEmptyEventLoop = false module.exports.handler = function (event, context, callback) { // Lambda finishes BEFORE `doSomething()` is invoked context.callbackWaitsForEmptyEventLoop = false; set
🌐
GitHub
github.com › dherault › serverless-offline › issues › 770
context.callbackWaitsForEmptyEventLoop property missing · Issue #770 · dherault/serverless-offline
context.callbackWaitsForEmptyEventLoop property missing#770 · Copy link · Labels · bug · dnalborczyk · opened · on Aug 7, 2019 · ref: https://docs.aws.amazon.com/lambda/latest/dg/nodejs-prog-model-context.html · https://docs.aws.amazon.com/lambda/latest/dg/nodejs-prog-model-handler.html#nodejs-handler-sync ·
🌐
Mongoose
mongoosejs.com › docs › 7.x › docs › lambda.html
Mongoose v7.8.7: Using Mongoose With AWS Lambda
// See https://www.mongodb.com... thanks to `callbackWaitsForEmptyEventLoop`. // This means your Lambda function doesn't have to go through the // potentially expensive process of connecting to MongoDB every time....
🌐
Js
middy.js.org › middlewares › do-not-wait-for-empty-event-loop
do-not-wait-for-empty-event-loop | Middy.js
October 21, 2025 - By default the middleware sets the callbackWaitsForEmptyEventLoop property to false only in the before phase, meaning you can override it in handler to true if needed.
🌐
GitHub
github.com › fastify › aws-lambda-fastify › issues › 26
Add easier support for callbackWaitsForEmptyEventLoop · Issue #26 · fastify/aws-lambda-fastify
September 9, 2019 - const proxy = awsLambdaFastify(app) exports.handler = function(event, context, callback) { context.callbackWaitsForEmptyEventLoop = false return proxy(event, context, callback) }
Author   ShogunPanda
🌐
npm
npmjs.com › package › @middy › do-not-wait-for-empty-event-loop › v › 2.0.0-alpha.0
Middy do-not-wait-for-empty-event-loop middleware
January 24, 2021 - import middy from '@middy/core' import doNotWaitForEmptyEventLoop from '@middy/do-not-wait-for-empty-event-loop' const handler = middy((event, context) => { return {} }) handler.use(doNotWaitForEmptyEventLoop({runOnError: true})) // When Lambda runs the handler it gets context with callbackWaitsForEmptyEventLoop property set to false handler(event, context, (_, response) => { t.is(context.callbackWaitsForEmptyEventLoop,false) })
      » npm install @middy/do-not-wait-for-empty-event-loop
    
Published   Sep 08, 2025
Version   2.0.0-alpha.0
Author   Middy contributors