Getting a Handle on Spiralling AWS Lambda Cost in ~15 sec
Cloud Computing, Product

AWS Lambda function might look low-priced while getting started. Even though developers can limit its max memory size and max function execution time, there are chances of costs spiraling out of control due to several reasons. It could be because of a DDoS attack, excess memory allocation to each function, or a bug in the code that accidentally invokes a function innumerable times!

In this post, we walk you through ways to get a handle on the cost of Lambda functions, and how a visual console can help you get clarity in ~15 seconds.

Factors that Affect AWS Lambda Cost:

At the top level, it looks like AWS bills you only for the time your Lambda functions are running. In actuality, it depends on:

– The number of executions/requests

– The time range for which a function is running (rounded up to the nearest 100 ms)

– The memory size of the function

Example: if a function uses 512 MB and is called 5 million times in a month (lasting one second for each invocation), the monthly cost for this Lambda alone would be  $36.8072.  Consider the number of dollars you would spend on all the functions put together!

Ideally, you have to keep a healthy balance between memory allocation, number of invocations and run time of the function to avoid the risk of overpaying. Monitoring lambda functions for optimality must be a part of your regular audits. Otherwise, the spend might reach up to hundreds of dollars.

Here are a few ways to monitor these functions for cost optimization:

# The Good Old Manual Approach:

(Takes minutes to hours depending on the number of functions.)

Every time a Lambda executes, a record prints:

Duration: 1000 ms Billed Duration: 500 ms Memory Size: 512 MB Max Memory Used: 25 MB

The above record clearly shows that the function is using just 25 MB out of 512 MB. In this scenario, a function with 128 MB of memory works fine too as well as save hundreds of dollars per month. However, if you allocate much lesser, the function might drop before execution.

On that account, monitor Lambda records regularly. The challenge, however, with this approach is you have to spend a lot of time and effort in monitoring each function. More the functions, more amount of time and effort you have to invest in knowing their performance.

That’s why several cloud engineers across the globe use AWS calculator or test the function before launching, with different memory allocations, execution time and run time and then calculate the cost.

# The Cost Explorer Approach:

(Takes few minutes, if all the Lambda functions are appropriately tagged.)

Using AWS Cost Explorer, you can closely monitor the pricing for the week, month, or quarter, slicing and dicing it further by Service, Region, AZ, Usage Type, Tag name, etc.

AWS Lambda functions Cost for RabbitMQ

Cost of Lambda function that triggers RabbitMQ

Despite the cost details, the AWS console does not provide the visibility into actual problem area. You can just figure out whether the Lambda function costs have spiralled out of control, when an issue occurs.

If you have tagged your Lambdas properly, you can check out each of these tagged function’s pricing for the week in the console and discover the culprit function to take further action. If you have not, it’s next to impossible to find that culprit function. So several developers use CloudWatch Alarms to get a notification when a function exceeds the set limits. 

# The Third-Party Tools Approach:

(Takes minutes to hours depending on the number of functions)

There are several third party tools available in the market, like this cool tool on GitHub that calculates AWS Lambda costs in near real-time. Even with such tools, you have to key in all the details to get cost details manually. You have to sieve through data to make sense of the entire picture.  

# Using a Visual Console:

(Takes ~ 15 seconds, irrespective of whether the functions are tagged or not!)

One of the novel ways to monitor Lambda cost by memory, runtime , execution time, code size, subnet, and more is to use a visual console.  

Like TotalCloud’s state-of-the-art interface featuring built-in filters. These filters help group resources by several parameters like memory utilization, runtime, execution, etc. at multiple levels. The console’s Cost Analyzer analyzes spend on top of these grouped resources, in 3D space. Above all, the interface helps you get a viewable context of Lambda usage and get a handle on spending, in real-time, in just a few seconds. Watch the video below to know more.


The Wrap up:

If you observe the table below, the time and effort it takes to monitor the performance and cost of Lambda:

– The Manual Way: minutes to hours depending on the number of functions

– The Cost Explorer Way: few minutes, if and only if you tag all the Lambda functions properly

– The TotalCloud Way: ~ 15 seconds, irrespective of whether you tag the functions or not! Plus, you get the cost and performance perspective at a glance, on a single pane of glass.

AWS Lambda function’s pay-per-use billing model, turning on only during execution definitely saves on computing resources and costs. That said, it is equally important to keep a close watch on sub-optimal functions, while also track its cost, in real-time.

Top Categories
Stay up to date on the latest stories case studies and videos
You might also like
Cloud Comics
The FIFA Fever and the AWS Bill Nightmare
The entire world is raving about FIFA world cup, and Mr. Dev is caught up in a nail-biting football match trying to keep up...
Read More
Cloud Comics, Cloud Computing
Despicable You and the AWS Cloud Bill Shock
To err is human… to avoid a massive bill is divine. Keep a check on those logs getting piled up in S3. Set a cost ceilin...
Read More
Cloud Comics
In Your Cloud: Expectations Vs. Reality
Few reflections from a Cloud user: Is the reality ever actually as good as expectations…time for a reality check! Tweet y...
Read More
AWS Tips & Tricks, Cloud Computing
5 Salient Benefits of S3 Select & How it can Help Protect Data under GDPR Compliance
Before the release of S3 Select, if you had to pull only a specific set of raw data from the S3 Bucket, you had to download...
Read More
AWS Tips & Tricks, Cloud Computing
Finding the Costliest AWS EBS Volume, in ~10 Seconds
Many AWS users, both novice and experts, often encounter high Amazon EBS, or elastic block storage, bills. The primary reas...
Read More