amazon-web-servicesaws-lambdaserverlessfaas

When is aws-lambda instance destroyed?


From the docs:

When your function is invoked, Lambda attempts to re-use the execution environment from a previous invocation if one is available.

When a lambda function is invoked, an instance of the configured runtime will be launched.

Once the execution completes, after what time that instance of lambda function is destroyed?

Suppose,

at t0=0 sec, lambda is invoked and subsequently starts to initialize its runtime and lets say it takes 2sec to launch the instance of its runtime (say nodejs)

at t1=2 sec, lambda function execution started, and

at t2=3 sec, lambda function execution completed,

and at some time t the instance of nodejs runtime will be destroyed on aws backend,

Is there any way the time t or can it be computed or if it is predefined ?


Solution

  • AWS Lambda functions run in ephemeral containers and all those mechanisms are implemented and maintained by AWS itself.

    Developer is not supposed to worry about environment. Developer only need to keep in mind that all functions in his app should be stateless and should not be designed to share any data via container itself.

    AWS scales the amount of available containers automatically to provide the optimal performance and minimum cold starts during spikes of load to your service.

    There is no exact time to live for those containers.

    You can read more about reusing in Understanding Container Reuse in AWS Lambda | AWS Compute Blog.