Understanding Reserved Instance Billing

0

Hi, In our Cost and Usage Report (CUR), I am trying to figure out the per instance cost covered under Reserved Instance plan, however, I see, for each hour there are 4 line items with different reservation ID attributing to 4 different unblended cost. My question is how do I Calculate the per instance cost Daily & monthly ? RI Plan Line Item

2 Answers
1
Accepted Answer

I guess you are looking for cost per instance type under reserved instance and I assume you only need EC2. The easiest way is to use excel/quicksight pivot table and group by month/day. It allows you to group by reserved option. You can also easily get the weekly by week function excel or quicksight

Enter image description here

Alternatively, if you wish to do this in CUR query, you can sacrifice displaying the reservation id and filter by DiscountedUsage or the line_item_line_item_type you defined like what Nataliya mentioned. Here is an example query and you should get the item group by instance type per region per day within Sep 1 to Oct 1. You can modify the grouping of query by taking away some filters.

SELECT 
  bill_payer_account_id,
  line_item_usage_account_id,
  DATE_FORMAT((line_item_usage_start_date),'%Y-%m-%d') AS day_line_item_usage_start_date, 
  CASE 
    WHEN line_item_line_item_type IN ('Usage') THEN 'OnDemand'
    WHEN line_item_line_item_type IN ('Fee','RIFee','DiscountedUsage') THEN 'ReservedInstance' 
  END AS case_purchase_option,
  SPLIT_PART(line_item_usage_type ,':',2) AS split_line_item_usage_type_instance_type,
  SPLIT_PART(SPLIT_PART(line_item_usage_type ,':',2), '.', 1) AS split_line_item_usage_type_instance_family,
  CASE product_region
    WHEN NULL THEN 'Global'
    WHEN '' THEN 'Global'
    ELSE product_region
  END AS case_product_region,
  line_item_line_item_type,
  SUM(TRY_CAST(line_item_usage_amount AS DOUBLE)) AS sum_line_item_usage_amount,
  SUM(TRY_CAST(reservation_unused_quantity AS DOUBLE)) AS sum_reservation_unused_quantity,
  SUM(TRY_CAST(line_item_normalized_usage_amount AS DOUBLE)) AS sum_line_item_normalized_usage_amount,
  SUM(TRY_CAST(reservation_unused_normalized_unit_quantity AS DOUBLE)) AS sum_reservation_unused_normalized_unit_quantity,
  SUM(CAST(reservation_effective_cost AS DECIMAL(16,8))) AS sum_reservation_effective_cost,
  SUM(CAST(line_item_unblended_cost AS DECIMAL(16,8))) AS sum_line_item_unblended_cost
FROM 
  customer_all
WHERE 
  line_item_usage_start_date BETWEEN FROM_ISO8601_TIMESTAMP('2023-09-01T00:00:00') AND FROM_ISO8601_TIMESTAMP('2023-10-01T00:00:00')
  AND product_product_name = 'Amazon Elastic Compute Cloud'
  AND line_item_operation LIKE '%RunInstance%'
  AND line_item_line_item_type IN ('Usage','Fee','RIFee','DiscountedUsage')
  AND product_product_family NOT IN ('Data Transfer')
GROUP BY 
  bill_payer_account_id,
  line_item_usage_account_id,
  DATE_FORMAT((line_item_usage_start_date),'%Y-%m-%d'),
  4, -- refers to case_purchase_option
  SPLIT_PART(line_item_usage_type ,':',2),
  SPLIT_PART(SPLIT_PART(line_item_usage_type ,':',2), '.', 1),
  7, -- refers to case_product_region
  line_item_line_item_type
ORDER BY 
  day_line_item_usage_start_date,
  split_line_item_usage_type_instance_type,
  sum_line_item_unblended_cost DESC;

You are able to get the example query from the below link. From the example above, it should give you the excel that you generated.

https://www.wellarchitectedlabs.com/cost-optimization/cur_queries/queries/compute/#ec2-reserved-instance-coverage

AWS
answered 7 months ago
profile picture
EXPERT
reviewed 22 days ago
  • Thanks so much. Appreciate your help and sorry for the delayed response. Yes, my query looks prety much the same and I am using the filer WHERE line_item_line_item_type = 'DiscountedUsage' and considering the unblended hourly rate for corresponding reservation ARN from line_item_line_item_type = RIFee. This gives me a complete breakdown of charges included under RIFee.

1

Could you share the SQL query you are using to pull this data from CUR? I feel like you're mixing the recurring cost for the Reserved Instance itself, with the cost for the running EC2 instances...

WHERE line_item_line_item_type = 'DiscountedUsage' is the right filter to use if you want to find instances covered by RIs. However, in line items where you have DiscountedUsage, your Unblended Cost should be $0; which is why I'm surprised to see some values in the unblended cost column (and suspect this must be the cost for the actual RI - reservation ARN)

profile pictureAWS
EXPERT
answered 7 months ago
  • Thanks Nataliya. Appreciate your quick help. Sorry for delayed response. Yes, I am using the filer WHERE line_item_line_item_type = 'DiscountedUsage' and considering the unblended hourly rate for corresponding reservation ARN from line_item_line_item_type = RIFee. This gives me a complete breakdown of charges included under RIFee.

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions