Guest User

Untitled

a guest
Nov 22nd, 2017
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.48 KB | None | 0 0
  1. #!/usr/bin/env python
  2. import datetime
  3. import boto3
  4.  
  5. now = datetime.datetime.now()
  6.  
  7. START = "{}-{}-01".format(now.year, now.month)
  8. END = "{}-{}-{}".format(now.year, now.month, now.day)
  9.  
  10. client = boto3.client('ce', 'us-east-1')
  11. a = client.get_cost_and_usage(
  12. TimePeriod={"Start": START, "End": END},
  13. Granularity="MONTHLY",
  14. Metrics=["UnblendedCost"],
  15. )
  16.  
  17. print("Total spend from {} to {} is {} USD".format(
  18. START, END, a['ResultsByTime'][0]['Total']['UnblendedCost']['Amount']))
Add Comment
Please, Sign In to add comment