Getting a Handle on Spiralling AWS Lambda Cost in ~15 sec

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 (Jump to Point#4 to watch it in action now!).

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:

#1 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.

#2  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.

#3  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.  

#4  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.

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

Product
Introducing the TotalCloud Smart Scheduler
Announcing the launch of the TotalCloud Resource Scheduler! Take complete advantage of AWS's 'pay for what you consume' model by putting a power control for every AWS resource that you use.
January 14, 2020
Sayonee
AWS Use Case Files
Increase AWS EBS Volume size (Auto-remediation)
Learn how a simple workflow can auto-remediate and increase the EBS volume size when disk utilization goes beyond 90%
December 2, 2019
Sayonee
AWS Use Case Files
Instance CPU Utilization Report
Learn how a single workflow can be used to generate a CPU Utilization Report for EC2 Instances. This enables you to stay on top of EC2 utilization efficiency, and ensure you aren't over or underutilizing them.
October 24, 2019
Sayonee
AWS Use Case Files
Lambda Daily Cost Predictor
Learn how a simple workflow can be used to predict daily lambda costs, that can help prevent 'bill-shocks' and optimize your costs better.
October 24, 2019
Sayonee
Cloud Automation
Putting DevOps on autopilot with LEGO-like automation
The post explains our flagship product, the TotalCloud Workflow Editor. The Editor assists you to do practically anything you want on your AWS infrastructure. It primarily enables you to create completely customized workflows from scratch to automate all cloud actions. Learn how to leverage the easy-to-use editor and save loads of time and costs.
October 24, 2019
Sayonee
AWS Use Case Files
Reporting Security Groups with TCP Port 22 (SSH) access from public IP
Learn how to use a simple workflow to generate a report of Security Groups with unrestricted Port 22 access from Public IP. Similarly, workflows can be generated to identify SGs with any open ports.
October 24, 2019
Sayonee