June 5th 2020
CEO of Dashbird. 13y experience as a software developer & 5y of building Serverless applications.
Nevertheless, there are still more cost-saving opportunities that many development teams miss on AWS Lambda.
Prioritizing Lambda optimizations
Optimizing Lambda functions can be time-consuming, though. One essential practice is prioritizing the ones that are contributing the most to the overall AWS bill.
Benchmark optimal Lambda memory settings
AWS doesn’t allow us to customize CPU for Lambda functions, but the more memory we allocate, the more computing power we get… and the faster our functions will execute our code! This can actually reduce the total execution cost.
Below is an illustration of the strategy: when we increased memory from about 1.8 GB to 2 GB, it decreased the total billed duration from 600 to 500 milliseconds. Although the memory cost is higher, the lower duration more than offsets the additional memory cost, rendering an effective 5% cost reduction. And we even have the extra benefit of lower latency.
Using Lambda internal memory as a local cache
The Lambda internal memory can be used as a cheap and fast caching mechanism. As it’s widely known, anything loaded outside the handler function remains in memory for the next invocations.
Constant monitoring is essential
Software projects are changing constantly, which makes cost optimization a moving target. For that reason, it’s important to have proper monitoring and alerting when our financial policies are not met so that we can act upon these incidents and fix them before they become a financial nightmare.
AWS offers spending alerts and expenditure information, but not on the granular level of a Lambda function, for example.
As we can see, there are many areas that may offer you cost savings opportunities on AWS Lambda functions. For very low-cost systems, averaging around dozens or even hundreds of dollars per month, it might not be worth the time spent in optimizing them. But once the application traffic increases, the opportunities can really stand out.