Created
November 1, 2017 03:29
-
-
Save njeirath/2fb9a7d18301350c332d6fc7c5a46954 to your computer and use it in GitHub Desktop.
Parses AWS instance list
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
# Download https://pricing.us-east-1.amazonaws.com/offers/v1.0/aws/AmazonEC2/current/index.json to local directory as index.json | |
# | |
# Install pandas | |
import json | |
import pandas as pd | |
f = file("index.json", "r") | |
raw_data = json.loads(f.read()) | |
lumpy_data = [v for k, v in raw_data["products"].iteritems()] | |
data = [] | |
for ld in lumpy_data: | |
i = {k: v for k,v in ld["attributes"].iteritems()} | |
i["sku"] = ld["sku"] | |
i["productFamily"] = ld["productFamily"] | |
data.append(i) | |
df = pd.DataFrame(data) | |
#[nan, u'AWS GovCloud (US)', u'Asia Pacific (Mumbai)', u'Asia Pacific (Seoul)', u'Asia Pacific (Singapore)', | |
# u'Asia Pacific (Sydney)', u'Asia Pacific (Tokyo)', u'Canada (Central)', u'EU (Frankfurt)', u'EU (Ireland)', | |
# u'EU (London)', u'South America (Sao Paulo)', u'US East (N. Virginia)', u'US East (Ohio)', | |
# u'US West (N. California)', u'US West (Oregon)'] | |
df["location"] = df["location"].map({ | |
"US East (Ohio)": "us-east-2", "US East (N. Virginia)": "us-east-1", "US West (N. California)": "us-west-1", | |
"US West (Oregon)": "us-west-2", "Asia Pacific (Mumbai)": "ap-south-1", "Asia Pacific (Seoul)": "ap-northeast-2", | |
"Asia Pacific (Singapore)": "ap-southeast-1", "Asia Pacific (Sydney)": "ap-southeast-2", | |
"Asia Pacific (Tokyo)": "ap-northeast-1", "Canada (Central)": "ca-central-1", "EU (Frankfurt)": "eu-central-1", | |
"EU (Ireland)": "eu-west-1", "EU (London)": "eu-west-2", "South America (Sao Paulo)": "sa-east-1"}) | |
print df[(df["operatingSystem"] == "Linux") | |
& (df["location"].notnull()) | |
& (df["productFamily"] == "Compute Instance")][["location", "instanceType"]].\ | |
drop_duplicates().to_json(orient="records") | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi njeirath,
I've made a few adaptions to this script here, maybe there are a few features which you'd like to implement from that. The changes are:
Here's the code so far:
`
# Download https://pricing.us-east-1.amazonaws.com/offers/v1.0/aws/AmazonEC2/current/index.json to local directory as index.json
#
# Install pandas
`