This post was written with the support of Alexis Polo @aledpolo
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.
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
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
Once the creation process is finished, click on the link powerTuningStateMachine
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" }
Start of execution
We have the following result which gives us very useful information to make adjustments in our lambda
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:
Lambda execution environments β AWS Lambda
Profiling functions with AWS Lambda Power Tuning β AWS Lambda
Top comments (0)