Computing
EC2 vs Lambda
EC2 gives you a virtual server you manage yourself; Lambda is an event-driven, serverless execution environment. The core difference is "always running" vs "runs only when triggered."
| Aspect | Amazon EC2 | AWS Lambda |
|---|---|---|
| Execution model | Always-on virtual server | Event-driven, runs code only on trigger |
| Billing unit | Running time (per second, 1 min minimum) | Invocation count and duration (1ms increments) |
| Scaling | Requires manual Auto Scaling setup | Concurrency scales automatically |
| Max execution time | No limit (can run continuously) | 15 minutes (hard timeout) |
| Infrastructure management | You manage the OS and middleware | No server management (serverless) |
| Cost profile | Billed while running, even if idle | No charge when not invoked |
How to Choose
EC2 suits steady, long-running workloads, jobs exceeding 15 minutes, or cases needing fine-grained OS control. Lambda suits unpredictable, spiky traffic with short-lived (under 15 minutes) processing where you want to avoid server management overhead.
Exam Points
- SAA frequently tests choosing Lambda from requirements like "minimize idle cost" or "unpredictable traffic"
- DVA covers Lambda concurrency limits, cold starts, and code sharing via Layers
- SAP/DOP cover ENI cold-start latency when Lambda runs inside a VPC, and event source mapping design
Related Service Guides
References
Last updated: 2026-09-06
This page is created from AWS official documentation and reviewed/edited by the operator. See our editorial & quality policy for details.