Pay per use is the longtime calling card of cloud computing, but many cloud customers find that's not the same as paying for what they need. Serverless computing advocates trumpet that promise, but customers see parallel challenges with AWS Lambda cost management.
Serverless computing offers a framework for customers to run their code without worrying about the underlying infrastructure. Customers pay based on the time it takes the service to execute their code, plus a fee per request. One of the primary appeals is that, unlike a more traditional infrastructure-as-a-service cloud instance, customers don't have to pay for idle resources if the service isn't actively processing a request. Many cloud providers now offer serverless platforms, including Google Cloud Functions, IBM Cloud Functions and Microsoft Azure Functions. But AWS Lambda pioneered the service and is the most mature and popular today.
That ability to only pay for resources when they're needed attracted Dropsource, a low-code mobile app development startup, to use AWS Lambda. The company needed to quickly deploy new workloads to generate source code for clients, but sporadic demand made it difficult to justify expanding on-premises infrastructure.
"There are a lot of things that don't make sense for us to host internally," said Dropsource CTO Nate Frechette. "We're able to throw as much load at Lambda as we need, and we don't have to worry about scaling."
Beyond the freedom from managing infrastructure, infinite scale on demand and reduced idle waste, the hook that has snagged many customers is the service's free options. The AWS Lambda cost structure includes a free tier that offers 1 million requests and 400,000 gigabyte-seconds of compute time per month, which is roughly equivalent to 1 GB memory for 111 hours and does not expire. That free compute time entices cost-conscious shops and lean startups, but it can also be deceiving.
"You get a lot of free executions, but there are customers who have intensive use cases. Once you're in that territory, serverless is not cheap," said Ernesto Marquez, owner of Concurrency Labs, a cloud consulting service.
Find the right balance
After customers exceed AWS Lambda's free tier, they pay a flat fee per request, plus the time for the service to execute their function at a rate based on the allocated memory. This pricing structure is similar to paying more for a cloud instance with more memory, but many customers struggle to grasp the relationship between memory and code execution time, Marquez said.
"If you allocate more memory to a function, you're going to pay more. But that extra memory means it's going to execute faster, which reduces cost. So, there's this very fine balance," Marquez said. "You have to find the right memory allocation so that it completes in a reasonable time, but [without] overallocating memory."
Some customers, such as Dropsource, run all of their functions with the same amount of memory, which simplifies AWS Lambda cost management for predictable functions or lighter workloads.
"Maybe once we get a lot more traffic, we'll have to be a little more cost-conscious. But we're not spending enough on it right now where tweaking would be beneficial to us," Frechette said.
Customers who want to optimize this balance and trim AWS Lambda cost must walk a fine line, said Chris Moyer, CTO of CNB Media. If a function is not allocated sufficient memory, it will fail or timeout. Additionally, customers do not have visibility into other factors that might affect execution time, such as CPU. AWS Lambda assigns CPU proportionate to memory, but Amazon does not disclose the number of cores or clock speed of the CPUs, leaving customers unsure whether it's memory or CPU slowing execution, Moyer said.
"Even if you're using half of the amount of memory [you've allocated], but it seems like it's taking a long time, it might be beneficial to bump it up," he said. "Really, the only way I've discovered that threshold is trial and error."
AWS seems to allocate other resources, such as networking, proportional to memory as well, Moyer said. Other serverless services, such as Google Cloud Functions, charge separately for networking or allow customers to select CPU clock speed tiers.
Focus on the code
Developers know that optimizing code can help reduce the resources required to execute it -- a fact that is even more important when using serverless services.
Ernesto MarquezOwner, Concurrency Labs
"Sometimes, a few hundred milliseconds in execution time can impact your overall bill by hundreds or thousands of dollars," Marquez said.
AWS X-Ray is an application performance management tool that can help analyze and debug Lambda functions. Third-party debugging tools, such as IOpipe, can also help give teams visibility into their code and identify why it's running poorly.
As with any cloud service, customers must also evaluate whether their workload is a right fit for the service. Localytics, a mobile app marketing firm, uses AWS Lambda in a variety of ways, including as part of its Slack ops infrastructure. However, in some cases, Lambda didn't make sense, said Michal Klos, senior director of engineering at Localytics.
"There are many use cases with real-time data processing where Lambda would be a good solution if it wasn't so expensive in comparison to running more traditional applications on EC2 servers," Klos said.
Set some limits
Customers can also manage their AWS Lambda costs using what Amazon calls "concurrency" to limit the number of concurrent executions and prevent unlimited autoscaling. But customers using Lambda for important workloads must be careful about setting hard limits, Moyer said.
"You could eventually end up screwing your customers because you have a spike and it doesn't auto scale like you expect," he said.
At a minimum, serverless users should set up account alerts to notify them if, for example, they exceed the free tier to avoid getting stuck with an unexpectedly large bill, Moyer said.
Customers looking for the best deal or hoping to cut serverless costs should evaluate other provider pricing structures, experts said. While serverless services generally have similar pricing structures -- a fee per request and based on duration time -- other fees may apply. Prospective customers should also compare networking or data transfer fees, as well as API request fees.
One serverless provider startup promises to handle this cost comparison for you. Spotinst's Function service takes a unique approach to serving up serverless computing. Rather than manage vast data centers, the company's service doles out compute time on other providers' infrastructure via a serverless framework. So, while customers interact with Spotinst's serverless front end, the code actually runs on cloud instances Spotinst reserves from other cloud providers, such as AWS, Azure, Google or IBM.
"We go to the lowest cost provider we can get, pay the instance-hour price and offer the resource to our customer," said Spotinst CEO Amiram Shachar.
Spotinst cuts large-scale discounts with some cloud providers and also aims to reserve excess capacity sold at a market-rate discount by other providers, an instance type AWS calls Spot Instances.
"If you think about it, the paradigm that serverless brings is that compute becomes a commodity," Shachar said. "You don't care which server you're actually using; you only care about a fast response."
Don't shoehorn serverless
Despite the serverless moniker, there's nothing magical about AWS Lambda. The service just presents a new model to consume the same old compute resources. While a functional comparison between Lambda and EC2 is imperfect, it illustrates that not all workloads are suited to a serverless model. For this example, we'll compare prices for a t2.micro Linux instance (a VM with one virtual CPU and 1 GB RAM) with a Lambda function that executes in one second, using 1 GB RAM.
Cost per month
t2.micro on demand (U.S. West N. Calif.)
t2.micro Spot Instance (U.S. West N. Calif.)
AWS Lambda (1 second duration at 1 GB RAM)
*reflects cost after accounting for the per-month free tier, based on one new request every second
However, it's unlikely anyone would run consecutive Lambda functions for a month straight. The real value of serverless is to scale during unpredictable or inconsistent loads. If we instead adjust the formula to assume you'll only need those Lambda resources during peak demand -- say, 40 hours per week -- it starts to look more attractive, at $2.06 per month after exhausting the free tier. Or what if your peak demand actually required the equivalent of 10 t2.micro instances at the same time, but you only reached peak demand for a few hours per month? From that perspective, serverless seems downright cheap compared to keeping underused instances around.
Zentrick, a video advertising management service, uses Spotinst's Functions service as a form of cloud bursting to handle demand spikes.
"We push the problem of keeping spare capacity around to someone else," said Zentrick CTO Pieter Mees. "While I haven't done the analysis per function call, it saves us the cost of having to keep spare capacity around. ... [Spotinst has] been able to give us much better rates than other providers we looked at."
While the concept behind serverless might commoditize compute, some customers find price is not the deciding factor and instead look for convenience and integration. Zillow was an early AWS Lambda customer and now uses the service in conjunction with Amazon Kinesis, a real-time data processing service.
"This mainly evolved due to all the different integrations Amazon has with Lambda," said Brian Filppu, director of business intelligence at Zillow. "It seems like it integrates with just about every AWS service now. … It just so happens that it's fairly inexpensive."