Optimize code
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.
Use of Graviton2
Workloads
Multithreading or performing many I/O operations
Machine learning inference based on the CPUs
Video encoding
Gaming
Cost
20% cheaper, including provisioned concurrency
Supported on Compute Savings Plans
Configuration in Serverless Framework
You must add the following line architecture: 'arm64'
.
Using AWS Lambda Power Tunning
Measuring cost efficient memory size is one of the very easy and 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
Usage guide
Choose the option that involves the least effort option #1. Open the following link while logged into the AWS account.
In the following template you can configure the range of RAM memory allowed for the evaluation Una vez termine el proceso de creación se debe dar clic en el link powerTuningStateMachine
Enter the json with the information of the lambda to be tested
Execution begins:
We have the following result which gives us very useful information to make adjustments in our lambda link
Serverless optimizations
Once finished, the stack must be deleted. To do so, go to CloudFormation > Stacks, select the power Tunings stack and delete it, thus deleting all the resources created, to avoid incurring additional costs.
References:
https://docs.aws.amazon.com/lambda/latest/operatorguide/perf-optimize.html
https://docs.aws.amazon.com/lambda/latest/operatorguide/execution-environments.html
https://docs.aws.amazon.com/lambda/latest/operatorguide/computing-power.html
https://docs.aws.amazon.com/lambda/latest/operatorguide/static-initialization.html
https://docs.aws.amazon.com/lambda/latest/operatorguide/architecture-best-practice.html
https://docs.aws.amazon.com/lambda/latest/operatorguide/profile-functions.html