Skip to content

Instantly share code, notes, and snippets.

@tatsuru
Created October 15, 2014 08:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tatsuru/70437490e1fb1bb0c7df to your computer and use it in GitHub Desktop.
Save tatsuru/70437490e1fb1bb0c7df to your computer and use it in GitHub Desktop.
ec2 price
#!/usr/bin/env ruby
require 'json'
def parse(uri)
JSON.parse `curl #{uri}`.gsub("/*\n * This file is intended for use only on aws.amazon.com. We do not guarantee its availability or accuracy.\n *\n * Copyright 2014 Amazon.com, Inc. or its affiliates. All rights reserved.\n */\ncallback({",'{').gsub("\);", '').gsub(/([a-zA-Z]+):/, '"\1":')
end
table = {
:light => parse('http://a0.awsstatic.com/pricing/1/ec2/previous-generation/light_linux.min.js'),
:medium => parse('http://a0.awsstatic.com/pricing/1/ec2/previous-generation/medium_linux.min.js'),
:heavy => parse('http://a0.awsstatic.com/pricing/1/ec2/previous-generation/heavy_linux.min.js'),
}
puts %w(
region
type
utilization
hourly_1year
upfront_1year
hourly_3year
upfront_3year
).join("\t")
table.each_key do |utilization|
table[utilization]['config']['regions'].each do |region_table|
current_region = region_table["region"]
region_table["instanceTypes"].each do |type_group|
type_group["sizes"].each do |type_table|
current_type = type_table["size"]
upfront_1year = type_table["valueColumns"].find{|x| x["name"] == "yrTerm1"}["prices"]["USD"].to_f
upfront_3year = type_table["valueColumns"].find{|x| x["name"] == "yrTerm3"}["prices"]["USD"].to_f
hourly_1year = type_table["valueColumns"].find{|x| x["name"] == "yrTerm1Hourly"}["prices"]["USD"].to_f
hourly_3year = type_table["valueColumns"].find{|x| x["name"] == "yrTerm3Hourly"}["prices"]["USD"].to_f
puts [current_region, current_type, utilization, hourly_1year, upfront_1year, hourly_3year, upfront_3year].join("\t")
end
end
end
end
@tatsuru
Copy link
Author

tatsuru commented Oct 15, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment