Forked from its original repository, simplified and adapted to @Klaxit needs. Many thanks to @jimzucker for sharing this!
I found myself logging in daily check our AWS spend and change to prior month to keep an eye on our AWS bill and decided to create a script to slack it one time per day to save time.
So I set out to automate this as a slack post daily to save time. While doing this I found that Forecast with % change from prior month that we see at the top of Cost Explorer are not directly available from the Cost Explorer API. Also, Current month costs is not accurate if AWS Saving Plans are used (as it includes that total amount of the reserved capacity from day one).
See these instructions: Click here
See documentation at the top of get_forecast.py
.
python3 get_forecast.py
- get_cost_forecast - used to get current month forecast. (note we exclude credits)
- get_cost_and_usage - used to get prior & current month actuals (note we exclude credits)
In testing I found several situations where the calls to get_cost_forecast would fail that we address in function calc_forecast:
- Weekends - there is a sensitivity to the start date being on a weekend
- Failure on new accounts or start of the month - on some days the calc fails due to insufficient data and we have to fall back to actuals