Last active
December 24, 2015 03:57
-
-
Save winebarrel/b561ce585e0626aac08b to your computer and use it in GitHub Desktop.
Rubyとjqでap-northeast-1のLinux/OnDemandの料金を出すやつ
This file contains hidden or 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
#!/usr/bin/env ruby | |
require 'json' | |
require 'jq/extend' | |
#require 'pp' | |
trap(:PIPE, :EXIT) | |
# wget https://pricing.us-east-1.amazonaws.com/offers/v1.0/aws/AmazonEC2/current/index.json -O AmazonEC2.json | |
json = File.read('AmazonEC2.json') | |
jq = JQ(json) | |
products = jq.search <<-EOS | |
.products[] | |
| select(.productFamily == "Compute Instance") | |
| select(.attributes.location == "Asia Pacific (Tokyo)") | |
| select(.attributes.operatingSystem == "Linux") | |
| select(.attributes.tenancy == "Shared") | |
EOS | |
terms = jq.search('.terms').first | |
products.each do |product| | |
sku = product.fetch('sku') | |
ondemand = terms.fetch('OnDemand').fetch(sku) | |
reserved = terms.fetch('Reserved')[sku] | |
product['attributes']['term'] = { | |
'OnDemand' => ondemand, | |
'Reserved' => reserved | |
} | |
end | |
prices = products.jq(<<-EOS) | |
.[].attributes | |
| {instanceType, OnDemand: .term.OnDemand[].priceDimensions[].pricePerUnit.USD} | |
EOS | |
puts prices.jq('.[] | [.instanceType, .OnDemand] | @tsv').sort.join("\n") |
This file contains hidden or 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
$ ./price.rb | |
c1.medium 0.1580000000 | |
c1.xlarge 0.6320000000 | |
c3.2xlarge 0.5110000000 | |
c3.4xlarge 1.0210000000 | |
c3.8xlarge 2.0430000000 | |
c3.large 0.1280000000 | |
c3.xlarge 0.2550000000 | |
c4.2xlarge 0.5590000000 | |
c4.4xlarge 1.1170000000 | |
c4.8xlarge 2.2340000000 | |
c4.large 0.1400000000 | |
c4.xlarge 0.2790000000 | |
cc2.8xlarge 2.3490000000 | |
cr1.8xlarge 4.1050000000 | |
d2.2xlarge 1.6880000000 | |
d2.4xlarge 3.3760000000 | |
d2.8xlarge 6.7520000000 | |
d2.xlarge 0.8440000000 | |
g2.2xlarge 0.8980000000 | |
g2.8xlarge 3.5920000000 | |
hi1.4xlarge 3.2760000000 | |
hs1.8xlarge 5.4000000000 | |
i2.2xlarge 2.0010000000 | |
i2.4xlarge 4.0020000000 | |
i2.8xlarge 8.0040000000 | |
i2.xlarge 1.0010000000 | |
m1.large 0.2430000000 | |
m1.medium 0.1220000000 | |
m1.small 0.0610000000 | |
m1.xlarge 0.4860000000 | |
m2.2xlarge 0.5750000000 | |
m2.4xlarge 1.1500000000 | |
m2.xlarge 0.2870000000 | |
m3.2xlarge 0.7700000000 | |
m3.large 0.1930000000 | |
m3.medium 0.0960000000 | |
m3.xlarge 0.3850000000 | |
m4.10xlarge 3.6600000000 | |
m4.2xlarge 0.7320000000 | |
m4.4xlarge 1.4640000000 | |
m4.large 0.1830000000 | |
m4.xlarge 0.3660000000 | |
r3.2xlarge 0.8400000000 | |
r3.4xlarge 1.6800000000 | |
r3.8xlarge 3.3600000000 | |
r3.large 0.2100000000 | |
r3.xlarge 0.4200000000 | |
t1.micro 0.0260000000 | |
t2.large 0.1600000000 | |
t2.medium 0.0800000000 | |
t2.micro 0.0200000000 | |
t2.small 0.0400000000 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment