Over-Provisioned Lambda Memory
CostLens identifies Lambda functions allocated more memory than they need, based on actual execution time patterns.
AWS Lambda charges are based on GB-seconds — the amount of memory allocated multiplied by execution duration. If a function is allocated more memory than it actually uses, and its execution time is consistently short, you are paying for compute capacity that provides no benefit. CostLens identifies these functions and recommends reducing their memory allocation.
How it works
CostLens lists all Lambda functions
Calls lambda:ListFunctions to retrieve all functions in each configured region.
Evaluates execution duration
Queries CloudWatch for the P99 (99th percentile) duration of each function over the past 14 days.
Identifies over-provisioned functions
Flags functions that are allocated more than 256 MB and consistently complete in under 100 ms. Fast execution at high memory allocation is a reliable signal that the memory is not being used.
Calculates savings
Estimates monthly savings based on the difference between current and recommended memory allocation, function duration, and an assumed invocation volume. Recommends reducing to 50% of current allocation (minimum 128 MB).
What to do
- Open the recommendation and review the current memory, recommended memory, and P99 duration.
- If the function is straightforward (event processing, lightweight data transformation), the reduction is likely safe.
- Apply the fix. CostLens calls
lambda:UpdateFunctionConfigurationto set the new memory value. - Monitor the function's error rate and duration in CloudWatch for the next 24 hours.
- If errors increase or duration spikes, manually restore the previous memory setting in the Lambda console and dismiss the recommendation.
Test in non-production first
Deploy the memory change to a non-production alias or version first if your function handles critical business logic, as execution behaviour can vary under different load conditions.
Severity levels
| Severity | Estimated monthly savings |
|---|---|
| critical | >$500 |
| high | $100–$500 |
| medium | $20–$100 |
| low | <$20 |
Required IAM permissions
Included in the CostLens IAM policies from AWS Accounts:
lambda:ListFunctions
cloudwatch:GetMetricStatistics
lambda:UpdateFunctionConfiguration
Limitations
- P99 duration is used as a proxy for memory utilisation. Functions with variable loads may behave differently under peak traffic — verify before applying.
- Very infrequently invoked functions may have insufficient CloudWatch data for a reliable assessment. CostLens will not flag functions without enough data points.
- Memory reduction may increase execution duration. Lambda pricing may still favour higher memory if the duration increase outweighs the memory saving — review the CostLens savings estimate carefully.