AWS Lambda Pricing Model

Dashbird continuously monitors and analyses your serverless applications to ensure reliability, cost and performance optimisation and alignment with the Well Architected Framework.

Product Features Start Free Trial

AWS Lambda Pricing Overview

AWS Lambda charges are based on two key metrics:

  • Function invocations
  • Execution duration time

Every time a function is invoked, AWS charges $0.0000002 per request. That translates to 1 Million requests for $0.20.

After it’s invoked, another charge starts counting based on how long it takes for the execution to finish. It charges a fraction of a cent per 100 milliseconds. How much depends on the amount of memory allocated to the function1.

A function with 1 GB allocated, for example, will cost $0.000001667 per 100 milliseconds. That translates to $16.67 for 1 Million requests lasting 1 second each.

For billing purposes, function execution time is rounded up to the next multiple of 100. When duration is 256 milliseconds, for example, Lambda rounds to 300 in order to determine the cost.

Dashbird offers a Lambda Cost Calculator, in case you would like to simulate your own use cases.

Free tier

AWS offers 1 Million invocations and 400,000 GB-seconds of execution time per month for free.

This free tier does not expire after 12 months of account creation, like other services. That means developers can continue enjoying the free tier for an unlimited period of time.

There is no official guarantee, though, that AWS will keep the free tier in place forever.

Additional costs

Event Sources

Lambda doesn’t work passively. It has to be invoked somehow in order to run. This is called an event source. Some sources are free, others will add up to the total execution cost.

By free event source we mean those that don’t add up to what normally costs for the Lambda invocation and execution time.

Examples of free event sources are:

  • Lambda API2: can be used to invoke a function directly
  • CloudWatch Rules3: invokes a function on a regular basis

Event sources that add up to Lambda costs are:

How much each of these will cost depend heavily on the service and usage patterns. It is necessary to study their pricing models and consider each particupar use case. Check our Knowledge Base table of contents, since we have pages covering many other AWS services.

CloudWatch

By default, Lambda will store all logs generated by applications running on the platform in CloudWatch Logs4. It is highly recommended to keep this logging practice. That is the only way to gain visibility over what happens inside Lambda functions runtime and whether anything went wrong.

CloudWatch Logs charges per amount of data ingested (generated by Lambda) and also for storage over time. It’s possible to set CloudWatch Logs to automatically delete logs onder than a certain lifetime threshold (e.g. one week, or a month).

Retries

When a function invocation results in an error, AWS Lambda may retry the request with the same parameters for a few times. This is called the Retry Behavior5. Each retry will be charged as a normal request. Depending on how many errors the application may experience during transient failures or during all the time, it may add up to the total Lambda execution costs.

AWS Lambda vs. EC2 Pricing

Consider an application running on the AWS US-East (Ohio) region. It serves 1 Million requests per month, each during on average 250 milliseconds. The workload requires 2 GB of RAM.

Now let’s compare this application running on Lambda vs. EC2:

Lambda

  • Invocations: 1,000,000 x $0.0000002 = $0.200
  • Execution time: 1,000,000 x roundup(250/100) x $0.000003334 = $10.002
  • Total cost: $0.200 + $10.002 = $10.202

EC2

Since Lambda runs on Amazon Linux6, let’s consider an EC2 instance also running on a similar type of OS.

To match the same Memory size (2 GB) and vCPU allocation7 (2 cores) of the Lambda function, we chose the t3a.small8 EC2 instance.

Also aiming at a fair comparison, we are using the EC2 on-demand pricing and assuming the application must be online 24×7, which better aligns with Lambda pricing model.

  • Cost per usage-hour: $0.0188
  • Number of hours: 30 days x 24 hours = 720
  • Total cost: $0.0188 x 720 hours = $13.536

Comparison

Even though Lambda offers a wide range of benefits over EC2 (fully-managed, highly available and scalable, etc), it can still be cheaper than provisioning and maintaining our own server instances.

A really fair comparison would consider a cluster of at least four EC2 servers: a couple servers in two different Availability Zones9. This would provide a level of availability similar with Lambda’s (although still not on par with it).

Only that would already quadruple EC2 costs and management work. On top of that, consider the need for a Load Balancer and an Auto-Scaling service, the total cost of the infrastructure would probably be 5 or 6 times higher than Lambda.

Advantages

The main benefit of Lambda pricing model is that it eliminates waste with idle resources. There’s no need to pay for servers allocated at waiting for requests in your application. Developers only pay when the function is invoked.

If 24 hours or even days, weeks pass without any invocation, it costs nothing. Nevertheless, the function remained highly available throughout all that time. Developers don’t have to worry about whether the application will be up when it’s needed.

Another major advantage that comes from this pricing structure is reduced financial risks. That is especially beneficial to SMEs and startups. To reach such level of availability and scalability, it’s usually necessary to allocate a large budget on a cluster of servers. That is without knowing how much of those resources will actually be needed.

Companies usually over-provision to avoid going out of compute or memory resources and failing during peak times, when auto-scaling systems cannot cope with the speed with which demand grows.

High availability comes totally free of charge in AWS Lambda.

Downsides

For workloads that have a difficult to predict duration, the Lambda model can actually increase financial risks.

With an EC2 server, for example, there is always some level of idle resources that can accommodate some compute time fluctuations without increasing costs. In AWS Lambda, on the other hand, if execution time increases, the total cost will increase proportionally.

Another downside is that, since pricing is fully variable to application demand, there are no economies of scale as the demand grows.

Lambda can be used to its full extent by implementing decoupled micro-services. Since a single-purpose user request is likely to invoke multiple functions. Costs and latency may add up in such architectures.

Footnotes


  1. AWS Lambda Pricing – cost per execution millisecond ↩︎
  2. Lambda API Reference ↩︎
  3. Tutorial: Schedule AWS Lambda Functions Using CloudWatch Events ↩︎
  4. Accessing Amazon CloudWatch Logs for AWS Lambda ↩︎
  5. Understand the Lambda Retry Behavior ↩︎
  6. Learn more about the Amazon Linux and other details about the Lambda execution environment. ↩︎
  7. Understand how AWS Lambda allocates vCPUs to the function execution environment. ↩︎
  8. AWS EC2 T3: low-cost, general purpose instance types ↩︎
  9. What is an AWS Availability Zone ↩︎

No results found