When estimating the cost of AWS services, I like to think in microbucks.
What is a microbuck? It is one millionth of a dollar, or one ten-thousandth of a cent.
AWS pricing can be complicated. But when you work it out, it turns out that the cost of a lot of commonly-used, pay-per-use services can be easily estimated in microbucks (µ$)
Per-Service Costs
Note: all of these estimates ignore the free tier.
Lambda
Lambdas cost about 1 µ$ per invocation. How so?
Making two assumptions:
- We use 512 MB of memory, which is pretty reasonable for many lambdas, and
- We finish in under 100 ms, and so get billed for 100 ms of time.
Then the cost comes out to about 0.8 µ$. Added to the per-request price of 0.2 µ$ per invocation, we get the handy rule of thumb:
1 microbuck per lambda invocation.
API Gateway
Calls to an HTTP API cost 1 µ$. Simple.
Calls to a REST API cost 3.5 µ$.
DynamoDB
With on-demand capacity, writes cost 1.25 µ$ for items under 1 kb. Reads up 4 kb are one tenth of that, so almost free.
Storage is 0.25 µ$ per item per month, assuming 1 kb items. So 3 µ$ per year.
Events
Publishing to EventBridge costs 1 µ$ per event.
SQS cost 0.4 µ$, but that's per-call. You'll need 3 calls - publish, then read, then ack. So it also ends up being about a microbuck per message.
S3
Write requests cost 5 µ$ each. Read requests are 0.4 µ$.
Storage: for 1 µ$, you can store 40 kb of data for a month.
CloudWatch Logs
Half a µ$ per kb logged.
Step functions
These are an outlier - they cost 25 µ$ per state transition. That can easily dominate your costs.
Express workflows are priced in a completely different way - you pay 1 µ$ per invocation, plus lambda pricing for the whole duration of the function, start to finish. It's not yet clear to me what you would use express workflows for, so I'll say no more.
SES
100 µ$ per email sent. Ouch.
Examples
Let's say you have a pretty standard serverless app. You can back-of-the-envelope the costs like this:
- Request comes in to API Gateway: 1 µ$
- API Gateway invokes a lambda: 1 µ$
- Lambda writes an item to DynamoDB: 1 µ$
- Lambda does some logging to CloudWatch: 1 µ$
- Total: 4 µ$
So if your app handles a million requests, it will cost you four bucks.
Another example:
- Request comes in to API Gateway: 1 µ$
- API Gateway invokes a lambda: 1 µ$
- Lambda writes an item to DynamoDB: 1 µ$
- Lambda does some logging to CloudWatch: 1 µ$
- Lambda publishes an event to EventBridge 1 µ$
- Another lambda consumes the event: 1 µ$
- Lambda 2 writes some data to S3: 5 µ$
- Lambda 2 also does some logging: 1 µ$
- Total: 12 µ$
So, 12 bucks per million requests.
And one more example:
- Request comes in to API Gateway: 1 µ$
- API Gateway invokes a lambda: 1 µ$
- Lambda starts a step function with 5 states / 4 transitions: 100 µ$
- One of the steps sends an email: 100 µ$
- The other steps do some stuff, whatever, let's call it another 5 µ$
- Total: 207 µ$
The step function and the email really killed us.
It's interesting to note that:
- Sending a single email can cost much more than all the other things you do in handling a request.
- Step Functions can really add up, especially if you have a retry-loop in your state machine. Even in the happy-path, a state machine with just 5 states will cost 100 µ$ per invocation (4 state-transitions), which is huge compared to the simple API example above at 4 µ$. Add in a retry-loop and it can be a whole lot more.