Created
December 5, 2017 08:20
-
-
Save okisanjp/0542ee04c714e51685ef5a50608b9f3d to your computer and use it in GitHub Desktop.
python boto3で~/.aws/credentialsのprofileごとに請求額を取る
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
# coding:utf-8 | |
from boto3.session import Session | |
import datetime | |
profiles = ['profile1', 'profile2'] | |
for profile in profiles: | |
session = Session(profile_name=profile) | |
client = session.client('cloudwatch', region_name = 'us-east-1') | |
bill_data = client.get_metric_statistics( | |
Namespace='AWS/Billing', | |
MetricName='EstimatedCharges', | |
Dimensions=[ | |
{ | |
'Name': 'Currency', | |
'Value': 'USD' | |
} | |
], | |
StartTime=datetime.datetime.today() - datetime.timedelta(days=1), | |
EndTime=datetime.datetime.today(), | |
Period=86400, | |
Statistics=['Maximum'] | |
)['Datapoints'][0] | |
print "{0:15s}".format(str(profile)) + "{0:8s}".format(str(bill_data['Maximum'])) + ' (USD)' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment