Right-Size Memory

Use AWS Lambda Power Tuning to benchmark memory configurations and choose the cheapest setting that still meets your latency targets.

Overview

Higher memory = more vCPU and network throughput per invocation, which can reduce execution time for CPU-bound or IO-heavy functions. The per-millisecond price increases with memory, but total cost can still drop when your function finishes much faster at a higher setting.

Testing different memory configurations is essential to find the sweet spot.

AWS Lambda Power Tuning

Is an open-source Step Functions state machine from AWS Labs that runs your function with different memory settings, captures cost and latency metrics, and recommends the best balance for your workload automatically.

You can deploy it straight from the official repository: alexcasalboni/aws-lambda-power-tuning.

Install:

git clone https://github.com/alexcasalboni/aws-lambda-power-tuning
cd aws-lambda-power-tuning
sam deploy --guided

Run Test:

{
  "lambdaARN": "arn:aws:lambda:region:account:function:my-function",
  "powerValues": [128, 256, 512, 1024, 2048, 3008],
  "num": 10,
  "payload": {}
}

Returns visualization showing cost vs performance trade-offs across memory settings so you can see where higher memory reduces total cost and where it only increases spend.

Best Practices

  • Test with realistic payloads and traffic patterns, not toy examples
  • Run each configuration multiple times to smooth out cold starts and network variance
  • Monitor p50, p90, p99 durations and error rates for each memory setting
  • Balance cost vs performance requirements, and prefer the cheapest configuration that still meets your latency and reliability targets