AWS Bites Podcast

Search...

6. Is AWS Lambda cheap or expensive?

Published 2021-10-14 - Listen on your favourite podcast player

In this episode Eoin and Luciano talk about the pricing model for AWS Lambda and describe some cases where it could be a very convenient solution but also cases where it might end up being very expensive (compared to EC2 spot instances).

In this episode we mentioned the following resources:

Let's talk!

Do you agree with our opinions? Do you have interesting AWS questions you'd like us to chat about? Leave a comment on YouTube or connect with us on Twitter: @eoins, @loige.

Help us to make this transcription better! If you find an error, please submit a PR with your corrections.

Eoin: Hello and welcome to another episode of AWS Bites, the weekly show where we answer questions about AWS in about five minutes. My name is Eoin and I'm joined again by Luciano. And today's question is, is AWS Lambda cheap or expensive? So I suppose the great thing about AWS Lambda is you pay for it only when it runs. That's the whole business model behind Lambda. And if you imagine Lambda when it runs, it's like this ephemeral resource. It starts when a given event occurs, it processes that event, and then it shuts down and you're not paying for it after that point. So how does that fit into the pricing model, Luciano? Can you take us through that? Yeah, so in short, there are like two parts to the pricing of Lambda.

Luciano: One is called like the fixed cost of Lambda and it's basically you pay per number of invocations. It's like, I think, 20 cents of dollar per one million invocation, which in my experience is quite negligible because in reality, the bulk of the cost is going to be the variable part. And the variable part is basically based on the actual execution, as you said. And it's a function of the time that you are actually running a given Lambda, but also the amount of memory that you are allocating for that Lambda.

So you can imagine that these two dimensions, you multiply them together and you get the actual price for a Lambda execution. The interesting bit, there is a caveat there that you might think, okay, then I'm going to be very cheap and not allocate a lot of memory. So I kind of save money that way. In reality, memory and CPU are very closely related, which basically means that if you allocate more memory to your Lambda, you will also get proportionally more CPU allocated for that Lambda, which sometimes it means non-obvious things like depending on your workload, if you're using a lot of CPU, you might be better off allocating more memory, even though you don't really need that memory because you get more powerful CPU, then you are probably going to complete the execution faster. So at the end of the day, it's going to be cheaper for you. And of course, all these mechanisms are not very easy to predict in all sorts of different use cases. So there is an interesting tool that I want to mention by Alex Casalboni called AWS Lambda Power Tuning that allows you to actually run a simulation of a given Lambda with all the different dimensions and see what is the configuration that is probably going to be cheaper for you long term. So definitely have a look at that in the cases where you are not 100% sure what's going to be the best configuration for your Lambdas. But yeah, I have to say that it's hard to estimate that. So I don't know, Eoin, if you want to add anything to this observation. Yeah, it is.

Eoin: I mean, if you compare it to EC2, it's easier to understand when you're billed by the hour based on the machine size and the configuration. The cost is just based on how long that machine is active, whether you're doing anything with it or not. But if you're going to say, OK, well, how does Lambda pricing compare to EC2, then it depends on how much traffic you have at any given moment. If you've got stable, consistent workloads running all the time and you're optimizing your EC2 instance to those workloads, it actually might be cheaper over time. But that's just one of the factors, right? So there's other cost factors you need to consider, like the time it takes to maintain provision, run these EC2 instances, patch them. There's a lot of factors involved. So it's not exactly a simple use case, a simple calculation, is it?

Luciano: Yeah, I remember there is a very good article by Yan Cui, I believe, that is like the total cost of ownership of serverless. And I think it was the first time where I got this idea that, yeah, you shouldn't look only at the bill that you get from AWS when you think about the cost, but you should think more about your entire operation, how much is it costing you to operate on Lambda compared to operate on EC2?

Like how many people do you need to hire and responsibilities? How do they spend their time compared also to the features that will make you money? Is it just patching instances, something that will make your business more successful or you can just avoid to do that because with Lambda you can focus more on features and be more productive? So that's definitely another read that I recommend people to have a look at. Okay, so yeah, it's interesting that you say that pretty much depends on the use case, but do you have an expectation that maybe, because Lambda is so convenient, right? And we are seeing more and more adoption. So is there maybe any hope or a chance that AWS will revisit the price structure to make it more, I guess, palatable, even if you are doing long running jobs?

Eoin: If I was to place a bet, I would expect that the need for wider Lambda adoption will result in some price changes at some point. If we look at, there was an article I wrote last week, last actually this year, I think, in response to this, having had experience running Lambda in various different workloads, when we see where you've got constantly running functions doing machine learning or business rule execution for hours at a time with thousands of containers, it really starts to look expensive.

And sometimes it's just optics and perception when people look at this price and compare it to EC2. I covered all of those calculations in the article, but sometimes it's a massive factor of difference, like 10 to 20 times difference if you compare it to EC2 spot. But people don't generally consider the total cost of ownership, and that's the unfortunate reality of it. They look at the ticket price.

So I think in order to just meet people where their thought process is, it will require some more adaptive pricing in the future. But look, I wouldn't say people should fear Lambda pricing. Lambda is still the best service to adopt for compute just because it allows you to get things done so quickly. So I would say, be aware of your cost, but don't fear your cost. Just understand how the model works. Go with it and try and optimize when you need to. So we will have all the links. I'll link into that article in the show notes. But otherwise, let's wrap it up for today. Thanks again for listening and let us know what you think in the comments. Send us your own questions for future episodes. Follow us and subscribe us and we'll see you next time.