Skip to main content

Serverless Cost Invocation Estimator

Calculate AWS Lambda and serverless costs including API Gateway and data transfer. Enter values for instant results with step-by-step formulas.

Frequently Asked Questions

When is serverless cheaper than EC2?

Serverless wins for: Variable, spiky traffic (scale to zero when idle). Low utilization (<20% of time active). Unpredictable demand. Event-driven workloads. EC2 wins for: Steady, high-volume traffic (>10M requests/day consistently). Long-running processes (>15 min). Specific hardware needs (GPU, high memory). Breakeven example: t3.medium ($30/month) handles ~10M requests/month at 100% utilization. Lambda at 10M requests, 200ms, 512MB: ~$35/month. Similar cost, but Lambda scales automatically; EC2 needs auto-scaling setup. At 50M requests, EC2 clearly cheaper ($30 vs $150+ Lambda).

What are the hidden costs of serverless?

Beyond Lambda: (1) API Gateway: $3.50/million (REST) or $1/million (HTTP). Often exceeds Lambda compute cost. (2) Data transfer: $0.09/GB out to internet. (3) CloudWatch Logs: $0.50/GB ingested + $0.03/GB stored. Verbose logging adds up. (4) NAT Gateway: $0.045/hour + $0.045/GB if Lambda in VPC accesses internet. (5) DynamoDB/RDS connections: DynamoDB pay-per-request or provisioned; RDS Proxy for connection pooling. (6) Step Functions: $0.025/1000 state transitions. Mitigation: Use HTTP APIs (not REST), compress logs, cache in CloudFront, avoid VPC unless necessary.

How does serverless scale during traffic spikes?

Lambda scales automatically: Concurrent executions increase as requests arrive. Default: 1,000 concurrent per region (can request increase). Provisioned concurrency: Pre-warmed instances (no cold start) at $0.015/GB-hour. Use for latency-sensitive endpoints. Burst limit: 3,000 (or 500-1,000 in some regions) initial burst, then 500/minute increase. Throttling: If limits exceeded, requests get 429 errors. Plan: Request limit increase before expected spike, use provisioned concurrency for critical paths, implement retry logic in clients. Compared to EC2: Auto-scaling takes 3-5 minutes; Lambda scales in milliseconds.

How do I calculate serverless cost per API call?

Total cost per call = (Lambda compute + Lambda invocation + API Gateway + Data transfer) / Invocations. Example: 1M API calls/month, 200ms duration, 512MB, 1KB response. Lambda invocation: (1M - 1M free) × $0.0000002 = $0 (within free tier). Lambda compute: 1M × 0.2s × 0.5GB = 100K GB-sec - 400K free = $0. API Gateway (HTTP): 1M × $0.000001 = $1. Data transfer: 1M × 1KB = 1GB × $0.09 = $0.09. Total: $1.09/month = $0.00000109/call. At 10M calls: Lambda $1.67, API $10, transfer $0.90 = $12.57 = $0.00000126/call. Economies of scale in invocation/compute; API Gateway scales linearly.

References