When we specify the memory size for a Lambda function, AWS will allocate CPU proportionally. For example, a 256 MB function will receive twice the processing power of a 128 MB function. That looks simple and straightforward, but…

I had this question: would there be an ideal memory size that minimizes the cost of running a given task on Lambda?

In order to answer that, I tested the same task running on multiple memory sizes to check whether such cost/memory trade-off sweet spot exists.

Benchmark Lambdas

I created two Lambda functions to run this test:

  • Fibonacci: basic code that generates a sequence of… you guessed it, Fibonacci numbers! It’s just a low-memory, CPU-intensive task.
  • Benchmarker: invokes the Fibonacci function (or any other function) multiple times, switching memory sizes; in the end, it averages out the results to determine which memory size optimizes speed and cost.

The  code is open sourced, in case you’d like to test your own Lambdas. The results presented below will certainly vary according to the function you test, so I encourage you to download the Benchmarker Lambda and run it for yourself.

Photo by  Stephen Dawson on  Unsplash

#aws-lambda #monitoring #observability #serverless

Lower Your AWS Lambda Bill By increasing Memory Size — Yep!
1.20 GEEK