AWS Lambda
Serverless functions run on events and billed per request and duration.
Scales automatically to zero; limited run time and cold starts are the trade-offs.
Cloud & DevOps
EC2 gives you virtual servers to manage, ECS runs your containers on managed infrastructure, and Lambda runs functions on demand with no servers to manage and pay-per-use pricing.
Serverless functions run on events and billed per request and duration.
Scales automatically to zero; limited run time and cold starts are the trade-offs.
Virtual machines you configure and manage.
Full control of OS, runtime and networking; you handle patching and scaling.
A managed container orchestration service, on EC2 or Fargate.
Runs Docker containers as services or tasks; with Fargate there are no servers to manage.
| Aspect | AWS Lambda | Amazon EC2 | Amazon ECS |
|---|---|---|---|
| Unit | Function | Virtual machine | Container |
| Server management | None | Full | None with Fargate |
| Scaling | Automatic, to zero | Auto Scaling groups | Service auto scaling |
| Pricing | Per request and ms | Per instance hour | Per task resources |
| Best for | Event-driven, spiky work | Full control, long-running | Containerised services |
EC2 gives you virtual machines you configure and manage. ECS runs your Docker containers as services or tasks, on EC2 instances or serverless Fargate. Lambda runs individual functions on demand in response to events, with no servers to manage and billing per request and duration.
For event-driven or spiky workloads: API handlers with variable traffic, file processing on S3 uploads, scheduled jobs and queue consumers, where scaling to zero and paying per use matter.
When you need full control of the operating system, long-running processes, special hardware such as GPUs, software that cannot be containerised easily, or steady workloads where reserved instances are cheapest.
When the app is containerised and runs continuously as services, such as web APIs or workers, and you want managed orchestration, optionally without managing servers by using Fargate.
Lambda scales automatically per request and to zero. EC2 scales with Auto Scaling groups adding or removing instances. ECS scales the number of tasks with service auto scaling, on EC2 capacity or Fargate.
Lambda charges per request and compute duration in milliseconds. EC2 charges per instance time whether busy or idle, with savings plans and spot discounts. ECS charges for the underlying EC2 instances or Fargate vCPU and memory per task.
A maximum execution time of 15 minutes, memory up to about 10 GB, limited temporary storage, cold starts and concurrency quotas, which make it unsuited to very long or stateful work.
The delay when Lambda creates a new execution environment, loading code and initialising before handling a request. Provisioned concurrency and smaller packages reduce it.
A serverless compute engine for containers used by ECS and EKS: you specify CPU and memory per task and AWS runs it without you managing EC2 instances.
On EC2 you patch the OS and runtime. On ECS with EC2 you manage the instances; with Fargate, AWS does. On Lambda, AWS manages the environment entirely.
Practise every comparison in your dashboard.
Start learning