Save money and improve performance with the new Lambda power tuner UI

Matthew Dorrian
6 min readSep 14, 2020

--

What is this story all about?

Through my serverless projects and AWS experience as a Solutions Engineer at Liberty IT, I have became an AWS CDK enthusiast and below is a story about how I open sourced an innovation aimed at helping developers and large organisations.

If you want to skip to the setup, follow the GitHub instructions here or read on to find out how this came about and the features of this CDK project.

Deployed website allowing power tuning with a few simple values

The foundation: alexcasalboni’s power tuner step function

Alex Casalboni is an extremely well known AWS developer advocate and developed the AWS Lambda Power Tuning project. This is a state machine powered by AWS Step Functions that helps you optimise your Lambda functions for cost and/or performance in a data-driven way.

There are many ways to deploy this functionality into your AWS environment from:

  • AWS Serverless Application Repository (SAR)
  • Fork the repo and deploy with AWS SAM
  • Deploy the SAR app with an AWS CDK wrapper (created by my colleague Matt Coulter)

Deploying and executing the power tuner within an organisation

The above options are great to deploy the base Step function infrastructure but how do you call/execute the state machine? CLI, Manually through the AWS Console, API Gateway?

Let’s look at two teams within an organisation and consider their setup and user experience:

  • Team X deploys the stack via SAR, create an IAM user and invoke via AWS CLI
  • Team Y deploys the stack via SAM, front it with an API Gateway and hit via postman.

This flexibility is great but this leads to differing user experience interacting with the power tuner, differing setup instructions in dreaded wikis and knowledge fragmenting depending on the path.

Now … the power tuner UI

I saw an opportunity within my organisation to centralise and improve the user experience for power tuning Lambda functions within AWS by creating an easy to use centralised UI. This solution abstracts away the implementation of the tuner through the simplicity of AWS CDK and lowers the barrier of entry to this essential activity.

The architecture is as follows:

  • Angular 9 website fronted via Amazon CloudFront & Amazon S3
  • Amazon API Gateway using direct integrations to AWS Step functions
  • Alex’s Power Tuning State Machine

The website allows any developer to run the power tuner in their AWS account through simple CDK commands without worrying about IAM users, CLI commands, infrastructure etc.

Once deployed into your AWS account, developers need to know only the ARN of the lambda and tweak the various settings to their own liking and simply click Start power tuner.

The tuner will generate a visualisation of average cost and speed for each power configuration using Matteo’s tool and shows the recommended memory based on the selected strategy including average cost & duration.

Developers can now tweak their lambda memory profiles not on a whim but using this data and knowledge to get the most out of their resources by improving performance or reducing cost of executions.

They can also bring back the results of a previous execution if the execution data is still available (based on AWS Step Function retention period) to prevent the need to run the tuner again (unnecessary cost) to show team members, demo to stakeholders and more:

Why power tune your Lambda functions in the first place?

Whenever you create a lambda within AWS, the memory is defaulted to 128mb (lowest). Whilst this is a great start for simple tasks and keeps your Total Cost of Ownership (TCO) down, sometimes developers need, want & should update this value based on the type of task it is performing. By simply tweaking this value, your performance of your lambda can be drastically improved with little to no effect to the cost (even cheaper at times).

And the best thing … developers are in control of the memory!

Below is a sample tuning result allowing 84% performance gain with little to no cost impact:

… and to achieve this massive improvement, all I had to do was to add/update one line of code:

Lambda definition defaults to 128mb memory size
Simply update the memory size to the recommended size: 1024mb

Explaining to developers, your business or stakeholders those sort of gains with such little development effort … ludicrous.

Why would I recommend using this project?

This project has one simple goal: lowering the barrier of entry to Lambda Power Tuning.

By deploying an easy to use website which is used to interact with the tuner, you can create a consistent user experience over tuning, promote usage as it requires less setup (once deployed in your account, any dev could use it), promote consistency across the org with less implementation paths and so on…

I hope you can see the benefits of having this activity made easier which is often seen as an “extra” activity and often hear in an organisation …

I am too busy to worry about tuning

I will get to that during innovation time

The default memory will be fine … AWS defaulted it for a reason

By lowering the barrier I hope every team using Lambda functions will utilise power tuning to help optimise their solutions using an easy to use and data driven consistent approach.

How do I deploy this in my organisation?

This solution can be deployed to your organistion in only a few commands with the main ones being:

  • npm run deploy-infra

This command will deploy a CDK infrastructure stack containing the resources needed to run the power tuner e.g. API Gateway, power tuner State machine & set up direct integrations via simply endpoints

  • npm run build

This command will build the angular website to allow the static files to be deployed to S3 for hosting pointing to the newly deployed API Gateway URL (needs updated in web prod environment props)

  • npm run deploy-website

This command will deploy a CDK infrastructure stack containing the resources to front a single page application using AWS CloudFront and S3 using anSPA Deploy package

More in-depth instructions can be found on my GitHub here.

Want to contribute?

If you would like to contribute to this project and have ideas how we can improve this experience for all developers, please get in contact via Twitter or submit a Pull Request.

--

--