Skip to content

Instantly share code, notes, and snippets.

@garyellis
Created March 13, 2018 15:41
Show Gist options
  • Save garyellis/e19970fe2ffffb21af0286f18be604cb to your computer and use it in GitHub Desktop.
Save garyellis/e19970fe2ffffb21af0286f18be604cb to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
import json
import requests
url = 'https://pricing.us-east-1.amazonaws.com/offers/v1.0/aws/AmazonEC2/current/index.json'
resp = requests.get(url=url)
data = json.loads(resp.text)
hourlyTermCode = 'JRTCKXETXF'
rateCode = '6YS6EN2CT7'
products = data['products']
def ebs_get_rate_gb_month(region, volume_type):
cost_mappings = {
'regions': {
'us-west-1': 'US West (N. California)',
'us-west-2': 'US West (Oregon)',
'us-east-1': 'US East (N. Virginia)',
'us-east-2': 'US East (Ohio)'
},
'volume_types': {
'standard': 'Magnetic',
'gp2': 'General Purpose'
}
}
for sku, properties in products.iteritems():
if properties['productFamily'] == 'Storage':
if (properties['attributes']['location'] == cost_mappings['regions'][region] and
properties['attributes']['volumeType'] == cost_mappings['volume_types'][volume_type]):
price = data['terms']['OnDemand'][sku][sku + '.' + hourlyTermCode]['priceDimensions'][sku + '.' + hourlyTermCode + '.' + rateCode]['pricePerUnit']['USD']
return price
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment