How do I use Amazon Athena to query my Cost and Usage Reports to show total costs for my Amazon EC2 Spot instances?

Last updated: 2020-01-07

I want to use Amazon Athena to query my Cost and Usage Report (CUR) and find out the total costs for each of my Amazon EC2 Spot instances. How do I do that?

Resolution

Before you get started, be sure that you've ingested your CUR into Amazon Athena.

Then, run the following query in Athena:

select
sum(line_item_unblended_cost) as cost
from DATABASE.TABLE
where
lower(line_item_usage_type) like '%spot%'
and line_item_product_code = 'AmazonEC2'

Note: Replace DATABASE and TABLE with the name of your database and table.

The query returns the following:

  • The account that the Spot instance ran on, or is running on
  • The usage details for what types of instances ran, or are running
  • The blended costs for the Spot instances

Did this article help you?

Anything we could improve?


Need more help?