

EC2 Console Launch Instance Wizard Spot Option Similar steps to get to these charts are also provided in the AWS EC2 Guide Docs. It is interesting to change the date range to 3 months to see how much spot prices have changed.Īlso, if you go a little deeper and click on Request Spot Instances, choose some Instance Types, click Select, and then click the Pricing History button, you can select multiple instances and compare them all in one chart. Here’s where the Pricing History button is:Īfter you have selected instances and clicked on the Pricing History button, you’ll be able to choose an instance type.

#AWS EC2 PRICING HOW TO#
We will look at the terms section later, but for now, let’s focus on the product section.Have you ever wondered how to find the current market spot price for an EC2 instance? When people first hear that spot instances can save you up 50%-90%, they tend to react in disbelief. If you look at a single product, you’d find that it has a the following structure: [ So what gives? We’ll look at that in the next section. Results of running the codeĮxecuting this script will return a JSON document of almost 10.000 lines! In the document you will find 60 products, all of them considered an m5.large in Ireland. You can find all region names on the AWS Regions and Endpoints page.
#AWS EC2 PRICING CODE#
‘EU (Ireland)’) instead of the Region Code (eg. Unfortunately, the Pricing API region requires the Region Name (eg. If you expect that this will only return one result, however, you might be in for a surprise. We will query the Pricing API so it will only return prices for EC2 instances located in the ‘EU (Ireland)’ region, with the m5.large instance type. We will then merge those results into an array called products. This will give us blocks of 100 results (as specified in the pagesize). The paginator will return an iterator, which we can loop over. This data cannot be returned in one request, which is why we use a paginator. The Pricing API will return a lot of data - we’ll get to that in a second.

If you don’t and then run your script in another AWS Region, it might fail because it can’t find the Pricing API in that region. This is the only region the Pricing API is available in, so you should hardcode it. The important part here is specifying the region as us-east-1. The pricing_client is defined as pricing_client = boto3.client('pricing', region_name='us-east-1'). Paginator = pricing_client.get_paginator( 'get_products')įor 38 lines of code, there is already a lot to digest here. Pricing_client = boto3.client( 'pricing', region_name= 'us-east-1') Let’s set up some basic scaffolding: import json We will write a python script that uses boto3 (the python SDK for AWS) to query the API, process the results, and store the data in a JSON file. In this blog post, we will focus on the first type.
