aws / aws-lambda-python-runtime-interface-client

Apache License 2.0
258 stars 73 forks source link

What happens when an AWS Lambda times out? #63

Closed Arvintian closed 2 months ago

Arvintian commented 2 years ago

I want to know what happens when an lambda timeout? Is like kill stop the being executed python function? whick line code show me the kill action?

m-rph commented 2 months ago

Hi, I am adding this comment for posterity and in case anyone finds this issue.

Lambda invokes your function in an execution environment, which provides a secure and isolated runtime environment. The execution environment manages the resources required to run your function. The execution environment also provides lifecycle support for the function's runtime and any external extensions associated with your function.

The function's runtime communicates with Lambda using the Runtime API. Extensions communicate with Lambda using the Extensions API. Extensions can also receive log messages and other telemetry from the function by using the Telemetry API.

This package implements the Runtime API.

We have the following LifeCycle.

image

Each phase starts with an event that Lambda sends to the runtime and to all registered extensions. The runtime and each extension indicate completion by sending a Next API request to the execution environment. Lambda freezes the execution environment when the runtime and each extension have completed and there are no pending events.

Shutting down

When Lambda is about to shut down the runtime (this package + your code), it sends a Shutdown event to each registered external extension. Extensions can use this time for final cleanup tasks. The Shutdown event is a response to a Next API request.

Duration: The entire Shutdown phase is capped at 2 seconds. If the runtime (this package) or any extension does not respond, Lambda terminates it via a signal (SIGKILL).

You can read more about this here:

https://docs.aws.amazon.com/lambda/latest/dg/lambda-runtime-environment.html