Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@matschaffer
Last active July 6, 2021 13:05
Show Gist options
  • Star 18 You must be signed in to star a gist
  • Fork 5 You must be signed in to fork a gist
  • Save matschaffer/4912279e49dce41ab9b2 to your computer and use it in GitHub Desktop.
Save matschaffer/4912279e49dce41ab9b2 to your computer and use it in GitHub Desktop.
Bash-friendly ec2 prices
#!/usr/bin/env bash
URL="http://a0.awsstatic.com/pricing/1/ec2/ri-v2/linux-unix-shared.min.js"
(echo 'function callback(data) { console.log(JSON.stringify(data)); }'; curl -s "$URL") |\
node |\
jq -r '.config.regions[] |
select(.region == "us-east-1") |
.instanceTypes[] |
[
.type,
( .terms[] | select(.term == "yrTerm1") | .onDemandHourly[].prices.USD ),
(
.terms[] | select(.term == "yrTerm1") | .purchaseOptions |
map(.valueColumns[] | select(.name == "effectiveHourly") | .prices.USD)[]
),
(
.terms[] | select(.term == "yrTerm3") | .purchaseOptions |
map(.valueColumns[] | select(.name == "effectiveHourly") | .prices.USD)[]
)
] |
join("\t")
'
@abcarroll
Copy link

abcarroll commented Nov 28, 2016

@michael-gracy

See my updated version:

https://gist.github.com/abcarroll/86850dc3cb4d449719888ba6a213b051

  • Fixes where amazon changed json node keys to to "yrTerm1Standard" .. etc and broke it entirely
  • Also fixes the nano alignment issue

Note to anyone interested, these files are available for all AWS services that I can find.... But not all easily compatible/using the same node tree.

Just go to the AWS pricing page of your choice and view source, and find "data-model". You will find one file for every single PricingTable/Tab combo. For example MySQL standard deployments (single AZ) is:

http://a0.awsstatic.com/pricing/1/rds/mysql/pricing-standard-deployments.min.js

One small possible positive note -- it seems the URL/filenames themselves do follow a bit of a pattern. So it should be easy to generate them. If you had time and a little more powerful of a programming language, you could do great things.

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