Serverless Cost Calculator
Compare AWS Lambda, Cloudflare Workers, and Vercel Functions costs across different traffic patterns. Includes cost formulas, Lambda Power Tuning, and cold start optimization strategies.
Platform Cost Comparison
| Platform | Request Cost | Compute Cost | Free Tier | Cold Starts |
|---|---|---|---|---|
| AWS Lambda | $0.20/1M req | $0.0000166667/GB-s | 1M req + 400K GB-s | 100ms–3s |
| CF Workers | $0.30/1M req | $0.02/M CPU-ms | 100K req/day | ~0ms (V8) |
| Vercel Functions | Free to 100GB-hrs | $0.18/GB-hr | 100 GB-hrs/month | 50–200ms |
| Netlify Functions | Free to 125K req | $25/M req after | 125K req/month | 100–500ms |
| Fly.io Machines | Per-second billing | ~$0.0000019/vCPU-s | 3 shared VMs | ~1s (container) |
Lambda Cost Formula
# Lambda cost calculation
# Cost = (requests × $0.0000002) + (GB-seconds × $0.0000000166667)
# GB-seconds = (memory_mb / 1024) × duration_ms / 1000 × monthly_requests
def calculate_lambda_cost(monthly_requests, memory_mb, avg_duration_ms):
request_cost = monthly_requests * 0.0000002
gb_seconds = (memory_mb / 1024) * (avg_duration_ms / 1000) * monthly_requests
compute_cost = gb_seconds * 0.0000000166667
# Subtract free tier
free_requests = 1_000_000
free_gb_seconds = 400_000
billable_requests = max(0, monthly_requests - free_requests)
billable_gb_seconds = max(0, gb_seconds - free_gb_seconds)
total = (billable_requests * 0.0000002) + (billable_gb_seconds * 0.0000000166667)
return {
"monthly_requests": monthly_requests,
"gb_seconds": round(gb_seconds, 2),
"monthly_cost_usd": round(total, 4)
}
# Examples
configs = [
(1_000_000, 128, 100),
(10_000_000, 256, 200),
(100_000_000, 512, 50),
]
for req, mem, dur in configs:
result = calculate_lambda_cost(req, mem, dur)
print(f"{req/1e6:.0f}M req @ {mem}MB/{dur}ms = ${result['monthly_cost_usd']}/month") Lambda Power Tuning Setup
# Deploy Lambda Power Tuning via SAR
aws serverlessrepo create-cloud-formation-change-set \
--application-id arn:aws:serverlessrepo:us-east-1:451282441545:applications/aws-lambda-power-tuning \
--stack-name lambda-power-tuning \
--capabilities CAPABILITY_IAM \
--parameter-overrides '[{"name":"lambdaResource","value":"*"}]'
# After deploy, invoke the Step Functions state machine
aws stepfunctions start-execution \
--state-machine-arn "arn:aws:states:us-east-1:YOUR_ACCOUNT:stateMachine:powerTuningStateMachine" \
--input '{
"lambdaARN": "arn:aws:lambda:us-east-1:YOUR_ACCOUNT:function:my-api-handler",
"powerValues": [128, 256, 512, 1024, 2048, 3008],
"num": 10,
"payload": "{\"path\":\"/health\"}",
"parallelInvocation": true,
"strategy": "cost"
}'
# strategy options: "cost" | "speed" | "balanced"
# Results visualized at: https://lambda-power-tuning.show/ Memory vs Duration Tradeoff
| Memory | Typical Duration | GB-seconds | Relative Cost |
|---|---|---|---|
| 128 MB | 800ms | 0.1 GB-s | 1.0x (baseline) |
| 256 MB | 420ms | 0.105 GB-s | 1.05x |
| 512 MB | 200ms | 0.1 GB-s | 1.0x (same cost!) |
| 1024 MB | 110ms | 0.11 GB-s | 1.1x |
| 2048 MB | 60ms | 0.12 GB-s | 1.2x |
Higher memory often runs faster enough that total GB-seconds is similar or lower. Always measure with Power Tuning — never guess.
Cold Start Mitigation
# Option 1: Provisioned Concurrency (eliminates cold starts, costs more) aws lambda put-provisioned-concurrency-config \ --function-name my-api-handler \ --qualifier prod \ --provisioned-concurrent-executions 10 # Option 2: EventBridge keep-warm rule (free, reduces cold starts) # Create rule to invoke every 5 minutes aws events put-rule \ --name KeepWarmRule \ --schedule-expression "rate(5 minutes)" aws lambda add-permission \ --function-name my-api-handler \ --statement-id KeepWarmPermission \ --action lambda:InvokeFunction \ --principal events.amazonaws.com \ --source-arn arn:aws:events:us-east-1:YOUR_ACCOUNT:rule/KeepWarmRule # Option 3: Lambda SnapStart (Java 21 runtime) # In function configuration: # SnapStart: ApplyOn: PublishedVersions # Then invoke by version alias, not $LATEST
Frequently Asked Questions
At what scale does Lambda become more expensive than a dedicated server?▼
The crossover point depends on memory allocation and invocation patterns. For a 512MB Lambda running 100ms average, the free tier covers 1M requests and 400,000 GB-seconds per month. At steady-state traffic (millions of requests/day), Lambda cost typically exceeds a t3.small EC2 instance around 5-10M requests/month at 100ms execution. However, Lambda's operational advantage (no capacity planning, zero idle cost, automatic scaling) often justifies higher per-unit costs. Use Lambda for spiky or unpredictable traffic. Use containers or EC2 for steady-state high-volume workloads where you can predict utilization above 50%.
How does Cloudflare Workers pricing compare to Lambda?▼
Cloudflare Workers is often 10-30x cheaper than Lambda for CPU-bound workloads at scale. Workers charges $0.30 per million requests after the first 10M/month (on the $5/month paid plan) with 30ms CPU time included. Lambda charges $0.20 per million requests plus compute time — at 128MB/100ms, that's $0.0000002083/request, or $0.21 per million plus the request fee. Workers runs at the edge globally with no cold starts. The tradeoff: Workers is limited to 30ms CPU time (up to 30s wall time), no persistent disk, limited Node.js compatibility, and no access to AWS services. For edge-computed responses, Workers wins on cost and latency; for complex backend logic with AWS dependencies, Lambda wins on capability.
What is Lambda Power Tuning and how do I use it?▼
Lambda Power Tuning is an open-source AWS Step Functions state machine that runs your Lambda function at multiple memory configurations (128MB to 10GB) and measures execution time and cost at each level. It produces a visualization showing the optimal memory setting for either minimum cost or minimum duration. Run it by deploying the SAR app from the AWS Serverless Application Repository (search 'aws-lambda-power-tuning'), invoke the state machine with your function ARN, number of iterations, and payload. Results often surprise teams — many functions run 3-5x faster at 1024MB vs 128MB with only 2x the memory cost, making them cheaper due to shorter duration billing.
How significant are cold starts and can I eliminate them?▼
Cold start latency ranges from 100ms (Python/Node.js) to 1-3 seconds (Java/.NET) and occurs when a new execution environment is initialized. For user-facing APIs, cold starts above 200ms are perceptible. Mitigation strategies: (1) Provisioned Concurrency — pre-warm a set number of instances, eliminates cold starts but costs the same as always-on. (2) Lambda SnapStart — available for Java, reduces cold start to under 1 second by pre-initializing and snapshotting. (3) Keep functions warm — invoke every 5-10 minutes with a ping (EventBridge rule). (4) Use lighter runtimes — Python and Node.js cold starts are much shorter than JVM-based. (5) Reduce package size — smaller packages initialize faster.
Related Products
on GumroadDeveloper Productivity Bundle
Stop rebuilding the same setup every project. 51 VSCode snippets, 40 Git aliases, 5 Docker Compose stacks, 5 GitHub Actions workflows, 5 README templates, and a dotfiles kit. Set up a professional dev environment in under an hour.
Buy on Gumroad →AI Prompt Engineering Toolkit
58 structured prompt templates for Claude, ChatGPT, and Gemini — organized by use case. Code Review, Debugging, Documentation, Architecture, and 10 model-specific tips. Stop writing prompts from scratch.
Buy on Gumroad →Developer Cheat Sheet Bundle
10 print-ready cheat sheets for the tools developers use every day: Git, Docker, Linux CLI, SQL, Regex, HTTP Status codes, VS Code shortcuts, Bash scripting, jq/JSON, and Markdown.
Buy on Gumroad →You Might Also Need
AWS CDK Infrastructure as Code Guide
Complete AWS CDK guide for TypeScript/Python IaC. Learn constructs (L1/L2/L3), stacks, CDK Pipelines, diff/deploy workflow, and comparison with Terraform and CloudFormation.
Open free tool →
AWS Lambda Cost Calculator
Estimate monthly AWS Lambda costs. Input invocations, duration, memory, and data transfer to get compute cost, request cost, and total with EC2 comparison.
Open free tool →
AWS Cost Estimator
Estimate monthly AWS costs for EC2, RDS, S3, CloudFront, and Load Balancers. Interactive calculator with itemized breakdown.
Open free tool →
More Free Tools
Related Articles
AWS Lambda Cold Start Optimization: 10 Proven Techniques 2026
Eliminate or minimize AWS Lambda cold starts with 10 proven techniques: provisioned concurrency, SnapStart, package minimization, ARM Graviton2, lazy loading, and more with benchmark data.
Cloud Cost Optimization in 2026: Strategies, Tools, and Real-World Savings
Cut your cloud bill without cutting performance. This practical guide covers FinOps practices, cost allocation, resource optimization, reserved capacity strategies, and the tools that help engineering teams understand and reduce cloud spend.
Serverless vs Containers 2026: When to Use Each
Decision framework for choosing between serverless functions and containers in 2026. Cost analysis, cold start realities, architecture patterns, and the right tool for each workload type.
Serverless vs Containers 2026: Lambda vs Docker Decision Guide
When should you use AWS Lambda vs Docker containers? This 2026 guide covers cost models, cold starts, use cases, hybrid architectures, and a decision flowchart to help you choose.
FinOps Engineering: A Developer's Guide to Cloud Cost Optimization in 2026
A practical guide to FinOps for engineers: AWS, GCP, and Azure cost tools, Infracost for Terraform, right-sizing, spot instances, reserved capacity, auto-scaling, and the FinOps maturity model. With code examples for CI/CD cost gates.
Enjoying this tool? Get more like it.
Weekly developer tool guides, productivity playbooks & AI tricks. Free. No spam.
Unlock AI-Powered Dev Tools
- ⚡ AI Code Review, Doc Generator & SQL Builder
- ⚡ All premium templates & early access
- ⚡ Member discounts on Gumroad products
$9/mo after trial · Cancel anytime
Want the full toolkit?
Get DevPlaybook Pro
Every template, guide, boilerplate, and automation script in one bundle. 13 premium products — grab them all at once and save big.
MIT licensed · Instant download · No subscription
See what's included → Browse all deals →