How do Lambda execution environments and cold starts work?
Learn the Lambda initialization and invocation lifecycle, what causes cold starts, how reuse works, and which latency optimizations are evidence-based.
How do Lambda execution environments and cold starts work?
A Lambda cold start is the initialization work required when Lambda prepares a new execution environment before it can run a function handler. The platform initializes the runtime, loads function code and dependencies, and runs initialization code; later invocations may reuse that environment, but reuse is an optimization and must never be required for correctness.
How this topic fits
Compute
Understand Lambda execution, scaling, concurrency, packaging, event sources, cold starts, and when serverless containers are the better fit.
Follow the execution-environment lifecycle
During initialization, Lambda prepares extensions, the runtime, and function code. During invocation, the runtime calls the handler with the event. Lambda may freeze and later reuse the environment, and eventually shuts it down.
Code outside the handler can initialize SDK clients, configuration, and reusable connections once per environment. Keep this work purposeful because it contributes to initialization latency and can fail before the handler begins.
Understand when initialization appears
Initialization occurs when capacity needs a new environment, including scale-out and replacement. Deployment changes, configuration changes, runtime behavior, provisioned-concurrency configuration, and long idle periods can affect when new environments appear.
Cold-start impact is a distribution, not one fixed number. Runtime, package size, dependency initialization, networking, memory, extensions, and traffic shape all influence the measured result.
Optimize the work you can measure
Remove unused dependencies, import only what is needed, initialize clients efficiently, select appropriate memory, and avoid blocking network calls during startup unless they are necessary. Measure initialization separately from handler duration.
For latency-critical paths, evaluate provisioned concurrency and runtime-specific capabilities against an explicit service-level objective. Do not pay to eliminate occasional initialization that users never observe.
Design correctness without environment reuse
Store durable state outside the execution environment. Files in temporary storage, in-memory caches, and open connections may be reused, but code must tolerate an empty environment and reconnect safely.
Never put request-specific sensitive data into reusable global state. Reset mutable state, validate connection health, and make handlers idempotent so retries or replacement environments cannot corrupt an operation.
Go deeper with AWS
Read the primary AWS documentation behind the service definitions and architecture guidance in this guide.
Next steps
Continue with the concepts that most directly shape this decision.
Lambda concurrency and scaling
Understand Lambda concurrency, account and function controls, burst behavior, downstream protection, and how to plan capacity from real traffic.
Serverless cost and performance
Measure cost per outcome, tune Lambda memory and duration, reduce request and data-transfer amplification, and optimize from production evidence.
Questions about this topic
Browse all serverless concepts
Explore compute, APIs, events, workflows, data, security, reliability, operations, delivery, and AI from one connected AWS serverless learning path.
What is serverless?
Learn what serverless computing means, how it works on AWS, what the cloud provider manages, and which trade-offs still belong to your team.
What is AWS Lambda?
Understand how AWS Lambda runs code, how functions are invoked, where permissions and state live, and when Lambda is a good compute choice.
What is serverless architecture?
Learn how managed compute, APIs, events, queues, workflows, data, identity, and observability fit together in a serverless architecture on AWS.
AWS serverless security
A practical guide to identity, least privilege, event validation, secrets, data protection, dependencies, and incident visibility in AWS serverless systems.
What is agentic AI?
Learn what makes an AI system agentic, how models, tools, memory, orchestration, identity, and evaluation fit together, and where serverless patterns help on AWS.
What is cloud computing?
Understand how on-demand infrastructure and managed services change the way teams provision, scale, pay for, and operate software systems.
What is event-driven architecture?
Learn how producers, routers, and consumers communicate through events, and how to design schemas, delivery, retries, and ownership deliberately.
What is a serverless API?
Understand the request path, authentication, routing, compute, data, throttling, observability, and failure controls behind a serverless API on AWS.
What are serverless workflows?
Learn when explicit workflow state improves retries, branching, parallel work, human approval, visibility, and recovery in distributed applications.
What is Amazon API Gateway?
Learn how API Gateway creates, publishes, secures, monitors, and operates HTTP, REST, and WebSocket APIs for AWS and external backends.
What is Amazon EventBridge?
Understand EventBridge event buses, rules, pipes, schemas, targets, schedules, permissions, delivery, and recovery in event-driven AWS systems.
Make the next serverless decision explicit.
Explore focused products for repeatable work, or bring the architecture decision that needs context and experienced review.