Skip to content

Latest commit

 

History

History
38 lines (26 loc) · 2.02 KB

README.md

File metadata and controls

38 lines (26 loc) · 2.02 KB

aws-forecast

Credits

Forked from its original repository, simplified and adapted to @Klaxit needs. Many thanks to @jimzucker for sharing this!

User Story

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).

Image of Cost Explorer

Solution

AWS Architecture

AWS Architecture

Setup

See these instructions: Click here

Environment Variables

See documentation at the top of get_forecast.py.

Sample Output

Sample Output of get_forecast

Command line (for development/testing)

python3 get_forecast.py

Technical Notes

AWS API Used

  1. get_cost_forecast - used to get current month forecast. (note we exclude credits)
  2. get_cost_and_usage - used to get prior & current month actuals (note we exclude credits)

Boundary conditions handled

In testing I found several situations where the calls to get_cost_forecast would fail that we address in function calc_forecast:

  1. Weekends - there is a sensitivity to the start date being on a weekend
  2. 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