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
已提问 2 个月前1396 查看次数
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
专家
已回答 2 个月前
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
已回答 2 个月前

您未登录。 登录 发布回答。

一个好的回答可以清楚地解答问题和提供建设性反馈,并能促进提问者的职业发展。

回答问题的准则

相关内容