Getting Amazon EC2 prices from the JSON offering using jq

JQ is a nifty tool to parse, slice and dice json data .

I know I can do this with python/ruby/whatever but it’s fun to try something new ..

Instance offering for Linux + EU Ireland

curl https://pricing.us-east-1.amazonaws.com/offers/v1.0/aws/AmazonEC2/20160126001708/index.json | jq '[.products| to_entries | .[].value | select (.attributes.operatingSystem == "Linux" and .attributes.location=="EU (Ireland)")  | {key: .sku, value: .}]|from_entries'

Pricing info

curl https://pricing.us-east-1.amazonaws.com/offers/v1.0/aws/AmazonEC2/20160126001708/index.json | jq '.terms.OnDemand | .. | .priceDimensions? | select (. != null) |map_values (.)| map (. + {sku: .rateCode|split(".")[0]}) | .[] ' 

It would be cool to somehow combine the two (per instance pricing) but for now this is ‘good enough’.

Leave a Reply

Your email address will not be published. Required fields are marked *