Lambda Cheaper Than EC2?
Incorrect Answer
Yes, AWS Lambda is cheaper than Amazon EC2.
Correct Answer
It depends on the workload. Both have different cost factors. Lambda can actually be more expensive than EC2 for high-throughput, long-running workloads. The key metric is TCO (Total Cost of Ownership) β Lambda eliminates patching, AMI management, and capacity planning overhead.
Lambda vs EC2 vs Fargate β Cost Comparison
| Aspect | Lambda | EC2 | Fargate |
|---|---|---|---|
| Pricing Model | Per request + duration Γ memory | Per hour (On-Demand/Reserved/Spot) | Per vCPU-hour + GB-hour |
| Idle Cost | $0 β pay only when invoked | Pays even when idle | Pays while task runs |
| Cheaper When | <1M requests/month, bursty/sporadic | >70% utilization, steady traffic | Containerized, variable workloads |
| Hidden Costs | NAT Gateway for VPC, CloudWatch Logs | EBS, ALB, AMI storage, patching time | ALB, CloudWatch, ECR |
| Max Duration | 15 minutes | Unlimited | Unlimited |
| Ops Overhead | Zero (fully managed) | High (OS patching, scaling config) | Low (no EC2 to manage) |
Lambda Limits (Know These for Interviews)
- Memory: 128 MB β 10,240 MB (10 GB)
- Timeout: Max 15 minutes
- Payload: 6 MB sync, 256 KB async
- Concurrency: 1,000 default (can request increase to 10,000+)
- Deployment: 50 MB zipped, 250 MB unzipped (use container images for up to 10 GB)
- Graviton: arm64 architecture gives 20% better price-performance
π― Key Takeaway
Interview tip: Never say "Lambda is always cheaper." Say: "Lambda wins on TCO for sporadic, event-driven workloads under 15 minutes. EC2 wins for sustained high-throughput workloads. I'd run a cost analysis using the AWS Pricing Calculator comparing the specific request volume, duration, and memory before choosing."