Cost optimization is important when developing solutions involving AWS Lambda
Cost optimization is important when developing solutions, including serverless applications on AWS Lambda.
To achieve this, it is advised to write efficient code, consider downstream services when making architectural decisions, continuously improve optimization, and prioritize changes that have the greatest impact.
Lambda pricing is calculated as a combination of:
Starting with right-sizing is an effective way to optimize costs without compromising performance or changing the code of an application. In AWS Lambda, right-sizing involves adjusting the memory configuration of a function, which ranges from 128 MB to 10 GB. This adjustment also impacts the amount of vCPU available during execution, allowing for improved performance and a reduced invocation duration.
The duration of a Lambda invocation is an important factor in its pricing. If the function takes longer to run, it will cost more and result in higher latency in the application.
As of September 2021, Arm-based AWS Graviton2 processors can be used to power Lambda functions. Graviton2 functions offer improved performance and cost-efficiency compared to x86, with up to 19% better performance at 20% lower cost. Using Graviton2 processors can also lead to a reduction in function duration due to the improved CPU performance, resulting in even lower costs.
To reduce Lambda function cold starts or avoid burst throttling, provisioned concurrency provides pre-ready execution environments for invocation. It can also lower Lambda costs when there is a steady volume of traffic, as the pricing model for provisioned concurrency offers a lower total price when fully used.
AWS Savings Plans is a pricing model that offers lower prices than on-demand pricing for a one- or three-year period, in exchange for a specific usage commitment measured in $/hour. Compute Savings Plans provide a discounted rate of up to 17% for Lambda usage in duration and provisioned concurrency over a 1- or 3-year term.