Created
February 3, 2016 15:47
-
-
Save modille/506269f96ced03f87861 to your computer and use it in GitHub Desktop.
AWS Lambda EstimatedCharges
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
import boto3 | |
from datetime import datetime, timedelta | |
region = 'us-east-1' | |
cloudwatch = boto3.client( 'cloudwatch', region_name=region ) | |
def lambda_handler( event, context ): | |
today = datetime.now() + timedelta( days=1 ) # today + 1 because we want all of today | |
two_weeks_ago = today - timedelta( days=14 ) | |
metrics = cloudwatch.get_metric_statistics( | |
Namespace = 'AWS/Billing', | |
MetricName = 'EstimatedCharges', | |
Dimensions = [ | |
{ | |
'Name': 'Currency', | |
'Value': 'USD' | |
} | |
], | |
StartTime = two_weeks_ago, | |
EndTime = today, | |
Period = 21600, | |
Statistics = [ | |
'Maximum' | |
], | |
Unit = 'None' | |
) | |
print metrics['Datapoints'] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment