DEV Community

Cover image for AWS Lambda Optimizations 👨‍💻
Kevin Lupera
Kevin Lupera

Posted on • Edited on • Originally published at dev.to

3 1 1 1 1

AWS Lambda Optimizations 👨‍💻

This post was written with the support of Alexis Polo @aledpolo

Spanish Version

Use packers such as esbuild or webpack, in several tests performed there was evidence of improvement using esbuild for compilation time and size here is a reference. Both have offline support.

Using Graviton2

Workloads
Multithreading or performing many I/O operations
Machine learning inference based on CPUs
Video encoding
Gaming
Processing
Cost
20% cheaper, including provisioned concurrency
Supported on Compute Savings Plans
Serverless Framework configuration
The following line architecture: 'arm64' must be added

serverless.yml provider: architecture: 'arm64'

Using AWS Lambda Power Tunning

Measuring cost efficient memory size is one of the easiest and most useful optimization practices.
By default using frameworks like serverless framework or SAM you can granularly define the amount of memory to each lambda but it is good how much memory and vCPU (Virtual CPUs) provide better response times and with it better.
We have a lambda that performs a read operation on a DB and brings 50 records for which we have a comparative table with the different memory configurations, response times and cost.

Table cost per memory

A very important fact is that the 128 MB configuration has a similar cost to the 1536 MB option but the time difference is significant 10 to 1.
More memory does not always mean higher costs

Sample cost vs execution time

Guide for use

Choose the option that involves the least effort option #1. Open the following link
Application Search - AWS Serverless Application Repository while logged into your AWS account.
In the following template you can configure the range of RAM allowed for the evaluation

Step 1

Step 2

Step 3

Once the creation process is finished, click on the link powerTuningStateMachine

Step 4

Step 5
Enter the json with the information of the lambda to be tested

{ "lambdaARN": "your-lambda-function-arn", "powerValues": [128, 256, 512, 1024, 2048, 3008], "num": 10, "payload": "{}", "parallelInvocation": true, "strategy": "cost" }
Enter fullscreen mode Exit fullscreen mode

Start of execution

Step 6

Step 7
We have the following result which gives us very useful information to make adjustments in our lambda

Result

Result Interpretation

Once finished, the stack must be deleted, for this we go to CloudFormation > Stacks, select the power Tunings stack and delete it, thus deleting all the resources created, to avoid incurring additional costs.

References:

ACI image

ACI.dev: The Only MCP Server Your AI Agents Need

ACI.dev’s open-source tool-use platform and Unified MCP Server turns 600+ functions into two simple MCP tools on one server—search and execute. Comes with multi-tenant auth and natural-language permission scopes. 100% open-source under Apache 2.0.

Star our GitHub!

Top comments (0)

ACI image

ACI.dev: Fully Open-source AI Agent Tool-Use Infra (Composio Alternative)

100% open-source tool-use platform (backend, dev portal, integration library, SDK/MCP) that connects your AI agents to 600+ tools with multi-tenant auth, granular permissions, and access through direct function calling or a unified MCP server.

Check out our GitHub!

Join the Runner H "AI Agent Prompting" Challenge: $10,000 in Prizes for 20 Winners!

Runner H is the AI agent you can delegate all your boring and repetitive tasks to - an autonomous agent that can use any tools you give it and complete full tasks from a single prompt.

Check out the challenge

DEV is bringing live events to the community. Dismiss if you're not interested. ❤️