This is a monthly report of our cloud costs, to give us more visibility over how much we're spending:
For example, this report tells us that in June/July/August we spent an average of $4900 per month, then we spent $5255 in September – a 7% increase.
These reports run once a month and post into a Slack channel, so everyone in the platform team can see what we're spending.
We want to spend money responsibly. Our budget isn't unlimited, but nor is it tight.
Right now, we want to understand why we're spending money, rather than get the absolute smallest bill. We want to avoid our bill growing in an unbounded way, or for an unexplained reason.
It's good for developers to have a general awareness of our cloud bill. Every developer can look at the bill in the AWS console, and this report is posted into a shared channel.
The report is designed to:
- Give us a regular reminder of the general direction of the bill. Is the bill going up, down, or constant?
- Highlight significant changes as compared to the average of the previous three months (±5% or more). Small month-to-month variations are fine.
- Combine costs information across all our AWS accounts and other major cloud providers, e.g. Elastic Cloud. The report has both an itemised list of per-account/provider costs, and the total figure.
The report is working if it starts conversations about significant changes in the bill. It might be fine if an account's bill doubles in a single month, as long as we understand why. For example, if we ingest a lot of new content in the storage service, we'd expect to see a big bill in the storage account. But if the bill doubles and nobody knows why, that needs further investigation.
This report runs as a Lambda function, triggered by a CloudWatch Event Rule that fires once a month.
The Lambda is deployed when you run terraform apply
.
If you want to test the Lambda, you can run the report locally:
$ python3 costs_report/costs_report.py
This just prints the ASCII table, and doesn't post a message to Slack.
The Terraform creates a new role in each account, which just allows permission to read the billing data. You need to:
- Create that role in Terraform, using the
roleset
module - Give the Lambda permission to assume the role
See commit 2af1f1b and cb2a39f as an example of adding a new account.