Commit b8eca7a1 by diegolima

support RDS parsing

1 parent 424eeb45
Showing with 52 additions and 22 deletions
import urllib.request
import json
import sys
if len(sys.argv) == 1:
print('You need to specify a product type', end='\n\n')
print('Supported product types are:')
print('- compute')
print('- database')
exit(1)
PRODUCT_TYPE = sys.argv[1]
if (PRODUCT_TYPE != 'compute') and (PRODUCT_TYPE != 'database'):
print('Product type needs to be either computer or database!')
exit(1)
TERM_ONDEMAND = 'JRTCKXETXF' #Ondemand. TODO: Find out where to get this from
HOURLY_DIMENSION = '6YS6EN2CT7' #Tier1. TODO: Find out where to get this from
if PRODUCT_TYPE == 'compute':
FCATALOG = 'ec2.json'
CATALOG = 'https://pricing.us-east-1.amazonaws.com/offers/v1.0/aws/AmazonEC2/current/index.json'
PRODUCT_FAMILY = 'Compute Instance'
elif PRODUCT_TYPE == 'database':
FCATALOG = 'rds.json'
CATALOG = 'https://pricing.us-east-1.amazonaws.com/offers/v1.0/aws/AmazonRDS/current/index.json'
PRODUCT_FAMILY = 'Database Instance'
with urllib.request.urlopen(CATALOG) as url:
DATA = json.loads(url.read().decode())
# with open(FCATALOG) as url:
# DATA = json.load(url)
for product in DATA["products"]:
if DATA['products'][product]['productFamily'] == PRODUCT_FAMILY:
sku = DATA['products'][product]['sku']
key = DATA['terms']['OnDemand'].get(sku)
if key:
cost = key[sku + '.' + TERM_ONDEMAND]['priceDimensions'][sku + '.' + TERM_ONDEMAND + '.' + HOURLY_DIMENSION]['pricePerUnit']['USD']
if cost != '0.0000000000':
print('aws', end=',')
print(DATA['products'][product]['attributes']['instanceType'], end=',')
print(DATA['products'][product]['attributes']['vcpu'], end=',')
print(DATA['products'][product]['attributes']['memory'], end=',')
print(cost, end=',')
print(DATA['products'][product]['attributes']['location'], end=',')
if PRODUCT_TYPE == 'compute':
print(DATA['products'][product]['attributes']['operatingSystem'])
elif PRODUCT_TYPE == 'database':
print(DATA['products'][product]['attributes']['databaseEngine'], end=',')
print(DATA['products'][product]['attributes'].get('databaseEdition'), end=',')
print(DATA['products'][product]['attributes']['licenseModel'], end=',')
print(DATA['products'][product]['attributes']['deploymentOption'])
import urllib.request
import json
TERM_ONDEMAND = 'JRTCKXETXF' #TODO: Find out where to get this from
HOURLY_DIMENSION = '6YS6EN2CT7' #TODO: Find out where to get this from
with urllib.request.urlopen("https://pricing.us-east-1.amazonaws.com/offers/v1.0/aws/AmazonEC2/current/index.json") as url:
DATA = json.loads(url.read().decode())
for product in DATA["products"]:
if DATA['products'][product]['productFamily'] == 'Compute Instance':
sku = DATA['products'][product]['sku']
key = DATA['terms']['OnDemand'].get(sku)
if key:
cost = key[sku + '.' + TERM_ONDEMAND]['priceDimensions'][sku + '.' + TERM_ONDEMAND + '.' + HOURLY_DIMENSION]['pricePerUnit']['USD']
if cost != '0.0000000000':
print('aws', end=',')
print(DATA['products'][product]['attributes']['instanceType'], end=',')
print(DATA['products'][product]['attributes']['vcpu'], end=',')
print(DATA['products'][product]['attributes']['memory'], end=',')
print(cost, end=',')
print(DATA['products'][product]['attributes']['location'], end=',')
print(DATA['products'][product]['attributes']['operatingSystem'])
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!