AWS Monitoring helps you gain observability into your AWS environment
AWS Lambda is a classic example for serverless cloud technology, or function as a service (FaaS). This technology allows users to run their applications without any provision or management of servers.
In this article, we’ll walk through the pricing structure of AWS Lambda and discuss how we can efficiently manage and optimize its costs—without having to compromise on the performance and operational excellence of Lambda functions.
AWS Lambda is an Amazon service used for serverless computing. It has gained massive popularity due to its many benefits, such as low-cost hosting charges, better code maintenance, automatic scaling, and optimized performance. Owing to these features, more and more organizations are moving their production code to serverless architecture using AWS Lambda. However, if not handled and maintained properly, Lambda can become a very expensive choice for a project.
Lambda is one of the most popular options for serverless functions hosted and maintained on the cloud. These single-purpose, programmatic functions help achieve near-perfect runtime performance and optimal scaling to any number of requests.
Lambda can be adapted to various use cases across established enterprises and startups alike. It can be used to run any type of mobile or web-based application, build efficient machine learning models, process data while scaling, or build event-driven applications. It offers users all this without the need to worry about the provision and management of servers.
For each account, AWS also specifies the limits for compute and storage resources to run and store Lambda functions. These limits apply to various resources, including the storage for uploaded functions; the number of concurrent executions; quotas for function configuration and deployment; and execution parameters like timeout, Lambda layers, environment variables, and burst concurrency.
A Lambda function request begins when its code starts to execute in response to an event triggered from a source like AWS SNS, calls from AWS API Gateway, or AWS SDK.
The cost of each of these requests is calculated based on various configurations of your account and the Lambda function itself.
AWS offers its customers three main pricing options:
The Lambda on-demand pricing plan is the most popular option and the one that fits the needs of the majority of customers, therefore we’ll use it as the basis for this article.
Being a serverless function, Lambda runs only when triggered. The three core contributors to the cost of running a Lambda function are:
You can also set the maximum memory size and maximum execution time of function for each of your Lambda to have better control over costs. The more memory is provisioned, the more CPU the function gets.
Apart from the above three factors, another one that affects the cost of a Lambda function is a feature called Provisioned Concurrency, which AWS introduced to have greater control over start-up latency when Lambda functions are triggered. Provisioned Concurrency helps solve the problem of cold starts and works great for applications and workloads requiring low latency, such as games, mobile backends, and complex transactions.
Before we move on to discuss the price that each aspect of a Lambda adds toward the overall costs, we need to understand the GB-seconds unit, as this is the main unit AWS uses to compute Lambda costs. GB-seconds are defined by the following formula:
Fig. 1: Calculating Lambda GB-secondsArchitecture | Consumed GB-seconds | Duration cost | Cost of requests |
---|---|---|---|
x86 | First 6 billion GB-seconds/month | $0.0000166667 for every GB-second | $0.20/1M requests |
Next 9 billion GB-seconds/month | $0.000015 for every GB- second | $0.20/1M requests | |
Over 15 billion GB-seconds/month | $0.0000133334 for every GB-second | $0.20/1M requests | |
Arm | First 7.5 billion GB-seconds/month | $0.0000133334 for every GB-second | $0.20/1M requests |
Next 11.25 billion GB-seconds/month | $0.0000120001 for every GB-second | $0.20/1M requests | |
Over 18.75 billion GB-seconds/month | $0.0000106667 for every GB-second | $0.20/1M requests |
The amount of memory that is allocated to the Lambda function will be a deciding factor for the duration cost. For more detailed pricing according to the memory allocated, refer to this pricing guide.
Note that the free-tier pricing is not applicable to Lambdas with Provisioned Concurrency enabled. If you have Provisioned Concurrency enabled, then prices would change as follows:
Architecture | Consumed GB-seconds | Duration cost | Cost of requests |
---|---|---|---|
x86 | $0.0000041667 for every GB-second | $0.0000097222 for every GB-second | $0.20/1M requests |
Arm | $0.0000033334 for every GB-second | $0.0000077778 for every GB-second | $0.20/1M requests |
Apart from the above, you may incur data transfer fees for Lambda. The pricing for these will be charged according to AWS EC2 data transfer rates.
AWS provides an easy-to-use pricing calculator for estimating Lambda costs. It contains all configurations that contribute toward Lambda costs. To start calculating costs, it requires the following basic information:
The next section of the calculator covers basic service settings. Here you’ll need to enter the below information:
The example in Fig. 2 uses the following parameters to estimate Lambda costs:
In the above output, the calculator shows that the total cost of our Lambda is $12,410.01. Moreover, it also shows the exact steps taken to arrive at this calculation based on the given parameters.
The flexibility of Lambda applications over traditional ones provides multiple options for optimizing an application’s execution costs and resource expenditures. In this section, we’ll cover some common methods for optimizing AWS Lambda costs.
We can make sure not to use Lambda functions for basic transformations. For example, when building an application with API Gateway, we can simply leverage the Velocity Tempting Language (VTL) supported by API Gateway instead of unnecessarily exploiting the full power of Lambda. VTL isn’t straightforward and has limitations when compared to Lambda functions, but it doesn’t incur extra costs like Lambda does.
The time it takes to execute a Lambda function is directly proportional to the amount being charged for it. So the goal here is to make Lambda functions small and purpose-centric. A Lambda function that executes in half the time will cost you only half the money. For example, if a Lambda function is created to get some code from S3 when the application starts, Lambda will take much more time to download 1 GB of data than to download 1 MB of data. This waiting time will create unnecessary costs.
Lambda functions are charged as per use—the Lambda function should only be called when it’s needed. There are various caching methods for Lambda functions that can have a significant impact on AWS Lambda pricing. We can add caching on the server-side in Lambda functions or on the client-side in the front-end to reduce cost. There is one more benefit of caching in addition to cost-cutting: We’ll get faster responses, because now the request doesn’t have to travel through the Lambda function all over again.
It is important that the right amount of memory is allotted to Lambda functions. AWS doesn’t allow customizing the CPU for Lambda functions, but you can customize the computing power by setting the memory allocation. This means that with single-processing applications, we can cut the memory short for cost saving.
CloudSpend is a ManageEngine tool that helps organizations efficiently manage their cloud resources. Its IT Automation feature allows auto-stop idle or non-productive cloud resources, or some user-defined actions to be triggered for them.
CloudSpend also provides a feature called Forecasting for right-sizing resources and improving the performance of the cloud infrastructure based on historical usage trends. And with CloudSpend’s Spend Analysis tool, you can get the cost split up based on service, region, account, resource, or instance type, as well as gain insight into minimum and maximum spending amounts.
Write for Site24x7 is a special writing program that supports writers who create content for Site24x7 “Learn” portal. Get paid for your writing.
Apply Now