Athena query to know a EC2 instances cost

0

Hi:

  I'm trying to get the total costs of 2 EC2 instances but getting the detail of each amount that contributs to the total, I mean how much was for storage, for network usage and for compute usage.

Do you know how I can get it?

Thanks! BR

AWS
已提問 3 個月前檢視次數 1397 次
2 個答案
1

You can use lineItem/ResourceId to query anything that has the instance ID in it. But it won't give you the EBS volume. You would have to also query the specific EBS Volume ID. The best way to get the total cost associated with an EC2 instance is to use cost allocation tag. Without the tag, you would have to use the instance ID and the volume ID (that is attached to the instance) to query separately.

profile pictureAWS
專家
已回答 3 個月前
0

If you are okay to use Athena + CUR , then here's a query that you might want to try:

line_item_resource_id, bill_payer_account_id, bill_billing_period_start_date, line_item_usage_account_id, DATE_FORMAT(line_item_usage_start_date,'%Y-%m') AS month_line_item_usage_start_date, savings_plan_savings_plan_a_r_n, line_item_product_code, line_item_usage_type, SUM(line_item_usage_amount) AS sum_line_item_usage_amount, line_item_line_item_description, pricing_public_on_demand_rate, SUM(pricing_public_on_demand_cost) AS sum_pricing_public_on_demand_cost, savings_plan_savings_plan_rate, SUM(savings_plan_savings_plan_effective_cost) AS sum_savings_plan_savings_plan_effective_cost FROM "<CUR_DB>" WHERE year='<YEAR>' AND month='<MONTH>' AND line_item_resource_id='<Instance-Id>' AND line_item_line_item_type LIKE 'SavingsPlanCoveredUsage' GROUP BY line_item_resource_id, bill_payer_account_id, bill_billing_period_start_date, line_item_usage_account_id, DATE_FORMAT(line_item_usage_start_date,'%Y-%m'), savings_plan_savings_plan_a_r_n, line_item_product_code, line_item_usage_type, line_item_unblended_rate, line_item_line_item_description, pricing_public_on_demand_rate, savings_plan_savings_plan_rate ORDER BY sum_pricing_public_on_demand_cost DESC;

AWS
已回答 3 個月前

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南