title: REST API - AWS EC2 Pricing Per Hour
body: <p>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).</p>
  
  <p>I want to provide a list of instance IDs:</p>
  
  <pre><code>i-12345   
  i-45678
  ...
  </code></pre>
  
  <p>and ultimately retrieve their price per hour:</p>
  
  <pre><code>i-12345 = $0.032
  i-45678 = $0.56
  ...
  </code></pre>
  
  <p>I'm trying to use Postman with my <code>AccessKey</code> and <code>SecretKey</code> but getting a <code>401 Unauthorized</code> when I use: <code>https://ec2.amazonaws.com/?Action=DescribeInstances&amp;Filter.1.Name=instance-id&amp;Filter.1.Value=i-12345</code></p>
  
  <p>It may well be that I need multiple REST calls:</p>
  
  <ol>
  <li>Describe instances to get the instance size and region.</li>
  <li>Call the pricing endpoint <code>https://docs.aws.amazon.com/aws-cost-management/latest/APIReference/Welcome.html</code></li>
  </ol>
  
  <p>Any ideas?</p>
  
  <p>Notes:</p>
  
  <ul>
  <li><p>I'm aware of the price list JSON <code>https://aws.amazon.com/blogs/aws/new-aws-price-list-api/</code> but this post was from 2015.</p></li>
  <li><p>I'm aware of the JSON downloads <code>https://pricing.us-east-1.amazonaws.com/offers/v1.0/aws/AmazonEC2/current/us-east-1/index.json</code> but this would require that I first know which region each of my instances is running in &amp; then download the entire +20MB JSON for each region.</p></li>
  <li><p>I'm aware of the pricing page: <code>https://aws.amazon.com/ec2/pricing/</code> which highlights another complication - <em>how</em> was the instance created.</p></li>
  </ul>
  
  <p>Perhaps I'm going about this the wrong way. Perhaps I should be querying the <code>cost explorer API</code> to see how much the instances <em>have</em> cost over the last X days and thus extrapolate from that?</p>