Files
lambda_local_runner/docs/lambdas-md/lambda-13-cost.md
2026-05-11 20:13:11 -03:00

43 lines
3.1 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# Cost
> Pricing model, memory/cost trade-off, x86 vs arm64, free tier, common surprises.
## The pricing formula
Lambda billing has two components, both permanent free tiers included:
| Component | x86_64 | arm64 | Free tier (permanent) |
|-----------|--------|-------|------------------------|
| **Requests** | $0.20 / 1M | $0.20 / 1M | 1M / month |
| **Duration** | $0.0000166667 / GB-s | $0.0000133334 / GB-s | 400 000 GB-s / month |
GB-seconds = memory configured (GB) × duration (seconds). A 512 MB function running for 300 ms = 0.5 × 0.3 = 0.15 GB-s. At 1 million invocations, that's 150 000 GB-s — well inside the free tier.
Duration is billed in **1 ms increments**. The old 100 ms minimum is gone (removed in 2020).
## Memory vs cost: more can be cheaper
CPU scales linearly with memory. A function configured at 1 769 MB gets a full vCPU; below that it's a fraction. Doubling memory often more than halves duration for CPU-bound work, which means the total GB-s cost stays the same or decreases — while latency drops.
**AWS Lambda Power Tuning** is a Step Functions state machine that automatically benchmarks your function at multiple memory sizes and produces a cost/performance curve. Run it before guessing at the right memory setting. The optimal point is almost never the default 128 MB.
## arm64 saves ~20%
arm64 duration pricing is 20% cheaper than x86. Same request price. If your function is compute-bound (not I/O-bound sleeping on S3 calls), arm64 also runs faster, compounding the saving. For I/O-bound functions (like `lambda_function.py`, which spends most of its time waiting on S3), the duration difference is smaller but the 20% price reduction still applies.
## Provisioned Concurrency billing
PC is billed separately: $0.0000097222 per GB-s of provisioned time (x86) — even when idle. If you have 10 × 512 MB environments provisioned for 24 hours: 10 × 0.5 GB × 86 400 s = 432 000 GB-s/day = ~$4.20/day = ~$126/month just for the warm slots, before counting actual invocation cost on top. PC is for latency, not cost — it always increases your bill.
## Hidden costs (the real bill)
- **NAT Gateway** — $0.045/hr per AZ (~$32/month) + $0.045/GB data. Often the largest line item for VPC Lambda.
- **API Gateway** — REST API: $3.50/1M calls. HTTP API: $1/1M. Can dwarf Lambda cost at high RPS.
- **CloudWatch Logs** — $0.50/GB ingestion + $0.03/GB storage/month. Verbose Lambda logs accumulate fast; set retention.
- **Lambda Insights** — additional CW Logs + custom metrics charges.
- **X-Ray** — $5/million traces (after free 100K/month).
- **Data transfer** — traffic leaving a region or going through a NAT has per-GB charges.
- **S3 API calls** — LIST and GET requests are billed per 1 000. A function that does 10 000 LIST calls/invocation at 1M invocations = 10B API calls = real money.
> ✅ **For this project's function:** at 1 000 invocations/day with 500 ms average duration and 256 MB memory, cost is ~$0.002/day — essentially free. Lambda's economics only require attention above ~100K invocations/day with non-trivial memory or duration.