As you might already know, AWS Lambda is a popular and widely used serverless computing platform that allows developers to build and run their applications without having to manage the underlying infrastructure. But have you ever wondered how AWS Lambda Pricing works and how much it would cost to run your serverless application?
When it comes to cloud computing, cost is often a major concern. AWS Lambda, Amazon’s serverless computing platform, is no exception. Understanding AWS Lambda Pricing has become increasingly important as the demand for serverless computing continues to rise.
In this blog post, we’ll briefly compare AWS Lambda Pricing with other Cloud providers, discuss the key elements of the AWS Lambda pricing model, see the difference between costs for EC2 and Lambda, and provide tips on how to optimize Lambda Costs.
Table of contents
- Understanding AWS Lambda Pricing?
- Breaking Down the Numbers of AWS Lambda Pricing
- Real-World Examples of AWS Lambda Pricing in Serverless Apps
- AWS Lambda Pricing vs AWS EC2 Pricing
- Strategies for Optimizing AWS Lambda Costs
- Keeping a Close Eye on AWS Lambda Costs
- Conclusion
- FAQs
Understanding AWS Lambda Pricing with Apples and Pears
The difference between AWS Lambda pricing and serverless computing offered by other Cloud providers can be similar to comparing apples and pears. Despite the fact that both are fruits, their flavors, colors, and forms are distinct. Similarly, even though serverless computing is something that AWS Lambda and other cloud computing platforms both support, their pricing methods and structures vary.
The three main cloud providers, Amazon Web Services (AWS), Microsoft Azure(Azure), and Google Cloud Platform (GCP), respectively, offer serverless computing primarily through AWS Lambda, Azure Functions, and Google Cloud Functions. These services allow customers to run functions without managing any infrastructure, making serverless computing a popular choice for many organizations. When it comes to choosing a cloud provider, pricing is a critical factor to consider.
Regarding cloud services, AWS Lambda is in good company. Others, like Google Cloud Functions and Microsoft Azure Functions, offer similar serverless computing capabilities. But what sets AWS Lambda apart is its cost-effective pricing structure. Compared to other cloud services, AWS Lambda has a more straightforward pricing model that is based on the number of function invocations, the duration of each invocation, and the amount of memory allocated to each function. This model is flexible and enables users to optimize costs by reducing function duration and allocating the right amount of memory for each function.
It is difficult to compare the prices of AWS Lambda, Google Cloud Functions (GCP), and Azure Functions because prices might change based on the volume of data handled, the length of each request, the amount of memory you allocate, and the number of GB-seconds spent.
Having said that, below is a general breakdown of the three platforms’ pricing schemes as of February 2023.
Want to dive deeper into serverless? Check out the Serverless vs Containers debate.
Breaking Down the Numbers of AWS Lambda Pricing
Breaking down the numbers of AWS Lambda and other serverless pricings can seem complex, but understanding the various components can help you optimize your costs and get the most out of your serverless application. There are a number of factors that contribute to the cost of a Lambda function, including the amount of memory you allocate, the duration of function execution, and the number of requests made.
Free Tier
For their respective serverless computing platforms, AWS Lambda, Google Cloud Functions, and Azure Functions, the three major cloud providers, AWS, GCP, and Azure, all have free tiers. Users can test out the services on these free tiers with limited resources without having to pay anything.
Have a look at the following table to get an understanding of the free tier for each of the cloud platforms.
AWS | Azure | GCP | |
Invocations | 1 Million/Month | 1 Million/Month | 2 Million/Month |
Compute Time | 400,000 GB-s | 4,00,000 GB-s | 400,000 GB-s, 200,000 GHz-s |
Now, let’s talk about the pricing model of AWS Lambda in the following section.
Memory Allocation
First, let’s look at the cost of memory allocation.
This component of the Lambda AWS pricing model is based on the amount of memory you configure for your function, with the cost increasing as you allocate more memory. This cost is constant, regardless of how many requests are made to the function.
AWS
Memory (MB) | Price per 1ms |
128 | $0.0000000021 |
512 | $0.0000000083 |
Click here to learn about other memory options and their pricing.
Cost of Duration
Next, let’s consider the cost of duration.
This component of the pricing model is based on the total time your function spends executing, measured in increments of 100ms. The cost per 100ms of execution time is based on the amount of memory allocated to the function. The longer the function takes to run, the more it costs.
AWS
Architecture(x86) | Duration |
First 6 Billion GB-seconds / month | $0.0000166667 for every GB-second |
Next 9 Billion GB-seconds / month | $0.000015 for every GB-second |
Click here to learn about other Architecture and Duration options and their pricing.
Cost of Requests
Finally, there is the cost of requests.
This component of the pricing model is based on the number of times your function is invoked. Each request incurs a small fee, regardless of the duration of the function execution.
AWS
Architecture(x86) | Requests |
First 6 Billion GB-seconds / month | $0.20 per 1M requests |
Click here to learn about other Architecture and Request options and their pricing.
Other
In addition to these three components, there are a number of other factors that can impact the cost of a Lambda function, such as the use of additional AWS services, data transfer costs, and the cost of storing logs in AWS Lambda CloudWatch. Understanding the various components of AWS Lambda pricing can help you make informed decisions about optimizing your costs and getting the most out of your serverless applications.
Real-World Examples of AWS Lambda Pricing in Serverless Apps
In this section, we’ll examine some real-world instances of serverless applications using AWS Lambda pricing. We’ll explore four distinct use scenarios and evaluate their financial effects, considering a number of variables like memory usage, processing time, and request volume. By going over these examples, we intend to provide you with a better grasp of how AWS Lambda Pricing works in practice and assist you in deciding whether to use this serverless technology for your projects.
Example 1: Simple CronJob
Delete unused volumes on a regular basis
You may have a requirement to delete unused EBS volumes across your AWS Account/s regularly. You can achieve this by writing down a script and executing it manually. But, this would not be a feasible option. Rather, you can write a Lambda Function that can be triggered on the desired schedule and get the work done for you.
Cost Calculation (Without Free Tier)
Let’s take an example where you would want your script to be executed at 11:11 am daily. It means the script will be executed only once a day, and the script may take around 2 minutes on average. For that script on x86 Architecture, you will be charged 0.01 USD/month without including Free Tier.
Let’s see the following calculations to understand the breakup.
Unit conversions
- Amount of memory allocated: 128 MB x 0.0009765625 GB in an MB = 0.125 GB
- Amount of ephemeral storage allocated: 512 MB x 0.0009765625 GB in an MB = 0.5 GB
Pricing calculations
- 30 requests x 120,000 ms x 0.001 ms to sec conversion factor = 3,600.00 total compute (seconds)
- 0.125 GB x 3,600.00 seconds = 450.00 total compute (GB-s)
- Tiered price for: 450.00 GB-s
- 450 GB-s x 0.0000166667 USD = 0.01 USD
- Total tier cost = 0.0075 USD (monthly compute charges)
- 30 requests x 0.0000002 USD = 0.00 USD (monthly request charges)
- 0.50 GB – 0.5 GB (no additional charge) = 0.00 GB billable ephemeral storage per function
Lambda pricing – Without Free Tier (monthly): 0.01 USD
Example 2: A Lightweight Application
Image Processing – Resizing an image or converting its format
AWS Lambda may be used to create an image processing application that automatically resizes images, changes their format, adds watermarks, and does other image modification activities. Based on the number of photos processed and the length of the function execution, the compute time cost will be determined for such applications.
Cost Calculation (Without Free Tier)
Let’s take an example where the Image Processing application is triggered 1000 times a day and runs for 5 seconds at 128 MB of memory. For such an application on x86 Architecture, you will be charged 0.32 USD/month without including Free Tier.
Let’s see the following calculations to understand the breakup.
Unit conversions
- Amount of memory allocated for the Image Processing Application: 128 MB x 0.0009765625 GB in an MB = 0.125 GB
- Amount of ephemeral storage allocated for the Image Processing: 512 MB x 0.0009765625 GB in an MB = 0.5 GB
Pricing calculations
- 30,000 requests x 5,000 ms x 0.001 ms to sec conversion factor = 150,000.00 total compute (seconds)
- 0.125 GB x 150,000.00 seconds = 18,750.00 total compute (GB-s)
- Tiered price for: 18750.00 GB-s
- 18750 GB-s x 0.0000166667 USD = 0.31 USD
- Total tier cost = 0.3125 USD (monthly compute charges)
- 30,000 requests x 0.0000002 USD = 0.01 USD (monthly request charges)
- 0.50 GB – 0.5 GB (no additional charge) = 0.00 GB billable ephemeral storage per function
- 0.3125 USD + 0.01 USD = 0.32 USD
Lambda pricing – Without Free Tier (monthly): 0.32 USD
Example 3: A Batch Processing Application
Video Transcoding
The process of transcoding big video files into numerous formats for various devices, bitrates, and resolutions is computationally intensive and requires a sizable amount of computing power. Video transcoding processes can be carried out with Amazon Lambda without creating or managing servers because the platform manages the computational resources.
Cost Calculation (Without Free Tier)
Let’s take an example where the Video Transcoding Batch application is triggered every 5 minutes and processes 10 videos, each taking an average of 30 seconds to process at 512 MB of memory. For such application on x86 Architecture, you will be charged 21.60 USD without including Free Tier.
Let’s see the following calculations to understand the breakup.
Unit conversions
- Amount of memory allocated: 512 MB x 0.0009765625 GB in an MB = 0.5 GB
- Amount of ephemeral storage allocated: 512 MB x 0.0009765625 GB in an MB = 0.5 GB
Pricing calculations
- Total Requests = every 5 minutes( i.e. 12 times an hour) * every day * every month
Total Requests = 12 times an hour * 24(hours) * 30(days) = 8,640 Requests - Duration = Total Videos in a batch * Time for each Video in sec * ms
Duration = 10(videos) * 30(seconds) * 1000(ms) = 300,000 ms - 8,640 requests x 300,000 ms x 0.001 ms to sec conversion factor = 2,592,000.00 total compute (seconds)
- 0.50 GB x 2,592,000.00 seconds = 1,296,000.00 total compute (GB-s)
- Tiered price for: 1296000.00 GB-s
- 1296000 GB-s x 0.0000166667 USD = 21.60 USD
- Total tier cost = 21.6000 USD (monthly compute charges)
- 8,640 requests x 0.0000002 USD = 0.00 USD (monthly request charges)
- 0.50 GB – 0.5 GB (no additional charge) = 0.00 GB billable ephemeral storage per function
Lambda pricing – Without Free Tier (monthly): 21.60 USD
Example 4: A Complex, Heavy Application
Data Analysis and Processing
Large-scale data processing or analytics applications that demand a lot of computing power and storage could be considered complicated and heavy applications for AWS Lambda. Consider an application that gathers and processes data from numerous sources in real time, applies sophisticated algorithms and machine learning models, and produces insights that can be used in business decisions. Without managing and maintaining complicated infrastructure, such application may be built and scaled up quickly with Amazon Lambda.
Cost Calculation(Without Free Tier)
Let’s take an example of a Data Warehouse. It processes and analyses enormous amounts of data from various sources to produce insights and reports. We can assume a monthly workload of 1 million requests, a processing time of 30 seconds for each, and a memory usage of 4096 MB on average. For that application on x86 Architecture, you will be charged 2,000.20 USD without including Free Tier.
Let’s see the following calculations to understand the breakup.
Unit conversions
- Amount of memory allocated: 4096 MB x 0.0009765625 GB in an MB = 4 GB
- Amount of ephemeral storage allocated: 512 MB x 0.0009765625 GB in a MB = 0.5 GB
Pricing calculations
- 1,000,000 requests x 30,000 ms x 0.001 ms to sec conversion factor = 30,000,000.00 total compute (seconds)
- 4 GB x 30,000,000.00 seconds = 120,000,000.00 total compute (GB-s)
- Tiered price for: 120000000.00 GB-s
- 120000000 GB-s x 0.0000166667 USD = 2000.00 USD
- Total tier cost = 2000.0040 USD (monthly compute charges)
- 1,000,000 requests x 0.0000002 USD = 0.20 USD (monthly request charges)
- 0.50 GB – 0.5 GB (no additional charge) = 0.00 GB billable ephemeral storage per function
- 2,000.004 USD + 0.20 USD = 2,000.20 USD
Lambda pricing – Without Free Tier (monthly): 2,000.20 USD
AWS Lambda Pricing vs AWS EC2 Pricing
Both AWS Lambda and AWS EC2 are computing services offered by AWS. However, they vary in terms of usage, cost, and architectural design. AWS Lambda and EC2 have different billing structures and can be more expensive or less expensive, depending on the use case.
Talking about AWS Lambda Pricing vs EC2 pricing, with AWS Lambda, you pay for the computing time that your code actually uses. And in terms of EC2, you are charged for the lifetime of your instances, whether or not you are utilizing them. In general, AWS Lambda can be a more economical option if an application is event-driven or has a modest traffic flow. However, if your application needs a constant, high-performance computing environment or a lot of memory, AWS EC2 can be a more affordable choice.
In short, there are differences between EC2 and AWS Lambda in terms of cost, ie. there is a difference between AWS Lambda Pricing vs EC2 pricing. The ideal option for a given use case depends on the individual demands of the application. Making an educated decision requires knowledge of the distinctions between the two services and their pricing structures. And the same applies to other compute services on AWS.
Example 1
Scenario 1 with EC2
EC2: Instance Type = t2.nano, EBS = 20 GBs, Usage = 100%(24*7)
Costs: 5.83 USD/Month
Scenario 1 with Lambda
Lambda: Memory = 512 MB, Requests = 30000, Duration = 30000 ms
Costs: 7.51 USD/Month
Scenario 2
Lambda: Memory = 512 MB, Request = 3000, Duration = 30000 ms
Costs: 0.76 USD/Month
Scenario 3
Lambda: Memory = 512 MB, Request = 30000, Duration = 3000 ms
Costs: 0.76 USD/Month
Example 2
Scenario 1 with EC2
EC2: Instance Type = t2.medium, EBS = 20 GBs, Usage = 100%(24*7)
Costs: 35.47 USD/Month
Scenario 1 with Lambda
Lambda: Memory = 4096 MB, Requests = 30000, Duration = 30000 ms
Costs: 60.01 USD/Month
Scenario 2
Lambda: Memory = 4096 MB, Requests = 3000, Duration = 30000 ms
Costs: 6.00 USD/Month
Scenario 3
Lambda: Memory = 4096 MB, Requests = 30000, Duration = 3000 ms
Costs: 6.00 USD/Month
Looking at the above observations, you can come to the conclusion that:
- For small-scale operations with a low request volume and fast code execution, AWS Lambda may be a financially advantageous option. This is especially true if you can optimize your code to use less memory and run faster.
- When you need to run persistent, long-lasting apps with a large number of workloads, AWS EC2 is a superior option since it gives you more control over the underlying infrastructure.
Note that these examples only consider the cost of maintaining the application and leave out other costs, such as those associated with data transit, storage, and management. Furthermore, a number of additional variables, such as the region, network latency, and the type of instance or memory needed, will affect the real cost of operating an application on AWS. Determining which service is the best fit for your use case requires a careful analysis of your application’s unique requirements, considering not only cost but also performance, scalability, and other aspects.
Strategies for Optimizing AWS Lambda Costs
As seen in the above section, AWS Lambda can be a cost-effective way to run and manage your application, but as your usage grows, costs can quickly add up. To ensure that you are getting the best value for your money, it’s important to take advantage of cost optimization strategies.
Now, we will explore strategies for optimizing your AWS Lambda cost. These will help you minimize your monthly bill while still delivering the performance and scalability your applications need. From right-sizing to reducing logging output to using compute savings plans, there are many tactics you can use to optimize your AWS Lambda cost. By implementing them, you can minimize expenses and ensure that your serverless applications run effectively and efficiently.
Optimizing through Right-Sizing
When it comes to optimizing AWS Lambda cost, right-sizing is a great place to start. This exercise allows you to identify the most cost-effective solution for your applications without sacrificing performance or making any code changes.
With Lambda, you can adjust the memory configuration for a function ranging from 128 MB to 10,240 MB (10 GB). This also adjusts the amount of vCPU available to the function during invocation. By tuning these settings, memory- or CPU-bound applications can access additional resources during execution, potentially reducing the duration of invocation and ultimately lowering costs.
Optimizing Performance
One of the main factors affecting the cost of using AWS Lambda is the duration of function invocations. The longer a function takes to run, the higher the cost and latency of your application. To keep costs low and maintain efficient performance, it’s important to write efficient code and follow best practices for AWS Lambda.
Here are a few ways to optimize your code:
- Reduce the size of your deployment package to only what’s necessary for the runtime. This shortens the time it takes to download and unpack the package.
- Keep dependencies simple. Simpler frameworks tend to load faster.
- Reuse execution resources. Initialize SDK clients and database connections outside the function handler and cache static assets locally in the /tmp directory. This allows subsequent invocations to reuse open connections and resources stored in memory and in /tmp.
- Follow general coding performance best practices for your chosen language and runtime.
AWS Graviton2
AWS Lambda functions recently became available on Arm-based AWS Graviton2 processors. These processors are claimed to offer up to 19% improved performance compared to x86 processors and at a 20% lower cost.
Users have the option to run both new and existing functions on the Graviton2 processors with no changes to the way the functions are invoked. However, some functions may require updates to their configuration or to utilize Arm-specific dependencies in order to fully take advantage of the price and performance benefits.
Before making any changes, it is advised to thoroughly test the impact on your workload.
Provisioned concurrency
Provisioned concurrency is an option that can be considered to address issues with cold starts and burst to throttle in Lambda functions. It offers ready-to-go execution environments, which can also result in cost savings when there is a consistent level of traffic. The pricing for a provisioned concurrency includes costs for total requests, total duration, and memory configuration, as well as the cost of each provisioned environment based on its memory configuration. When the execution environment is fully utilized, the cost of the combined invocation and environment can potentially reduce duration costs by up to 16% compared to regular on-demand pricing.
AWS Savings Plans
AWS Savings Plans offer a cost-effective pricing model compared to the on-demand pricing model. You can avail of lower prices in exchange for a specific usage commitment (measured in $/hour) for either a one-year or three-year period.
This pricing model includes Amazon EC2, AWS Fargate, and Lambda. Using Lambda for the duration and provisioned concurrency can be charged at a discounted rate of up to 17% with a 1- or 3-year term Savings Plan.
Implementing Savings Plans is straightforward, as it does not require any changes to your function code or configuration. It can be an easy way to reduce expenses for Lambda-based workloads. However, it is advisable to analyze past usage patterns before opting for a savings plan to understand any fluctuations in your monthly usage.
Fargate vs Lambda: Read the full blog covering costs, performance, and more.
Minimizing Log Data
Lambda functions automatically record information generated by the code in Amazon CloudWatch Logs. These logs can be useful for the real-time monitoring of your application. However, they come with a monthly cost based on the total data ingested. By limiting the log data to only essential information, you can help reduce costs.
Keeping a Close Eye on AWS Lambda Costs: Monitoring and Control
Monitoring and controlling the costs associated with running applications on the cloud is an important task for organizations. AWS Lambda is a serverless computing platform that allows organizations to run their applications without having to worry about the underlying infrastructure. While this offers many benefits, it also introduces a new set of cost-related challenges. To ensure that the costs associated with AWS Lambda stay within budget, it is important to keep a close eye on them and take steps to control them.
One of the ways to monitor and control the costs associated with AWS Lambda is by using the AWS Cost Explorer. This tool provides a comprehensive view of AWS costs and usage, making it easy to identify areas where costs can be reduced. For example, it can help identify underutilized resources, unused storage, and other areas where expenses can be reduced. In addition, the tool provides detailed information about the different cost components, making it easier to understand where they are coming from.
Another important aspect of controlling AWS Lambda costs is being mindful of the resources being used. For example, using the right size of compute resources, being mindful of the amount of memory used, and optimizing the function code can all help reduce costs. In addition, using cost-saving options such as provisioned concurrency, savings plans, and reducing logging output can also help keep costs under control.
Overall, it is important to continuously monitor the costs associated with AWS Lambda and take steps to control them to ensure that the platform is being used in the most cost-effective manner possible.
Conclusion
You can run your apps on AWS Lambda’s serverless computing technology without worrying about the underlying infrastructure. While there are many advantages to this, there are also new cost-related concerns that you need to be aware of. One of the crucial elements in ensuring that platform costs remain within budget is understanding the AWS Lambda Pricing mechanism for serverless apps.
You can utilize techniques like right-sizing resources, writing performance-improving function code, and utilizing cost-saving options like provisioned concurrency and savings plans to optimize costs. It is also very important to understand how the pricing works in AWS Lambda, and to help you with that; we tried to break down the numbers by providing real-world examples.
Finally, to ensure that the platform is being used as cost-effectively as possible, it is crucial to carefully check costs using monitoring and control tools like AWS Cost Explorer.
This blog is also available on Medium
FAQs
AWS Lambda is a cloud-based serverless computing platform that enables you to run code without managing servers. It automatically scales your applications in response to incoming traffic, and you pay only for the computing time you consume. The costs associated with AWS Lambda include the total duration of function invocations, the number of requests, the memory configuration, and any additional charges for the services used by your functions.
There are several strategies you can use to optimize your AWS Lambda costs. You can reduce the total duration of function invocations by using efficient code, minimizing logging output, adjusting memory configurations to minimize costs, and using compute savings plans to reduce your overall expenses.
Yes, reducing the number of requests is one way to reduce the cost of your AWS Lambda functions. You can also reduce it by optimizing the code for performance efficiency, reducing logging output, and using cost-saving features such as provisioned concurrency and AWS Savings Plans.
When choosing between cloud providers, factors to consider include pricing, support for the languages and frameworks you use, performance and scalability, security, and global availability of the services offered.