Cold Start in AWS Lambda

What is a Cold Start?

A cold start occurs when a Lambda function is invoked, but there is no "warm" container available to execute it. AWS must create a new container, initialize the runtime environment, and load the function code before the execution begins. This causes a delay, typically lasting a few hundred milliseconds to a few seconds, depending on various factors.

When Does a Cold Start Happen?

How to Mitigate Cold Starts?

  1. Provisioned Concurrency: Keeps a predefined number of containers warm.
  2. Optimize Function Code: Reduce initialization time by minimizing external dependencies and optimizing code.
  3. Use Smaller Runtimes: Languages like Node.js and Python tend to have shorter cold start times compared to Java or .NET.
  4. Use VPC Endpoint Correctly: Avoid unnecessary VPC configuration unless required, as it can increase cold start times.
  5. Frequent Invocations: Trigger the function periodically (e.g., using a CloudWatch rule) to keep containers warm.

Limitations of AWS Lambda

Execution Time

Memory and CPU