do-not-wait-for-empty-event-loop
This middleware sets context.callbackWaitsForEmptyEventLoop property to false.
This will prevent Lambda from timing out because of open database connections, etc.
Install
To install this middleware you can use NPM:
npm install --save @middy/do-not-wait-for-empty-event-loop Options
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. You can set it in all steps with the options:
runOnBefore(defaults totrue) - sets property before running your handlerrunOnAfter(defaults tofalse)runOnError(defaults tofalse)
Sample usage
import middy from '@middy/core'
import doNotWaitForEmptyEventLoop from '@middy/do-not-wait-for-empty-event-loop'
const lambdaHandler = (event, context) => {
return {}
}
export const handler = middy()
.use(doNotWaitForEmptyEventLoop({ runOnError: true }))
.handler(lambdaHandler)