Skip to content

Instantly share code, notes, and snippets.

@modille
Created February 3, 2016 15:47
Show Gist options
  • Save modille/506269f96ced03f87861 to your computer and use it in GitHub Desktop.
Save modille/506269f96ced03f87861 to your computer and use it in GitHub Desktop.
AWS Lambda EstimatedCharges
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