How do I use Amazon Athena to query my Cost and Usage Reports to show total costs for each of my S3 buckets?

Last updated: 2019-09-30

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 Simple Storage Service (Amazon S3) buckets. How do I do that?


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

Then, run the following query in Athena:

-- s3_by_bucket.sql
    when "line_item_usage_type" like '%Byte%' then "line_item_usage_amount"/1024
    else "line_item_usage_amount"
  end) as "Usage",
    when "line_item_usage_type" like '%Byte%' then 'TBs'
    else 'Requests'
  end as "Usage Units",
  sum("line_item_unblended_cost") as cost
where "line_item_product_code" = 'AmazonS3'
group by
order by
  sum("line_item_unblended_cost") desc

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

This query retrieves the following:

  • Your total monthly S3 costs by usage type
  • The resource ID for your S3 buckets (bucket name)
  • The usage amount
  • The usage unit (TBs or requests)
  • The total cost (in USD)

For the current month, the output shows you your estimated costs.

You can add more columns and metadata to the output of this query. For example, you might add lineItem/UsageAccountId or product/region. For more information, see Cost and Usage Report Details.

Did this article help you?

Anything we could improve?

Need more help?