Skip to main content

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.

✓ Cost formula table ✓ Lambda Power Tuning ✓ Cold start guide ✓ Memory vs duration

Platform Cost Comparison

Platform Request Cost Compute Cost Free Tier Cold Starts
AWS Lambda$0.20/1M req$0.0000166667/GB-s1M req + 400K GB-s100ms–3s
CF Workers$0.30/1M req$0.02/M CPU-ms100K req/day~0ms (V8)
Vercel FunctionsFree to 100GB-hrs$0.18/GB-hr100 GB-hrs/month50–200ms
Netlify FunctionsFree to 125K req$25/M req after125K req/month100–500ms
Fly.io MachinesPer-second billing~$0.0000019/vCPU-s3 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 MB800ms0.1 GB-s1.0x (baseline)
256 MB420ms0.105 GB-s1.05x
512 MB200ms0.1 GB-s1.0x (same cost!)
1024 MB110ms0.11 GB-s1.1x
2048 MB60ms0.12 GB-s1.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.

Share this tool: X / Twitter LinkedIn
✓ 60,000+ developers use DevPlaybook ★★★★★ 4.8 / 5 on Gumroad ✓ MIT licensed · Instant download ✓ No login required

Related Products

on Gumroad

You Might Also Need

More Free Tools

Related Articles

Enjoying this tool? Get more like it.

Weekly developer tool guides, productivity playbooks & AI tricks. Free. No spam.

DevPlaybook Pro 7 days free

Unlock AI-Powered Dev Tools

  • ⚡ AI Code Review, Doc Generator & SQL Builder
  • ⚡ All premium templates & early access
  • ⚡ Member discounts on Gumroad products
Start Free Trial →

$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.

$79
$241 separately Save $162 (67% off)
Get DevPlaybook Pro — $79 →

MIT licensed · Instant download · No subscription

See what's included → Browse all deals →