AWS Lambda cost optimization (high-leverage fixes)
Lambda cost optimization is mostly about reducing GB-seconds (duration × memory) and preventing accidental multipliers (retries, verbose logs, and expensive networking paths). Use this checklist to find the biggest wins first, then validate savings with billing.
High-leverage Lambda knobs
- Memory vs duration: right-size to reduce total GB-seconds.
- Provisioned concurrency: use only for latency-critical paths.
- Request volume: reduce retries and noisy clients first.
1) Reduce duration (fix the slow parts first)
- Remove cold-start bloat: smaller bundles, fewer dependencies, faster initialization.
- Reduce downstream latency: cache hot reads and avoid chatty per-request calls.
- Batch work where possible (especially for stream/queue processing).
2) Right-size memory by testing (duration vs memory curve)
Memory affects both cost and performance. Try a few memory sizes and compare total cost per 1M requests (or per job run), not just duration.
- Measure p50 and p95 duration at each memory size.
- Pick the best “cost per unit of work” point, not the smallest memory number.
3) Eliminate retries and wasted invocations (the common spike driver)
- Set timeouts and retry policies intentionally; don’t let defaults amplify incidents.
- Use idempotency where retries are unavoidable.
- Watch for upstream retry storms: one incident can multiply invocations and duration.
4) Be deliberate about concurrency and cold starts
- Cold starts often increase duration; frequent cold starts can raise GB-seconds.
- Provisioned concurrency can reduce cold starts but adds baseline cost.
- Separate “SLA paths” from background jobs; they need different concurrency choices.
Guide: concurrency and cold starts
5) Reduce logging and networking bills
- Logs: reduce verbosity, sample high-volume logs, and set retention deliberately.
- Networking: avoid routing through NAT by accident; model egress and transfer explicitly.
6) Validate savings (don’t guess)
- Compare billed GB-seconds and request count before/after changes.
- Check duration distribution (p50/p95) and error/retry rate; spikes usually correlate with these.
- Verify log ingestion GB/day and retention dropped if that was a target.
Common pitfalls
- Reducing memory without measuring duration (can increase GB-seconds).
- Optimizing code but leaving retries/timeouts to multiply invocations.
- Using provisioned concurrency broadly instead of only for latency-sensitive paths.
- Ignoring logs and transfer until they become top line items.
- Not re-checking after traffic growth (optimization needs a feedback loop).
Related tools and guides
Sources
Related guides
Fargate cost optimization (high-leverage fixes)
A practical Fargate cost optimization checklist: rightsize tasks, scale on real signals, reduce idle capacity, and avoid hidden networking and logging costs.
NAT Gateway cost optimization (high-leverage fixes)
A practical playbook to reduce NAT Gateway spend: cut GB processed with private connectivity, remove recurring downloads, prevent retry storms, and validate savings with metrics/flow logs.
AWS Lambda pricing (what to include)
A practical checklist for estimating AWS Lambda-style costs: requests, duration × memory (GB-seconds), provisioned concurrency when used, logs, and common hidden line items.
Lambda vs Fargate cost: a practical comparison (unit economics)
Compare Lambda vs Fargate cost with unit economics: cost per 1M requests (Lambda) versus average running tasks (Fargate), plus the non-compute line items that often dominate (logs, load balancers, transfer).
AWS Fargate pricing (cost model + pricing calculator)
A practical Fargate pricing guide and calculator companion: what drives compute cost (vCPU-hours + GB-hours), how to estimate average running tasks, and the non-compute line items that usually matter (logs, load balancers, data transfer).
AWS RDS cost optimization (high-leverage fixes)
A short playbook to reduce RDS cost: right-size instances, control storage growth, tune backups, and avoid expensive I/O patterns.
Related calculators
Log Cost Calculator
Estimate total log costs: ingestion, storage, and scan/search.
Log Ingestion Cost Calculator
Estimate monthly log ingestion cost from GB/day or from event rate and $/GB pricing.
Log Retention Storage Cost Calculator
Estimate retained log storage cost from GB/day, retention days, and $/GB-month pricing.
Log Search Scan Cost Calculator
Estimate monthly scan charges from GB scanned per day and $/GB pricing.
FAQ
What’s the biggest lever for Lambda cost?
Reducing GB-seconds: lower duration and right-size memory. For many systems, eliminating retries and controlling log volume can save more than micro-optimizing code.
Does lowering memory always save money?
Not always. Lower memory can increase duration. The right approach is to test a few memory sizes and pick the best cost/performance point for your function.
What causes Lambda cost spikes?
Retry storms, downstream latency, sudden increases in invocation count, and verbose logs. Cold-start mitigation choices (like provisioned concurrency) can also add baseline spend.
Last updated: 2026-02-07