Comparisons / EC2 vs Lambda
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."

AspectAmazon EC2AWS Lambda
Execution modelAlways-on virtual serverEvent-driven, runs code only on trigger
Billing unitRunning time (per second, 1 min minimum)Invocation count and duration (1ms increments)
ScalingRequires manual Auto Scaling setupConcurrency scales automatically
Max execution timeNo limit (can run continuously)15 minutes (hard timeout)
Infrastructure managementYou manage the OS and middlewareNo server management (serverless)
Cost profileBilled while running, even if idleNo 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

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.