3

When I run this code on AWS Lambda nothing gets logged, although when I invoke this locally using serverless (framework), it does log. Is there anything that I am missing?

exports.handler = async () => {
  process.on("exit", (code) => {
    console.log("process exit code: ", code);
  });
};
Vincent
  • 51
  • 4

2 Answers2

3

There is no such event in AWS Lambda to know when the container is stopped. The "Exit" event that fired when you run your code locally it a Node.js event and it is not supported by the AWS Lambda implementation.

You can find here a discussion on how to handle DB connection: AWS Lambda Container destroy event

maximus
  • 716
  • 7
  • 18
2

Lambda endpoints stay alive even after API responds. The actual exit happens when the container that processed the request gets disposed after 15 minutes.

Allan Chua
  • 9,305
  • 9
  • 41
  • 61