I want to programatically retrieve a list of prices for given instance IDs for AWS EC2 instances. I'm trying to do this via plain REST API calls (ie. without a framework).
I want to provide a list of instance IDs:
i-12345
i-45678
...
and ultimately retrieve their price per hour:
i-12345 = $0.032
i-45678 = $0.56
...
I'm trying to use Postman with my AccessKey and SecretKey but getting a 401 Unauthorized when I use: https://ec2.amazonaws.com/?Action=DescribeInstances&Filter.1.Name=instance-id&Filter.1.Value=i-12345
It may well be that I need multiple REST calls:
- Describe instances to get the instance size and region.
- Call the pricing endpoint
https://docs.aws.amazon.com/aws-cost-management/latest/APIReference/Welcome.html
Any ideas?
Notes:
I'm aware of the price list JSON
https://aws.amazon.com/blogs/aws/new-aws-price-list-api/but this post was from 2015.I'm aware of the JSON downloads
https://pricing.us-east-1.amazonaws.com/offers/v1.0/aws/AmazonEC2/current/us-east-1/index.jsonbut this would require that I first know which region each of my instances is running in & then download the entire +20MB JSON for each region.I'm aware of the pricing page:
https://aws.amazon.com/ec2/pricing/which highlights another complication - how was the instance created.
Perhaps I'm going about this the wrong way. Perhaps I should be querying the cost explorer API to see how much the instances have cost over the last X days and thus extrapolate from that?
There's an pricing API, see Jeff Barr's Blog: https://aws.amazon.com/blogs/aws/aws-price-list-api-update-new-query-and-metadata-functions/
Note that pricing records are for multiple services, so a good filter can really help you zoom in on the records you get back and the number of pagination API calls needed (which translate to speed...).
Example: