I have a AWS Lambda function that connects to a RDS instance using the Knex.js NPM module. After I get the data from the DB, and call the callback()
function, the AWS Lambda won’t exit, won’t send back a response and will time out.
If I console.log()
the result from the DB I see the data, meaning the retrieval of the information from the DB was successful.
Turns out that by default AWS Lambda will wait for the event loop to be empty before terminating the execution of the function. This means that even if you call the callback()
function, AWS Lambda won't quit. To change this behavior you need to set callbackWaitsForEmptyEventLoop
to false
. This tells AWS Lambda to quit even when the event loop is not empty, which in this case it is our DB connection.
context.callbackWaitsForEmptyEventLoop = false;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With