Created
December 19, 2022 10:58
-
-
Save holly/dd3e61bb22354bb6a7e725884b49b7ac to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# vim:fileencoding=utf-8 | |
import os | |
import requests | |
import datetime | |
import boto3 | |
from dateutil.relativedelta import relativedelta | |
dt = datetime.datetime.now() | |
tomorrow = (dt + datetime.timedelta(days=1)).strftime("%Y-%m-%d") | |
next_month_first_date = (dt + relativedelta(months=+1, day=1)).strftime("%Y-%m-%d") | |
ce = boto3.client("ce", region_name="us-east-1") | |
res = ce.get_cost_forecast(TimePeriod={"Start": tomorrow, "End": next_month_first_date}, Granularity='MONTHLY', Metric="UNBLENDED_COST") | |
amount = float(res["Total"]["Amount"]) | |
print("forcast is USD{0:,.2f}".format(amount)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment