AWS Builder Center

5 Practical Ways to Cut Costs on Serverless AWS Applications

5 Practical Ways to Cut Costs on Serverless AWS Applications

5 Practical Ways to Cut Costs on Serverless AWS Applications

Serverless is often sold as "pay only for what you use," but teams are still routinely surprised by their AWS bill once a Lambda-based application goes into production. The good news: most serverless cost problems come from a handful of repeatable mistakes, and each one has a straightforward fix. This article walks through five techniques I've used to bring real workloads' costs down significantly, with concrete examples using Lambda, DynamoDB, and API Gateway.

1. Right-size Lambda memory (it also controls CPU)

A common misconception is that Lambda memory only affects RAM. In reality, AWS allocates CPU power proportionally to the memory setting. This means a function configured with too little memory can actually cost more overall, because it runs slower and racks up more billed duration — while a function with more memory can finish faster and end up cheaper per invocation.
Don't guess — measure. AWS Lambda Power Tuning is a free, open-source tool (built on Step Functions) that runs your function at several memory levels and plots the cost/performance curve for you, so you can pick the true sweet spot instead of relying on intuition.
In practice, functions doing CPU-bound work (image processing, JSON parsing of large payloads, compression) often see costs drop 30-50% simply by moving from 128 MB to 512 MB or 1024 MB, because the shorter duration more than offsets the higher per-ms rate.

2. Stop paying for idle DynamoDB capacity

If you provisioned DynamoDB read/write capacity based on a rough guess and never revisited it, you're likely paying for headroom you don't use. Two fixes, depending on your traffic pattern:
  • Spiky or unpredictable traffic → switch to on-demand mode. You pay per request with no capacity planning.
  • Steady, predictable traffic → keep provisioned mode, but turn on auto scaling with a target utilization around 70%, and use DynamoDB Accelerator (DAX) if you're re-reading the same hot items repeatedly (a leaderboard, a config table, a session store).
Switching billing mode is a one-line change in the console or CLI. For tables with a clear "hot key" pattern, DAX can cut read costs and latency dramatically because cached reads never touch the table's provisioned throughput at all.

3. Cache at the API Gateway or CloudFront layer

Every Lambda invocation your API Gateway triggers has a cost, even if the underlying data hasn't changed. For endpoints that don't need per-request freshness (product catalogs, public reference data, rarely-changing config), enable API Gateway response caching or put CloudFront in front of the API.
Turning on caching for a stage or method is a checkbox in the console (or a few lines in your infrastructure-as-code template) — no application changes needed. Even a five-minute cache on a busy read endpoint can eliminate 90%+ of the Lambda invocations that would otherwise fire for identical requests.

4. Batch and compress your event sources

If you're processing events from SQS, Kinesis, or DynamoDB Streams, check your batch size setting. Invoking Lambda once per message is far more expensive (and slower) than processing messages in batches, since each invocation carries fixed overhead — cold starts, init time, and per-invocation billing minimums.
Two settings control this on your event source mapping: batch size, and a batching window that tells Lambda to wait a few seconds to accumulate a fuller batch instead of invoking on every single message. For high-throughput queues, tuning these up can cut Lambda invocation counts (and cost) by an order of magnitude.

5. Set a log retention policy — seriously

This one is easy to overlook: by default, CloudWatch Logs groups created by Lambda have no expiration, meaning every log line your functions have ever written is stored (and billed) forever. On a busy application, log storage costs quietly become a meaningful line item.
Setting a retention period (say, 14 or 30 days) takes one setting per log group, and every infrastructure-as-code tool — SAM, CDK, Terraform — supports it as a single property. Set it for every log group as part of your deployment pipeline, and pair it with structured, leveled logging so you're not paying to store verbose debug output in production.

Putting it together

None of these changes require a rearchitecture — they're configuration and operational hygiene. A reasonable order of attack:
  1. Set log retention on every log group (5 minutes of work, immediate savings).
  1. Run Lambda Power Tuning on your top 5 highest-invocation functions.
  1. Check DynamoDB billing mode against actual traffic shape.
  1. Add caching to any read-heavy, low-volatility API endpoint.
  1. Review batch sizes on every event-source-mapped function.
Serverless cost control isn't about avoiding serverless — it's about tuning the same knobs you'd tune on any system: right-sizing compute, caching reads, batching work, and not paying to store data you don't need. Applied consistently, these five changes typically produce a 20-40% reduction in the AWS bill for a Lambda-based application without touching its architecture or user experience.
Any opinions in this article are those of the individual author and may not reflect the opinions of AWS.
Enjoyed reading this content? Let the author know!

Your likes, comments, shares, and saves help creators reach more builders.

Loading recommendations

Loading article