Automation tool for AWS Lambda sizing

As a continuation to my post on best practices on AWS Lambda I wrote a tool which finds the right size of your existing Lambda function programmatically by continuously resizing it, firing test events at it until it finds the best size which would either:

  1. Save you the most money OR
  2. Give you the best performance

Currently, in its first version it gives auto resizing options based on best latency with configurable acceptable drop in performance (e.g. 3%) in favor of cost savings. I will be building up this tool to have more such strategies and refining it as I go.

Find the project under MIT license on github here.

Prerequisites

You need .NET core installed wherever you run this tool, .NET core is open source and cross-platform so get one for your own OS.

The server / PC you run it on must either be running under a AWS Role having permissions to resize, get configurations and invoke Lambda functions or if you are on your PC, provide the credentials by keeping it in standard locations as AWS recommends here.

Using the tool

You can run it in command line mode by simply giving some arguments, in .NET core command line is run via the dotnet.exe file:

"C:\Program Files\dotnet\dotnet.exe" aws.lambda.sizeOptimizer.dll [-?|-h|--help] [-r |--aws-region <region>] [-n |--fn-name <functionName>] [-p |--payload-path <payloadPath>] [-64 |--use-64mb] [-l |--latency-margin <acceptableDropInPerformance>] [-ar |--auto-resize]

Running it manually

Simply run the program without giving it any arguments and it will ask for input.

Want to contribute?

I am open (and actually looking forward) to pull requests on the project.

Setting up the environment

You need Visual Studio Code, Visual studio code is a free and open source code editor developed by Microsoft. It is cross-platform and works with Windows, MAC and Linux, for more features and background on this checkout this wiki link.

In my experience with this code editor, it is by far the best free code editor that I have worked with. Its ability to go multi-platform along with being free to use while supporting all the languages that I will ever use (with plugins installed) it is a go-to IDE for anyone on a budget or a requirement of cross-platform targeting.

If you don’t have .Net core installed get it from here.

Install the c# extension for VS code from VS code marketplace.

You can optionally checkout a getting started guide that I had posted some time back.

If you liked this article, you can choose to follow this blog/subscribe to email alerts (top of sidebar or below comments in mobile) so that you know when any future posts come about.

Advertisements

8 thoughts on “Automation tool for AWS Lambda sizing

      • Cross platform or not, I’m not eager to install the .Net runtime. If the runtime can be packaged with the app, or even if it could be run as a Lambda itself, it would remove a barrier to entry.

        Probably a bias here on my part (I’m a Java guy myself), but not one that I think will be unusual.

        Like

      • Hmm.. Would you like to write a java version of the tool? The tool took me like two half days to write, you can send a PR in github.com by refactoring the project into .Net and java. I would have written it in something else if .Net wasn’t cross platform, but i can’t make myself rewrite it just to get adoption :), I don’t get paid for this stuff you know. I would love to get other people’s ideas in it though.. So mixed thoughts

        Like

  1. Understood – I’m not looking for a rewrite, but was curious if there was a way to package it more conveniently.

    Incidentally, have you experienced any possible optimization on Amazon’s part when running this? I’ve seen my cold starts get unusually faster when I’m actively working on a function, and have heard of others seeing this as well.

    Like

    • This tool does a three runs per memory size, ignores the first run and takes the faster one of the next two to get dependable and realistic numbers. I saw that the first run is always very slow which is expected since a new container is allocated and the code initialized

      Like

  2. Pingback: Calypsas AWS Week in Review – February 27, 2016

  3. Pingback: AWS Week in Review – February 27, 2016 - Browser Zone

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s