AWS cost · Lambda
Lambda memory over-provisioning and the CPU trap
Lambda bills memory multiplied by time, and you choose the memory. Set it to 1024 MB because that was in the example you copied, and every invocation for the next three years is priced at 1024 MB - even if the function never touches 200.
A function at 1024 MB running 200 ms, ten million times a month, costs about $33.33 in us-east-1. Halving the memory halves that - unless it doubles the duration, which is what a CPU-bound function does.
The arithmetic, and where it stops working
| What | Cost | Note |
|---|---|---|
| Duration | $0.0000166667/GB-second | us-east-1, first 6 billion GB-seconds |
| 1024 MB, 200 ms, 10M invocations | ~$33.33/month | the starting point |
| The same at 512 MB, duration unchanged | ~$16.67/month | the saving people expect |
| The same at 512 MB, duration doubled | ~$33.33/month | what a CPU-bound function does instead |
The last two rows are the same change with two outcomes. Which one you get depends on what the function spends its time doing.
Memory is also the CPU dial
Lambda does not let you choose processing power separately. CPU scales with the memory setting, so the number labelled memory is really the size of the machine.
That splits functions into two kinds. One waits on a database, an API or S3. Its duration barely moves when the CPU shrinks, so cutting memory is close to a pure saving. The other computes, and cutting memory stretches it out until the GB-seconds are unchanged and the only thing that moved is your latency.
The same logic runs the other way. Raising memory on a CPU-bound function can make it cheaper, because it finishes far enough ahead to pay for the bigger machine.
Why nobody fixes this
Because the number you would need is not where you would look for it. CloudWatch publishes invocations, duration, errors and throttles for every function by default - and not memory. There is no metric to graph and no alarm to set on memory you are not using.
The figure does exist. Every invocation writes a REPORT line into the function log carrying max memory used. The evidence is in CloudWatch Logs rather than CloudWatch Metrics. Lambda Insights turns it into a proper metric, but it is opt-in per function and costs extra. On most accounts, most functions have never been measured.
How to check
# every function and the memory it is configured for
aws lambda list-functions \
--query 'Functions[].{Name:FunctionName,MB:MemorySize,Timeout:Timeout,Runtime:Runtime}' \
--output table
# what one actually used - the REPORT line carries max memory used
aws logs filter-log-events --log-group-name /aws/lambda/my-function \
--filter-pattern "REPORT" --limit 20 \
--query 'events[].message' --output textStart with the functions that run most, not the ones whose setting looks most wrong. The waste is per invocation, so a badly sized function nobody calls is not worth recovering.
What the fix costs
Changing memory changes CPU, so the duration you were counting on is no longer the duration you have. Re-measure after every change, and compare GB-seconds rather than milliseconds - a function that got faster and more expensive is easy to ship by accident.
Leave headroom above the observed maximum. Exceeding the memory limit does not slow the function down, it kills the invocation. This is one of the few cost changes with a hard failure mode.
# MUTATING - changes CPU as well as memory; re-measure duration after
aws lambda update-function-configuration \
--function-name my-function --memory-size 512For where the rest of a Lambda bill goes - requests, duration, and the things that dwarf both at scale - see is Lambda expensive.
Want to know which functions are paying for memory they never touch? Connect your account read-only and see what it is wasting, in real dollars.
The role can only read - Get, Describe, List, nothing else. Read the exact permissions before you deploy it, and delete the stack whenever you want.
Frequently asked questions
How is AWS Lambda memory billed?+
In GB-seconds: configured memory multiplied by how long the function runs. In us-east-1 that is $0.0000166667 per GB-second for the first 6 billion, dropping to $0.000015 and then $0.0000133334 at higher volumes. You pay for the memory you configured, not the memory you used.
Does halving Lambda memory halve the cost?+
Only if the duration stays the same. Lambda scales CPU with memory, so halving memory also halves the processing power. A CPU-bound function then takes about twice as long, the GB-seconds come out the same, and you have added latency for nothing.
How do I see how much memory a Lambda function actually uses?+
Not from CloudWatch metrics - Lambda publishes invocations, duration, errors and throttles by default, but not memory. The real figure is in the function's own logs: every invocation writes a REPORT line carrying max memory used. Lambda Insights reports it as a metric, but it is opt-in per function and costs extra.
What memory setting should I use?+
Measure rather than guess, because the answer is not monotonic. Raising memory can make a CPU-bound function cheaper by finishing sooner; lowering it can make an idle-waiting function cheaper because the duration will not move. Test a few settings against a realistic payload and compare GB-seconds, not milliseconds.
What happens if I set the memory too low?+
The function is killed when it exceeds the limit, and the invocation fails. Unlike most cost changes this one has a hard failure mode, so leave headroom above the observed maximum rather than trimming to it.
Is over-provisioned memory worth fixing at all?+
It depends entirely on invocation volume. The waste is per invocation, so a function called ten times a day is not worth anyone's afternoon, and one called ten million times a month is. Sort by invocations before you sort by how wrong the setting looks.
Related cost breakdowns
Why EKS is expensive: the $73/month control plane
Every EKS cluster bills $0.10/hour - about $73/month - for the control plane before a single node runs, and $0.60/hour once it falls out of standard support. Idle and forgotten clusters are pure waste.
Why your stopped EC2 instance is still being charged
A stopped EC2 instance keeps billing for its attached EBS disk and any Elastic IP. One 8 GB volume quietly cost me ~$70 over six years. Here is what still charges when an instance is off.
Spot instances: what is safe to run on them, and what is not
Spot instances are up to 90% cheaper than on-demand - I moved almost everything to spot. The catch is a 2-minute interruption notice. Here is what is safe to run on spot and what is not.
Graviton (ARM) is ~20% cheaper than x86 for the same work
AWS Graviton instances cost about 20% less than comparable x86 at equal or better performance, and arm64 Lambda is a one-dropdown switch. Here is how to find migration candidates.