Calculate AWS Costs in Detail
Calculating AWS costs upfront is a challenge. To get accurate numbers, you have to understand the pricing model of the used AWS services. A pricing model consists of one or many pricing dimensions. E.g., GBs stored, number of requests, etc. Keep in mind that each service is different. EC2 instances are billed based on how long they run, how much storage you provision, and how much traffic they receive and send (some traffic is free). The pricing dimensions of an S3 bucket are stored data, number of requests, number of tags, and many more. After you understand the pricing model, you have to come up with the numbers. How much traffic does your application process? How many requests to S3 do you plan to make? The second step is usually the more challenging part. In this blog post, I share the tools and techniques I use to calculate AWS costs.
The ins and outs of the architecture
To calculate costs, you need a detailed understanding of the architecture. What AWS services are used? How are the services used? What communication paths exist? What data is processed and stored? What are data retention policies? And many more questions.
I usually start by looking at the architecture diagram. I recommend diving as deep as possible to understand what’s going on. VPC Flow Logs can be helpful to understand communication paths. IAM policies provide a hint of what APIs are called.
Once you know what AWS services are used, you can familiarize yourself with the pricing models of each service.
Understanding the pricing models
Each AWS service has a pricing page. I recommend you to read them from top to bottom. There are no shortcuts if you need an accurate cost calculation. Check out the following pricing pages to get a sense of the differences between services:
Keep in mind that prices are likely different in each AWS region!
Estimating price dimension usage
Once you understand the pricing dimensions, you have to estimate the usage for each of the dimensions. Some dimensions are straightforward to guess. Others are more tricky. Let me provide you two examples.
A CloudWath dashboard is priced at $3 / month. I know that I create one dashboard, so it is easy to estimate the costs.
CloudWatch Logs are priced based on the data volume you ingest and the data volume you store. The problem: How much log data does your application produce? The log volume likely correlates with the number of requests the application processes. I recommend running an experiment to get a better understanding of the usage pattern:
- Set up your application.
- Take a note of the
storedBytes
value of the log group. - Run
x
number of requests through the system. If you are lucky, you can reuse a load test that you already have. Make sure thatx
is large enough (e.g., 100,000 requests). - Take a note of the
storedBytes
value again. - Calculate the difference between the two
storedBytes
values and divide them byx
.
Tools
AWS provides tools to help us with cost calculations. the Pricing Calculator is the new kid on the block. The Simple Monthly Calculator is the older version you might need to fall back to. Both tools miss services and pricing dimensions! I highly recommend not skipping the Understanding the pricing models step to avoid surprises.
I use the AWS tools to come up with rough estimates only. If I need detailed calculations, I create a spreadsheet. I believe you need a spreadsheet anyway because you usually need to calculate the pricing dimension usage to enter into the tools.
I prefer to use a “business” metric as a starting point, such as daily active users or the number of files uploaded. Based on this number, I can calculate the pricing dimension usage. The screenshot shows a real-world calculation of mine:
Pitfall: Traffic
I see many calculations miss an important aspect: traffic. Traffic costs are very tricky:
- Traffic from the Internet to EC2 is free.
- Traffic from EC2 to the Internet is billed.
- Traffic between EC2 instances in the same AZ is free.
- Traffic between EC2 instances in different AZs/regions is billed.
- Traffic between EC2 and RDS is free.
- Traffic between EC2 and MSK (Kafka) is billed.
I usually think about traffic costs this way: I assume all traffic is billed. I check the pricing pages to find the traffic costs. In some cases, you will find that traffic is free.
In the following video, I share my workflow in more details based on a real-world example:
Summary
Calculating AWS costs is tricky. I recommend following these steps:
- Understand the architecture
- Research pricing models of used AWS services
- Estimate price dimension usage
Creating an accurate calculation for a medium complex architecture can take a working day.
Further reading
- Article AWS Cost Optimization 101
- Article Reduce your AWS bill with Savings Plans
- Article A Deep Dive into AWS CloudTrail
- Tag costs