Demystifying AWS Pricing APIs & its Cryptic codes

Written by Dhruv.Desai | Published 2018/08/16
Tech Story Tags: aws | api | aws-ec2 | aws-pricing-apis | aws-pricing

TLDRvia the TL;DR App

Bob is a senior IT in charge of a mid-sized manufacturing company, having its operations in 10 countries, and factories in 2 countries.

The company decided two years back to migrate 80% of its IT infrastructure to AWS. As Bob led this activity, he was the go-to-guy for the finance dept., for verifying the bills.

For few months, Bob managed the verification of bills and budget planning, by going through AWS website and scrubbing pricing data, through his own eyes and mind.

But, Bob was a certified smart guy. So, he decided to automate it.

How? Let’s hear from Bob.

Me: Hey Bob, How you doing?

Bob: (smiles, coz he got who I sounded like) cool man, thanks.

Me: Bob, you used the AWS pricing APIs. What compelled you to do so?

Bob: The time taken to go through the AWS site, for pricing details.

We use 100s of EC2s of different flavours, of different sizes, TBs of different types of storages, databases, etc. And that’s just a small part of huge offerings by AWS.

Manually going through the prices, noting it at a particular date, keep looking for changes was too much. So, decided to do something about it.

By integrating the AWS APIs, now we have a dashboard tailored to our needs, and is always up-to-date. We have also created our own customized calculator for our users. It integrates the AWS prices and that from local vendors.

This has helped in streamlining our consumption and price is now more predictable.

Me: This makes sense for somebody like you, who deals with these many AWS components day-in-day-out, and is accountable for the expense.

Bob: Yes that true.

Me: I went through the API documentation of AWS Pricing. Let me summarize what I have understood, and ask you my doubts.

Bob: Sure

Me: First, the basics:

  1. The API access is through https.
  2. AWS provides the pricing information as json or csv.
  3. The APIs are publicly accessible, without AWS account.
  4. The base address for accessing json/csv is https://pricing.us-east-1.amazonaws.com/
  5. us-east-1 in above url is where all information is available and is not limited only to this zone.

To access the data, I followed these steps

Step1: Got the list of offerings from AWS by downloading

https://pricing.us-east-1.amazonaws.com/offers/v1.0/aws/index.json.

It has details of all AWS products and information of where to get its prices from.

For eg.

“AmazonEC2”: { “offerCode” : “AmazonEC2”, “versionIndexUrl” : “/offers/v1.0/aws/AmazonEC2/index.json”, “currentVersionUrl”: “/offers/v1.0/aws/AmazonEC2/current/index.json”, “currentRegionIndexUrl”: “/offers/v1.0/aws/AmazonEC2/current/region_index.json” },

(Note: A product, like AmazonEC2, is referred as ‘Offer’)

Step2: From the above set, accessed the ‘currentRegionIndexUrl’ url –

https://pricing.us-east-1.amazonaws.com/offers/v1.0/aws/AmazonEC2/current/region_index.json

It gave details of prices in each region.

For eg.

"ap-south-1" :{

"regionCode" : "ap-south-1",

"currentVersionUrl":"/offers/v1.0/aws/AmazonEC2/20180628005902/ap-south-1/index.json"

},

Now, the things are getting murkier. It’s a sea of confusing data.

There are some cryptic codes involved, and I couldn’t find any AWS document explaining these codes. Also, some sections show price as 0.0 dollars. How’s that possible?

Bob: The summary till now is correct. You have reached the source of data, but you are struggling to extract information out of it. To do that, you have to understand the offerings, and find patterns.

For example, you are accessing EC2 pricing. Now, EC2 pricing has variations like on-demand, dedicated hosts, reserved hosts. Then again, variations like full/no/partial upfront payment, etc.

Such variations are captured through those alien-looking codes.

Let’s take an example:

We want to check the price of Linux m5.large with SQL Enterprise preinstalled.

Through parsing, you get the code of this variant — ZV5VAXGR4YZS96VY

Search with this code and you will get multiple blocks in the file.

Each block represents a unique variant of the same product — the varying factors are mentioned above, like payment terms, dedicated hosts, etc

Each block will have a unique identifier, ‘Offertermcode’. For eg., ‘JRTCKXETXF’ represents on-demand pricing, payable per hr.

Another example, ‘HU7G6KETJZ’ represents reserved pricing with partial upfront fees. So the billing will include some amount to be paid upfront and some per month. ‘2TG2D8R56U’ is for upfront & ‘6YS6EN2CT7’ is for per/hr.

That’s it.

To summarize, there are three level of depths.

  1. Unique code of EC2 — say ZV5VAXGR4YZS96VY
  2. Unique offertermcode of above variant –On-demand, fully-upfront-paid, no-upfront-paid, etc –~13 unique offertermcode

  3. Upfront and/or Per-hr payment terms

Me: Thanks Bob. It’s clear and demystified now.

I really want to be like you.

AWS Price API documentation can be accessed here.

This post was originally posted here.

Please provide your feedback in the comment section. It will help me improve. You can also email me at [email protected].


Published by HackerNoon on 2018/08/16