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

所要時間3分
コンテンツレベル: 上級
2

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.

Resolution

Prerequisites:

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

CREATE OR REPLACE VIEW spot_3months AS
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
1r5b.4xlargeus-west-2usw2-az30.8269807582.0211027520.59082695910
2r5b.4xlargeus-west-2usw2-az2196.9376632334.44308390.41114744910
3r5b.4xlargeca-central-1cac1-az14.41511250922.630922610.80490797510
4r5b.4xlargeeu-west-1euw1-az11.3132077673.2564986640.59674242110

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
エキスパート
公開済み 9ヶ月前2253ビュー
コメントはありません

関連するコンテンツ