region m3.large m3.medium m4.2xlarge m4.xlarge m3.2xlarge m4.large m4.4xlarge m4.10xlarge m3.xlarge
------------ ---------- ----------- ------------ ----------- ------------ ---------- ------------ ------------- -----------
apac-sin 0.0216 0.0115 0.1553 0.353 0.0906 0.1085 0.318 0.353 0.0433
us-west 0.0176 0.0085 0.0882 0.0348 0.0695 0.0145 0.15 0.3361 0.0337
apac-syd 0.0203 0.0102 1 0.0908 0.0817 0.018 0.142 0.353 0.0419
eu-ireland 0.0205 0.011 0.0676 0.0389 0.0824 0.0172 0.111 0.3654 0.0413
apac-tokyo 0.0207 0.0119 0.0744 0.0391 0.0823 0.0225 0.1741 0.4252 0.0414
us-east 0.0165 0.0081 0.0552 0.0296 0.0678 0.0145 0.1592 0.3314 0.0331
us-west-2 0.0163 0.0091 0.0545 0.2521 0.0678 0.0276 0.101 0.4316 0.035
eu-central-1 0.0204 0.0108 0.0889 0.0337 0.0812 0.0159 0.12 2.9951 0.0424
sa-east-1 0.0206 0.0103 0 0 0.0811 0 0 0 0.0406
Last active
August 29, 2015 14:24
-
-
Save marklit/12619d37398c01f14268 to your computer and use it in GitHub Desktop.
EC2 spot prices in tabular form across all regions
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
pip install requests termcolor tabulate |
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 json | |
from termcolor import colored | |
import requests | |
from tabulate import tabulate | |
resp = requests.get('http://spot-price.s3.amazonaws.com/spot.js') | |
content = resp.content.strip().replace('callback(', '')[:-1] | |
content = json.loads(content) | |
assert len(content['config']['regions']) >= 9 | |
prices = {} | |
for region in content['config']['regions']: | |
if region['region'] not in prices: | |
prices[region['region']] = {} | |
for instance_types in region['instanceTypes']: | |
if instance_types['type'] != 'generalCurrentGen': | |
continue | |
for size in instance_types['sizes']: | |
for os_type in size['valueColumns']: | |
if os_type['name'] != 'linux': | |
continue | |
try: | |
price = float(os_type['prices']['USD']) | |
except ValueError: | |
price = 0.0 | |
prices[region['region']][size['size']] = price | |
instance_types = set([instance_type for instance_type in prices[key].keys() \ | |
for key in prices.keys()]) | |
table = [['region'] + list(instance_types)] + \ | |
[[region] + [prices[region][instance_type] | |
for instance_type in instance_types] | |
for region in prices.keys()] | |
for col_id, val in enumerate(table[0]): | |
if not col_id: | |
continue | |
# TODO this should be by column and not row | |
low = min([p for p in table[col_id] if p > 0 and type(p) is float]) | |
high = max([p for p in table[col_id] if p > 0 and type(p) is float]) | |
closer = {key: low - p > p - high | |
for key, p in enumerate(table[col_id]) | |
if key > 0} | |
for row_id, cost in enumerate(table[col_id]): | |
if type(cost) is not float: | |
continue | |
if row_id in closer and closer[row_id]: | |
table[col_id][row_id] = colored(table[col_id][row_id], 'green') | |
else: | |
table[col_id][row_id] = colored(table[col_id][row_id], 'red') | |
print tabulate(table, headers="firstrow") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment