devops

AWS Lambda vs Containers: Real Cost Comparison Nobody Shows You

Actual dollar numbers: when Lambda is cheaper, when containers win, and the hidden costs that flip the math. Includes calculator examples at 3 traffic levels.

April 7, 2026·6 min read·
#aws#lambda#serverless#containers#cost-optimization

Every serverless tutorial says "Lambda is cheap." Every containers tutorial says "Lambda gets expensive at scale." Both are right. Neither tells you where the crossover actually is.

I've run this math on real production workloads. Here's the actual breakdown.

The Setup

Two identical APIs. Same logic, same database, same traffic pattern. One runs on Lambda, one on ECS Fargate (containers).

Traffic profile:

  • Peak: 500 req/s for 4 hours/day
  • Off-peak: 5 req/s for 20 hours/day
  • Avg request duration: 200ms
  • Memory: 256MB

Let's run the math.

Lambda Cost at This Traffic Level

Invocations per month:

  • Peak: 500 × 3600 × 4 × 30 = 216M invocations
  • Off-peak: 5 × 3600 × 20 × 30 = 10.8M invocations
  • Total: ~227M invocations/month

Compute (GB-seconds):

  • 227M × 0.2s × 0.25GB = 11.35M GB-seconds

Lambda pricing (us-east-1, 2026):

  • Requests: 227M × $0.0000002 = $45.40
  • Compute: 11.35M × $0.0000166667 = $189.16
  • Free tier (first 1M requests + 400K GB-sec): subtract ~$6.67
  • Lambda total: ~$228/month

Fargate Cost at This Traffic Level

For 500 req/s peaks with 200ms response time, you need ~2 tasks (1 vCPU / 2GB each) running 24/7 for availability:

Fargate pricing (us-east-1):

  • vCPU: 2 × $0.04048/hr × 730hr = $59.10
  • Memory: 2 × 2GB × $0.004445/GB/hr × 730hr = $12.98
  • ALB: ~$25/month base + LCU charges ~$5
  • Fargate total: ~$102/month

Lambda loses at this traffic level by ~$126/month.

Where Lambda Actually Wins

The math flips at low, unpredictable traffic.

Low-traffic scenario:

  • 100K requests/month
  • 500ms avg duration
  • 512MB memory

Lambda:

  • Requests: 100K × $0.0000002 = $0.02
  • Compute: 100K × 0.5s × 0.5GB = 25K GB-sec → within free tier
  • Lambda: ~$0/month (free tier)

Fargate (minimum viable, 1 task 0.25 vCPU / 0.5GB):

  • vCPU: $0.01012/hr × 730hr = $7.39
  • Memory: 0.5GB × $0.001111/hr × 730hr = $0.41
  • ALB: $16/month minimum
  • Fargate: ~$24/month

Lambda wins by $24/month.

The Crossover Chart

Based on this analysis, the crossover point for a typical web API (200ms, 256MB):

| Monthly Requests | Lambda | Fargate (min) | Winner | |-----------------|--------|---------------|--------| | < 10M | < $5 | ~$24 | Lambda | | 10M–50M | $5–$25 | ~$24–$50 | Depends | | 50M–200M | $25–$100 | ~$50–$90 | Fargate | | 200M+ | $100+ | ~$90–$200+ | Fargate |

The crossover is typically 20–50M requests/month depending on duration and memory.

The Hidden Costs Nobody Includes

Lambda Hidden Costs

Cold starts hurt revenue. For user-facing APIs, Lambda cold starts add 300ms–2s latency. If you're running Provisioned Concurrency to eliminate cold starts:

  • 10 provisioned = $0.015/hr × 730hr × 10 = $109.50/month
  • That alone is more than Fargate at many traffic levels.

Duration pricing is per-millisecond but billed at 1ms increments. Your 200ms function that sometimes takes 210ms gets billed for 210ms. Optimize function duration aggressively.

API Gateway adds up fast. At 100M requests: API Gateway HTTP API = $10. REST API = $35. Lambda alone doesn't cover your API exposure cost.

Fargate Hidden Costs

You pay for idle. 2 tasks running 24/7 cost the same whether you're at 0 req/s or 500 req/s. Lambda scales to zero; Fargate doesn't (unless you set min tasks = 0 and accept cold start latency).

NAT Gateway is a silent killer. Fargate tasks in private subnets need NAT Gateway to call AWS services: $0.045/GB processed. A service calling S3 or DynamoDB heavily can add $50–200/month just in NAT charges.

ECR image storage + pull fees. Small but real: $0.10/GB/month storage + $0.09/GB data transfer out. 1GB image pulled by 10 tasks = $0.90/pull. At 10 deploys/month = $9 just for image pulls.

Real-World Decision Framework

Choose Lambda when:

  • Traffic is unpredictable or spiky with long idle periods
  • Budget is tight and scale is unproven
  • Functions are truly stateless and short-lived (<15min)
  • You want zero-maintenance scaling
  • Monthly requests < 20M

Choose Fargate/containers when:

  • Consistent traffic (24/7 load)
  • Long-running processes (>15min)
  • Cold start latency is unacceptable
  • You need WebSockets or persistent connections
  • Monthly requests > 50M
  • Migrating existing containerized workloads

Choose both (hybrid) when:

  • Core API on containers, background jobs on Lambda
  • Real-time user-facing on containers, batch processing on Lambda
  • Multi-region: primary on Fargate, failover Lambda for burst

The Architecture That Often Wins

For most SaaS products at $1M–$10M ARR:

User → CloudFront → ALB → ECS Fargate (API, 2 tasks)
                              ↓
                    Lambda (async jobs, webhooks, crons)

You get:

  • Predictable API latency (no cold starts for users)
  • Zero cost for background jobs at low volume
  • Simple horizontal scaling for the API tier
  • Lambda handles burst events without over-provisioning containers

This hybrid runs $80–150/month for most early-stage products — cheaper than Lambda-only once you add Provisioned Concurrency, and more reliable.

Quick Cost Calculator

For your own workload:

Lambda monthly cost = 
  (requests × $0.0000002) + 
  (requests × duration_sec × memory_GB × $0.0000166667)

Fargate monthly cost =
  (tasks × vcpu × $0.04048 × 730) +
  (tasks × memory_GB × $0.004445 × 730) +
  ALB_base ($16) +
  NAT_Gateway_estimate

Plug in your numbers before committing to either architecture. The "serverless is cheap" assumption costs companies tens of thousands per year when traffic grows.

FAQ

Q: Does Lambda@Edge change the math? A: Yes — Lambda@Edge runs in 400+ CloudFront PoPs and costs 3x standard Lambda. Only use it for true edge logic (auth, redirects, A/B testing). Move business logic to regional Lambda or containers.

Q: What about Lambda SnapStart for Java? A: SnapStart eliminates cold starts for Java Lambda functions by taking a snapshot after init. Makes Lambda much more competitive for Java workloads that previously needed Provisioned Concurrency.

Q: Is Lambda good for database-heavy workloads? A: Careful — each Lambda invocation opens a new DB connection. At 500 req/s, that's 500 simultaneous connections. Use RDS Proxy to pool connections, or the math changes significantly (RDS Proxy adds ~$0.015/vCPU-hour).

Q: When does Lambda become truly cost-prohibitive? A: Above 1B requests/month, Lambda compute alone exceeds $1,000/month for typical workloads. At that scale, reserved EC2 instances or Fargate Savings Plans are significantly cheaper.

#aws#lambda#serverless#containers#cost-optimization
D
DevToCashAuthor

Senior DevOps/SRE Engineer · 10+ years · Professional Trader (IDX, Crypto, US Equities)

I write about real infrastructure patterns and trading strategies I use in production and in live markets. No courses, no affiliate hype — just documentation of what actually works.

More about me →