Lambda vs Fargate vs EC2 Cost Analysis 2026
Serverless vs containers vs VMs: Break-even analysis, real scenarios, decision framework. Save up to $500K/year.
Quick Pricing Overview
Platform
Pricing Model
Startup Workload (1M invocations/month)
Mid-Market (100M invocations/month)
Enterprise (5B invocations/month)
AWS Lambda
$0.20 per million invocations + GB-seconds
$200–$500/month
$20K–$50K/month
$500K–$2M/month
AWS Fargate
$0.04288/GB/hour + vCPU
$500–$1K/month
$10K–$50K/month
$200K–$1M/month
EC2 On-Demand
$0.05–$0.40 per hour per instance
$200–$500/month
$10K–$50K/month
$300K–$1.5M/month
EC2 Spot (80% off)
$0.01–$0.08 per hour per instance
$50–$150/month
$2K–$10K/month
$50K–$300K/month
Real-World Cost Scenarios
Scenario 1: Event-Driven Workload (Webhooks, Image Processing, 100M events/month)
Option
Annual Cost
Setup Complexity
Best For
Lambda (1GB, 5s avg)
$240K/year
Low (serverless, auto-scaling)
✓ Bursty, event-driven workloads
Fargate (2 CPU, 4GB RAM)
$180K/year
Moderate (containerized, needs orchestration)
Sustained load, better than Lambda
EC2 On-Demand (2 × t3.xlarge)
$150K/year
High (management, patching, scaling logic)
Sustained, predictable load
EC2 Spot (2 × t3.xlarge + auto-scaling)
$30K/year
High (Spot management, fallback logic)
Cost-sensitive, fault-tolerant workloads
Scenario 2: Continuous API Backend (1B requests/month, 100ms avg latency)
Option
Annual Cost
Notes
Lambda (2GB, 100ms average)
$1.8M/year
Expensive at this scale; better for API gateway integration
Fargate (4 CPU, 8GB RAM × 10 tasks)
$720K/year
✓ Good balance: container per request or connection pooling
EC2 On-Demand (5 × c6i.2xlarge)
$480K/year
✓ Cheapest managed option for sustained load
EC2 Spot + Reserved (3 reserved + 2 Spot)
$180K/year
✓ Cheapest overall if workload is 80%+ predictable
⚡ Lambda Break-Even Analysis
Lambda becomes cheaper than Fargate at:
<50K invocations/month: Lambda wins (low sustained load)
50K–500K invocations/month: Fargate slightly cheaper, Lambda simpler
>1M invocations/month: Fargate wins (sustained load, 30–40% cheaper)
>5B invocations/month: EC2 Spot/Reserved wins (60–80% cheaper than Fargate)
Rule of thumb: If you need 24/7 compute, move off Lambda. If you have 100+ concurrent requests, use Fargate or EC2.
Feature Comparison
Feature
Lambda
Fargate
EC2
Cold start latency
300–1000ms (first invocation)
5–10s (container startup)
Instant (already running)
Max execution time
15 minutes
As long as needed
As long as needed
Concurrency
1,000 concurrent (can increase)
Unlimited (per task)
Unlimited
Networking
No direct public IP (NAT Gateway $45/mo)
Full VPC networking
Full VPC networking
Persistence
/tmp (512MB, temporary)
EBS volumes available
EBS/instance store
Auto-scaling
Automatic (Lambda API)
Manual (ECS target scaling)
Manual (Auto Scaling groups)
Cost visibility
Per invocation (easy to optimize)
Per container hour (fixed)
Per instance hour (fixed)
5 Cost Reduction Tactics
1. Lambda Memory Right-Sizing (20–50% savings for CPU-bound workloads)
Lambda CPU scales linearly with memory. Find your optimal balance:
Charge model: $0.0000166667 per GB-second. Allocate 128MB–3GB (you pay per execution time).
Test: Run same function at 512MB, 1GB, 2GB, 3GB. Find where cost/duration product is lowest.
Real example: Image processing function: 3GB allocation (finishes in 10s, $0.000025 cost) vs 512MB (takes 60s, $0.000010 cost per execution but 3K invocations/day = $30/day vs $10/day = $7K/year savings)
Savings: Typically 20–40% by right-sizing to optimal GB-second ratio
2. Lambda to Fargate Migration (30–60% savings for sustained workloads)
If Lambda concurrency is consistently high, Fargate is cheaper and simpler:
Threshold: If you have >1,000 concurrent Lambda executions OR >10M invocations/month, Fargate wins
Migration effort: 2–4 weeks (refactor event handlers to HTTP server, containerize, deploy to ECS)
Real example: Team running 2M Lambda invocations/month (2 GB, 1s avg) = $240K/year → Fargate (same workload) = $80K/year = $160K/year savings
Bonus: Fargate has no Lambda cold-start penalty for sustained load
3. EC2 Spot Instances for Fault-Tolerant Workloads (70–90% savings)
Use Spot instances for batch jobs, async processing, distributed computing:
Spot discount: 70–90% off on-demand for same instance type
Catch: Can be interrupted with 2-minute notice. Safe for fault-tolerant apps (Spot instance interruption handler available)
Mix strategy: 80% Spot + 20% on-demand (or reserved) for high availability
Real example: 10 × c5.2xlarge on-demand ($480K/year) → 8 Spot + 2 reserved = $90K/year = $390K/year savings
Use case: ML training, batch ETL, log processing, data pipeline jobs
4. EC2 Savings Plans / Reserved Instances (30–60% for predictable load)
Commit upfront to lock in discounts for sustained EC2 workloads:
1-year Savings Plan: ~30% discount on on-demand
3-year Savings Plan: ~50% discount on on-demand
Reserved Instances: ~60% discount, but less flexible than Savings Plans
Real example: $500K/year EC2 on-demand → $250K with 3-year Savings Plan = $250K/year savings
Risk: Lock-in; use only if workload is stable
5. NAT Gateway Consolidation (Save $45–$90/month per gateway)
Lambda in VPC requires NAT Gateway ($45/month + data transfer $0.045/GB). This is expensive for event-driven workloads:
If Lambda doesn't need VPC: Remove VPC (you pay for NAT Gateway even if not using it heavily)
If Lambda needs VPC: Use NAT instance on EC2 spot (~$10–20/month) instead
Real example: 10 Lambda functions in VPC = 10 NAT Gateways = $450/month = $5.4K/year waste. Fix: 1 NAT instance = $15/month = $180/year = $5.2K/year savings
⚠️ Lambda Cold Start Trap: Cold starts (300–1000ms) add up for event-driven workloads. At 100M invocations/month with 10% cold start rate = 10M cold starts = massive latency tail. Use Fargate or keep Lambda warm with scheduled invocations if cold starts matter.
3 Real Case Studies
Case Study 1: Startup (Event-Driven → Lambda)
Situation: Early-stage SaaS processing webhooks, 10M events/month, bursty traffic (5–10x variance).
Setup:
Lambda (1GB, 1s average): $80K/year
DynamoDB for state: $10K/year
SNS/SQS for queueing: $5K/year
Total: $95K/year
Result: Scales automatically, no servers to manage, predictable cost.
Case Study 2: Mid-Market (Lambda → Fargate Migration)
Situation: SaaS company with 500M Lambda invocations/month, 2GB memory, 500ms average latency, growing costs.
Before (Lambda):
Lambda cost: $1.2M/year
NAT Gateway + data transfer: $60K/year
Total: $1.26M/year
After (Fargate):
Fargate (10 tasks, 4 CPU, 8GB each): $360K/year
Network (no NAT Gateway needed): $10K/year
Total: $370K/year
Savings: $890K/year (71% reduction)
Effort: 3 months refactoring + migration
Case Study 3: Enterprise (EC2 On-Demand → Spot + Reserved Hybrid)
Situation: Enterprise with 24/7 API backend, 100B requests/year, on-demand instances.
Before (All On-Demand):
EC2 fleet (40 × c5.4xlarge): $1.5M/year
Operational overhead (1 DevOps engineer): $150K/year
Total: $1.65M/year
After (Spot + Reserved Hybrid):
Reserved instances (20 × c5.4xlarge, 3-year): $450K/year
Spot instances (20 × c5.4xlarge, ~$300K/year baseline): $90K/year (70% discount)
Operational overhead: $100K/year (automated Spot fallback)
Total: $640K/year
Savings: $1.01M/year (61% reduction)
Decision Framework
Workload Pattern
Best Choice
Annual Cost (100M requests)
Event-driven (10M events/month)
Lambda
$50K–$200K
API backend (100M requests/month, sustained)
Fargate or EC2
$300K–$600K (Fargate) or $150K–$400K (EC2 Spot+Reserved)
Batch/async jobs (24/7 fault-tolerant)
EC2 Spot
$100K–$300K (70–90% off on-demand)
Database workload (long-running, stateful)
EC2 dedicated/on-demand
$300K–$1M+
Cost-sensitive, high volume (>5B requests/month)
EC2 Spot + Reserved
$400K–$1M+ (50–80% savings vs on-demand)
Migration Paths
Lambda → Fargate: Refactor event handlers to HTTP server, containerize, deploy to ECS. Effort: 2–4 weeks.
EC2 On-Demand → Spot: Set up Spot instance request, fallback to on-demand, implement interruption handler. Effort: 1–2 weeks.
EC2 On-Demand → Savings Plan: Minimal effort (just purchase commitment). Requires 1+ year lock-in.
Ready to Optimize Your Compute Costs?
Get a personalized analysis of your Lambda, Fargate, and EC2 usage with specific cost reduction recommendations.
Get Your Compute Cost Analysis
Additional Resources
AWS Lambda pricing calculator: https://aws.amazon.com/lambda/pricing/
AWS Fargate pricing: https://aws.amazon.com/fargate/pricing/
EC2 Spot instances: https://aws.amazon.com/ec2/spot/
AWS Lambda power tuning tool: https://github.com/alexcasalboni/aws-lambda-power-tuning
EC2 Spot interruption handler: https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/spot-interruptions.html