AWS Lambda Cold Start
An AWS Lambda cold start occurs when Lambda prepares a new execution environment before running your function.
This initialization can add latency because Lambda must prepare the environment, load your code and runtime, and execute initialization logic before the function handler begins.
Cold starts are different from normal function execution and should be investigated separately when startup latency affects application performance.
Cold Start at a Glance
Request → No reusable environment → Create environment → Load runtime → Load function code → Run initialization → Execute handler
By contrast, when Lambda can reuse an existing execution environment:
Request → Existing environment → Execute handler
The second path is commonly referred to as a warm invocation.
AWS describes cold-start initialization as including preparation of the execution environment, loading code, starting the runtime, and running initialization code outside the handler.
What Causes a Lambda Cold Start?
A cold start occurs when an existing suitable execution environment is not available.
This can happen when:
- a function receives its first invocation
- Lambda scales to additional execution environments
- a new function version is deployed
- existing environments are no longer available
- configuration changes result in new environments being created
Cold starts are therefore a normal part of Lambda's execution model.
The goal is usually not to eliminate every cold start.
The goal is to reduce cold-start impact when startup latency matters to users or downstream systems.
What Happens During Lambda Initialization?
The initialization path contains several pieces of work.
Environment setup
Lambda prepares the execution environment.
Runtime startup
The selected language runtime must start.
Code loading
Lambda makes your deployed function code available.
Dependency initialization
Libraries, frameworks, SDKs, and other application dependencies may need to load.
Initialization code
Code outside the handler can run before the invocation begins.
Only after these steps can the handler process the request.
Heavy initialization therefore increases startup latency.
Cold Start vs. Warm Start
| Cold invocation | Warm invocation |
|---|---|
| New environment needed | Existing environment reused |
| Runtime initialization occurs | Runtime already available |
| Dependencies may need initialization | Existing initialized state may be reused |
| Additional startup latency | Typically lower startup latency |
| Init Duration may be relevant | No equivalent full initialization phase |
Lambda retains execution environments for possible reuse after an invocation, but applications should not depend on an environment remaining available indefinitely.
What Affects Lambda Cold Start Time?
Cold-start duration varies by application.
Major contributors include:
Runtime
Different language runtimes have different startup characteristics.
Deployment size
Larger functions and dependency sets can require more initialization work.
Framework initialization
Large frameworks may initialize dependency injection, configuration, routing, or other application components before the handler runs.
Initialization code
Database clients, SDKs, configuration retrieval, model loading, and other work performed before the handler can increase startup time.
Memory and CPU
Lambda allocates CPU resources in relation to function resources. Increasing resources can sometimes reduce initialization and execution time.
AWS recommends increasing memory as one possible strategy when initialization itself is timing out because greater memory also provides more proportional CPU.
How Do You Measure a Lambda Cold Start?
Lambda logs provide initialization information.
AWS's standard REPORT information can include:
- duration
- billed duration
- memory size
- maximum memory used
- initialization duration
Init Duration indicates time spent executing initialization work for a newly prepared environment.
With JSON logging and provisioned-concurrency initialization, Lambda can also expose initialization information through platform events.
You should evaluate cold starts using distributions rather than one isolated request.
Useful questions include:
- What percentage of requests experience initialization?
- What is p95/p99 latency for affected requests?
- Which functions experience the most cold starts?
- How much of overall latency comes from initialization?
- Are cold starts visible to users?
How to Reduce AWS Lambda Cold Starts
1. Reduce initialization work
Keep startup work focused on what every invocation actually needs.
Avoid unnecessarily loading large resources before the handler executes.
2. Remove unnecessary dependencies
Smaller dependency trees generally reduce packaging complexity and can simplify initialization.
3. Reuse clients and connections appropriately
AWS recommends initializing SDK clients and database connections outside the handler when they can safely be reused across invocations.
This can reduce repeated work during warm invocations.
4. Review memory allocation
A function with too little CPU may initialize slowly even when memory usage itself appears low.
Benchmark real workloads rather than choosing the smallest memory configuration by default.
5. Use provisioned concurrency when latency is critical
Provisioned concurrency prepares execution environments before requests arrive.
AWS positions it primarily for interactive, latency-sensitive workloads and notes that it incurs additional cost.
It is most useful when predictable startup latency justifies the added cost.
6. Evaluate Lambda SnapStart
Lambda SnapStart initializes the function when a version is published, creates an encrypted snapshot of the initialized environment, and restores new environments from that snapshot.
AWS states that SnapStart can reduce initialization latency to sub-second levels in suitable workloads.
Applications using SnapStart must also account for snapshot-specific considerations such as uniqueness and connection state.
Provisioned Concurrency vs. SnapStart
| Provisioned concurrency | SnapStart | |
|---|---|---|
| Approach | Keeps initialized environments ready | Restores initialized environment from snapshot |
| Main goal | Predictable low startup latency | Reduce initialization work |
| Additional Lambda capacity cost | Yes | Different pricing/feature considerations apply |
| Best fit | Highly latency-sensitive workloads | Functions with expensive initialization |
| Requires application review | Usually limited | Yes, especially state/connection behavior |
The best option depends on runtime support, traffic patterns, startup requirements, and cost.
Should You Worry About Every Cold Start?
No.
A background function processing queue messages may tolerate several hundred milliseconds of startup latency without user impact.
A Lambda powering a latency-sensitive authentication or checkout request may not.
Prioritize cold-start optimization when:
- users directly experience the latency
- initialization dominates total execution time
- p95 or p99 latency is affected
- traffic causes frequent environment creation
- an SLA requires predictable response time
Do not optimize cold starts purely because an initialization event exists.
Measure its effect first.
Monitor Cold Starts in Context
Suppose API latency increases.
A trace may show:
API request 1.4 sec
Lambda initialization 0.9 sec
Handler 0.1 sec
Database 0.4 secCold start is clearly important.
But another request could show:
API request 3.2 sec
Lambda initialization 0.1 sec
Handler 0.1 sec
Database 3.0 secOptimizing Lambda initialization in the second case would barely improve user experience.
This is why cold starts should be evaluated alongside distributed traces and dependency latency, not as an isolated number.
AWS Lambda Cold Start FAQs
What is a Lambda cold start?
A cold start occurs when AWS Lambda must prepare a new execution environment before running a function invocation.
Does every Lambda request have a cold start?
No. Lambda can reuse existing execution environments, allowing later requests to avoid the full initialization path.
How do I know if Lambda had a cold start?
Lambda logs can expose initialization information, including Init Duration, for newly initialized environments.
What increases Lambda cold-start time?
Runtime startup, package size, dependency loading, framework initialization, and custom initialization code can all contribute.
Does provisioned concurrency prevent cold starts?
Requests handled within provisioned concurrency use environments initialized ahead of the request, which is designed to avoid cold-start latency.
What is Lambda SnapStart?
SnapStart initializes a function when a version is published and saves a snapshot of that initialized environment so new execution environments can restore from it rather than repeating the full initialization process.
Should I optimize all Lambda cold starts?
No. Optimize cold starts when they materially affect user-facing latency, throughput, or application objectives.