Top Aws Lambda Gotcha You Must Know Before Configuring Them

“Once you set it, you forget it.”

Often, we see several cloud practitioners quote this line about serverless technologies. While serverless services have brought so much convenience, they have brought few challenges as well along with them. Like no visibility into abstracted layers that the service provider takes care of! One such serverless service is AWS Lambda function, where AWS allocates CPU power to each function on your behalf depending on the memory allocation. “Some abstractions do not actually simplify our lives as much as they were meant to do, ” like Joel Spolsky says in his article, The Law of Leaky Abstractions.

“What’s with Lambda?

Misconfigured functions, most of the time??”

So, in this post, we walk you through how CPU allocation affects Lambda execution time.

AWS Lambda Function Memory & CPU Dynamics: Why You Should Know

When you’re running a piece of code on a traditional server, you can monitor CPU utilization and memory utilization continually.

In the AWS cloud world, if you happen to use EC2s, you have the visibility into CPU allocation time, memory, IOPS, and network, etc.

In case of serverless services, like Amazon Lambda function, you just run the code without provisioning or managing servers. So, with Lambda functions, we naturally tend to not worry about system level metrics, such as CPU allocation time as well as other metrics like disk utilization, I/O and the network. We tend to focus more on application metrics, right?

The Catch: CPU Allocation Per Memory Consumption

Recently, we ran a Lambda function code with 250 MB memory allocation, for experimentation purposes. This function after execution in actuality consumed just 170 MB.

This actual memory consumption often MISLEADS several AWS users. When their code execution time moves up north, they tend to focus entirely on their code optimization and ignore other dynamics, such as the underlying CPU allocation for each batch of memory allocation.

When we increased our Lambda function memory allocation to 512MB, the execution time of the code magically reduced to 52 mSec, which is ~50% increase in execution speed!

Memory Allocated Actual Memory Consumption Execution Time
250 MB 170 MB 100 mSec 512 MB 170 MB 52 mSec

The result:

REPORT Duration: 48.44 ms Billed Duration: 50 ms Memory Size: 170 MB
REPORT Duration: 52.91 ms Billed Duration: 50 ms Memory Size: 170 MB

Serverless-as-a-Success: Debunking the AWS Lambda Performance Challenge

Even though your Lambda function code consumes memory within limits, a higher allocation of memory improves the performance by 50%!

According to AWS, a user needs to choose the amount of memory required for a function and it will allocate proportional CPU power according to memory allocation and other resources. You can update the configuration and request additional memory in 64 MB increments from 128MB to 3008 MB. Amazon allocates CPU power proportional to the memory using the same ratio as a general purpose Amazon EC2 instance type.

As Jeremy Daly mentions in one of his blog posts, “ CPU resources, I/O, and memory are all affected by the memory allocation setting. If your function is allocated more than 1.8GB of memory, then it will utilize a multi core CPU. Thus, if you have CPU intensive workloads, increasing your memory to more than 1.8GBs should give you significant gains. The same is true for I/O bound workloads like parallel calculations.”

There have been several debates around CPU allocation in AWS Lambda since 2015. Mustafa Akin’s post throws enough light on how CPU allocation happens for Lambdas. He recommends profiling the application and recognizing the bottlenecks before adjusting the function configuration for ideal memory settings.

In conclusion, the “CPU” performance scales with provisioned memory. You will have access to more compute power when the next new larger settings is chosen. But, do try out with different memory options before configuring Lambda functions the next time.

If you want to know other AWS Lambda Gotchas, here’s a curated list of good reads:

5 Things you should know before using Lambda

My Accidental 3–5x Speed Increase of AWS Lambda Functions

AWS Lambda: Faster Is Cheaper

RELATED READING: If you are looking to monitor AWS Lambda function costs in seconds, watch this short TotalCloud Interactive Cost Analyzer video. Sign-up to try.

Top Aws Lambda Gotcha You Must Know Before Configuring Them

Smart Scheduling at your fingertips

Go from simple to smart, real-time AWS resource scheduling to save cost and increase team productivity.

Learn More
More Posts

You Might Also Like

Cloud Computing
How To Migrate To Azure Faster?
Migrating from on premise data centers to a cloud provider is always considered a difficult endeavor. From the cost, to the planning and resource allocation, plenty of preliminary work is gone to setting up a cloud infrastructure. Which is why, Microsoft Azure’s new program stands to benefit many organizations still on the fence about migrating to the cloud.
July 21, 2021
Cloud Computing
Everything You Need To Know About Kubernetes Scheduler
When creating a Kubernetes cluster, scheduling the pod to an available node is an important component of the process. This component works under specific rules and technicalities that I’d like to explore in this article...
September 23, 2020
Cloud Computing
20 Cloud Influencers You Should Be Following in 2020
It’s important to follow the right individuals so that you remain on the loop and always find yourself learning things that you were unaware of. These thought leaders and influencers can only be the avenues by which you meet other interesting technologists.
September 23, 2020
Cloud Automation
New In: No-code cloud management workflows for Azure, VMware & Private Cloud (in addition to AWS)
At TotalCloud, we’ve been enabling workflow-based cloud management for AWS to make it intuitive, accelerated, and no-code. Instead of programming cloud management use cases or depending on siloed solutions, we built out a platform that gives you building blocks to assemble any cloud management solution. 
September 4, 2020
Cloud Computing
List of Essential Kubernetes Tools
Kubernetes is a Container-as-a-Service with tons of unique tools to choose from. External tools play a role in integrating with different systems or maintaining control over the clusters you deploy. Manual health checks and troubleshooting is not ideal to keep a system in full health.This list of tools will provide ample support to your containers and have enough configuration to leave management flexible...
August 12, 2020
AWS Use Case Files
TotalCloud Inventory Actions: Giving a new meaning to Cloud Inventory
Learn how the TotalCloud Inventory Dashboard can become equivalent to your cloud provider’s SDK. Carry out any action on any discovered resource with Inventory Actions.
July 30, 2020