Today’s entry into our exploration of public cloud prices focuses on AWS Lambda pricing.

Low costs are often cited as a benefit of using serverless. A recent survey showed that companies saved an average of 4 developer workdays per month by adopting serverless, and 21% of companies reported cost reduction as a main benefit. But why aren’t 100% of companies reporting cost savings?

In this article, we’ll take a look at the Lambda pricing model, and some things you need to keep in mind when estimating costs for serverless infrastructure.

How AWS Lambda Pricing Works

Core Pricing

AWS Lambda pricing is based on what you use. There are two major factors that contribute to the calculation of “what you use”:

  • Requests — Lambda counts a request each time it starts executing in response to an event notification or invoke call. Each request costs $0.0000002.
  • Duration — Duration is calculated from the time your code begins executing until it returns or otherwise terminates, rounded up to the nearest 100ms. But, the price is not charged per second. Rather, it is charged per GB-second, which is the duration in seconds multiplied by the maximum memory size in GB. Every GB-second costs $0.0000166667.

Free Tier

There is a free tier available to all Lambda users — and note that this is unrelated to your regular AWS free tier usage. Every user gets 1 million requests per month and 400,000 GB-Seconds per month, for free.

Additional Charges

In addition to requests and duration, you will also be charged for additional AWS services used or data transfers – regardless of whether you’re using Lambda’s free tier. For many applications, API requests and data transfers will cost significantly more than the AWS Lambda core pricing.

Why AWS Lambda Pricing is So Confusing

Ultimately, Lambda pricing is confusing and hard to predict. Here’s why:

  • Granularity — the fact that cost is per each function execution makes it difficult to estimate compared to server-based pricing models. Thinking in terms of iterations of a microservices script requires some mental gymnastics.
  • Multiplicative costs — the fact that the duration charges are based on a calculation makes it harder to conceptualize and more variable than other pricing models – and if both duration and memory change, the costs increase quickly.
  • Additional charges at a cost of $3.50 per million calls, AWS API Gateway charges often make up a significant portion of the cost to run serverless – plus data transfers and other “on top” costs.
  • Wait time — if a function makes an outgoing call and sits idle waiting for the result, you’ll be charged for the wait time. Be sure to set a maximum function execution time to prevent this from driving up costs (as well as a maximum memory size).
  • Code maintenance it’s a murkier area when it comes to costs, but with more functions come more lines of code to maintain.

Of course, there are several AWS Lambda pricing calculators out there to help estimate costs — ranging from the simpler that include only the number of executions, memory allocation, and average duration (examples from Dashbird and A Cloud Guru) to those incorporating language, activity patterns, and EC2 comparisons from the cheekily named

AWS Lambda Costs Are Just One Factor

There are plenty of benefits to serverless, from low latency to scalability to simple deployment. However, alongside vendor lock-in, applications with long or variable execution times, and control over application performance, cost is another reason why serverless may not replace traditional servers for all situations.