Lambda cost explained: a deep dive into serverless pricing
Lambda bills on requests and on compute measured as memory times duration, with memory also determining CPU. Understanding that model reveals why right-sizing memory, cutting duration, and choosing ARM are the levers that control serverless cost. Here is the full picture.
Quick answer
Lambda has two cost components: a small charge per request and a compute charge measured as memory allocated times execution duration (GB-seconds). The subtlety is that memory allocation also determines CPU, so more memory means faster execution, which can reduce duration and sometimes lower total cost even though the per-second rate rises. The levers that control Lambda cost are therefore: right-size memory (find the sweet spot where more memory pays for itself in speed), cut execution duration, reduce invocations where possible, and switch to cheaper ARM architecture.
Lambda's appeal is that you pay only when your code runs, with no idle server cost. But the pricing model has real subtlety, and misunderstanding it leads to functions that cost far more than they should. The two things you pay for are requests and compute, and the compute charge behaves in a non-obvious way because memory and CPU are linked. Understanding that linkage is what turns Lambda cost from a mystery into a set of clear levers.
The two cost components
| Component | Billed on |
|---|---|
| Requests | A small charge per invocation |
| Compute (GB-seconds) | Memory allocated times execution duration |
Requests are cheap and usually a minor part of the bill unless you have enormous invocation volume. Compute is the main event: it is your allocated memory multiplied by how long the function runs, measured in GB-seconds. A function with more memory or longer duration costs more per invocation. This is the same request-plus-compute shape that appears when estimating the cost to host an API on serverless.
The memory and CPU linkage
Here is the counterintuitive part: Lambda allocates CPU in proportion to memory, so choosing more memory also gives your function more CPU, which makes it run faster. Because you pay for memory times duration, a function that finishes twice as fast at double the memory can cost roughly the same, and sometimes less if the speedup more than offsets the higher memory. This means the cheapest memory setting is often not the smallest one. Finding that sweet spot is the single most important Lambda optimization.
Right-sizing memory
Because of the memory and CPU linkage, right-sizing memory is not about picking the minimum; it is about testing several memory settings and measuring total cost (memory times the resulting duration) at each. CPU-bound functions often get cheaper as you add memory up to a point, because the speed gain outweighs the rate increase; memory-light, IO-bound functions may not benefit. Tune per function rather than applying one setting everywhere, and revisit as the code changes. This is the highest-leverage lever in the model.
Cutting duration and invocations
Since compute is memory times duration, anything that shortens execution lowers cost: faster code, less work per invocation, avoiding slow synchronous calls, and reusing connections across invocations. Reducing invocation count helps too, batching events, caching results, and avoiding needless retries. And watch for idle wait time inside a function (a function blocked waiting on a slow downstream call still bills for that duration), which is pure waste. These duration savings compound with memory right-sizing.
Architecture and the full lever set
The last major lever is architecture: moving to ARM-based Graviton cuts the compute rate by about 20 percent with often equal or better performance, as covered in Lambda ARM Graviton savings. Put the levers together, right-size memory to the cost sweet spot, cut duration, reduce invocations, and switch to ARM, and you control Lambda cost systematically rather than hoping it stays small. For a serverless-heavy system, fold these into the broader SaaS backend cost picture and track them as part of your FinOps KPIs. Lambda is cheap when idle and controllable when busy, but only if you understand that memory, CPU, and duration move together.
FAQ
How is AWS Lambda priced?
On two components: a small charge per request (invocation) and a compute charge measured as memory allocated times execution duration, in GB-seconds. Requests are usually minor unless invocation volume is enormous; compute is the main cost. Because memory allocation also determines CPU, the compute component behaves non-obviously, which is where most Lambda cost surprises and optimization opportunities come from.
Why does more Lambda memory sometimes cost less?
Because Lambda allocates CPU in proportion to memory, so more memory means more CPU and faster execution. Since you pay for memory times duration, a function that finishes twice as fast at double the memory can cost about the same or less if the speedup outweighs the higher memory rate. So the cheapest memory setting is often not the smallest, especially for CPU-bound functions.
How do I right-size Lambda memory?
Test several memory settings and measure total cost (memory times the resulting duration) at each, rather than defaulting to the minimum. CPU-bound functions often get cheaper as you add memory up to a point because the speed gain outweighs the rate increase; IO-bound functions may not benefit. Tune per function rather than applying one setting everywhere, and revisit as the code changes.
How do I reduce Lambda cost?
Right-size memory to the cost sweet spot (accounting for the memory-CPU linkage), cut execution duration with faster code and connection reuse, reduce invocations by batching and caching, eliminate idle wait time inside functions, and switch to ARM-based Graviton for about 20 percent cheaper compute. These levers compound, so a busy function tuned across all of them can cost substantially less than an untuned one.
Does idle wait time inside a Lambda cost money?
Yes. Lambda bills for the entire execution duration, so a function blocked waiting on a slow downstream call still pays for that wait time even though it is doing no useful work. That idle wait is pure waste. Reducing it (faster downstreams, asynchronous patterns, avoiding blocking calls) directly lowers the duration you are billed for, which is one of the cleaner duration savings available.
Does C3X price Lambda functions before deploy?
C3X reads your Terraform and prices Lambda functions against a live catalog before deploy, so the memory, architecture, and configuration choices that drive function cost are visible in the pull request. Invocation volume and duration depend on runtime behavior, but the structural cost decisions (memory allocation, ARM versus x86) that shape the bill are exactly what C3X surfaces at design time.
What to do next
Price your serverless functions before they ship. C3X reads your Terraform and prices your resources against a live catalog. Start with the quickstart.
Share this post
Try C3X on your own Terraform
Free and open source. No API key required. One command to install, one command to estimate.