How can I see the Trailing 3-month Spot Discount for each instance type and Availability Zone?

3 minute read
Content level: Advanced

I want to know which Availability Zone have provided the best discount for Spot instances over the past 3 months

Short description

Spot instances are unused EC2 Capacity and pricing hourly based on supply and demand. This means that pricing can vary between Availability Zones. Pricing data is stored in CUR and can be queried with Athena in order to see which Availability Zone was the cheapest during the lookback period.



Create SQL View in CUR Using Athena

  1. Open the Athena Query Editor
  2. Select the database from the drop down menu that contains the Cost and Usage Report data
  3. Run the following query to create a view for the trailing 3 months:

Note: customer_all is a default table name that contains unpartitioned data from CUR

SELECT product_instance_type "Instance Type", product_region "Region" , product_availability_zone "AZ", line_item_unblended_cost "Spot Cost", pricing_public_on_demand_cost "On-Demand", line_item_operation, line_item_line_item_type, month
FROM customer_all
WHERE line_item_operation like '%RunInstances%SV%' and line_item_line_item_type like '%Usage%' and (CAST("concat"("year", '-', "month", '-01') AS date) >= ("date_trunc"('month', current_date) - INTERVAL '3' MONTH))
  1. Ensure the query completed successfully. You should see a VIEW named spot_3months on the left hand side of the console.

Pull Spot Discount Data with SQL Query

  1. Run the following query against the same database that you did in the previous section:
SELECT "Instance Type", "Region", "AZ",
sum ("Spot Cost") "Spot Cost (Before EDP Discount)",
sum ("On-Demand") "On-Demand Cost",
1.0- (sum("Spot Cost")/sum("On-Demand")) "Discount" ,
month "Month"
FROM "spot_3months"
GROUP by 1,2,3, month
  1. Ensure the query completed successfully. The output should be in the following format:
#Instance TypeRegionAZSpot Cost (before PPA)On-Demand CostDiscountMonth

Interpreting the Data

  • Looking at the above data, you can see that r5b.4xlarge averaged a 59% discount in usw2-az3 while averaging a 41% discount in usw2-az2 during October.
  • It is important to remember that this data does not take into consideration capacity or availability of instance types or any active PPAs (such as an EDP)

Related information

Spot Instances

Spot Instance pricing history

profile pictureAWS
published 4 months ago1812 views