Vincent
Vincent

Reputation: 61

on exit event does not fire in AWS Lambda

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);
  });
};

Upvotes: 4

Views: 1204

Answers (2)

Allan Chua
Allan Chua

Reputation: 10175

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

Upvotes: 2

maximus
maximus

Reputation: 746

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

Upvotes: 4

Related Questions