Understanding AWS Lambda Cold Start and Warm Start

Sushant Raje
2 min readJul 9, 2023

Cold Start: The Initialization Process

When a Lambda function is invoked for the first time or after a period of inactivity, it goes through an initialization process. This includes AWS Lambda downloading code files from internal s3, setting up environment variables, allocating memory, and spinning up the execution environment. Once the initialization is complete, the default constructor of class ‘function’ is called, followed by the execution of the function handler code. This process is called Cold Start.

The Cold Start process can take some time, depending on various factors such as the size of the deployment package, the complexity of code, and the amount of memory allocated to the function.

Warm Start: Reusing the Execution Environment

After a Cold Start, AWS Lambda freezes the execution context for a non-deterministic time. If within the same time duration, Lambda function is invoked again, AWS will use the same execution environment. This time default constructor will not get called instead handler code will get called. This process is called Warm Start.

This results in significantly faster execution time compared to Cold Start. AWS does not charge for those frozen execution environments.

Concurrency with Cold Start and Warm Start

If we get multiple concurrent execution requests for lambda, multiple instances of lambda will spin up at the same time. For example, 10 requests are concurrently calling lambda, then 10 times Cold start will occur. Once execution is completed, AWS will freeze all 10 execution contexts for some non-deterministic time. If we get a request again within this duration, the request will be served by these execution environments.

Provisioned Concurrency

Provisioned Concurrency allows you to allocate a fixed number of execution environments to a function. This ensures that the execution environments are always warm but you will have to Pay for it.

Conclusion

In this article, we explored the concepts of Cold Start and Warm Start in AWS Lambda. Key takeaways are, we learned Cold Start occurs during the initialization process of a Lambda function, while Warm Start refers to the reuse of an existing execution environment.

--

--