Find out the most costly resources in your AWS account

As a builder in cloud, you might feel confused about which resources cost mostly in your account.

In AWS, you can quickly find out which services even functionality cost a lot via AWS Billing or AWS Cost Explorer. However sometimes it sucks on finding out which functions cost mostly if you have hundreds of Lambda functions, or which metrics/log groups cost mostly in Amazon CloudWatch.

AWS Cost and Usage Reports should be helpful in above scenairos. The AWS Cost and Usage Reports (AWS CUR) contains the most comprehensive set of cost and usage data available, including product and product resource, and tags that you define yourself. You can use Cost and Usage Reports to publish your AWS billing reports to an Amazon S3 bucket that you own. The CUR reports are plain CSV text file, you still need analysis the report to find out the insight what you want. So Amazon Athena is one of simplest and effcientst ways to analyze your cost on demand. See the doc to how set up the Athea to analyze your AWS cost.

Athena is out-of-the-box integrated with AWS Glue Data Catalog, allowing you to create a unified metadata repository across various services. With Amazon Athena, you pay only for the queries that you run. See my post how using Glue and Athena to analyze images in Docker repository.

Below are few samples to find out the mostly cost resources in your AWS account,

1SELECT line_item_resource_id as resource, sum(line_item_unblended_cost) as total_cost  FROM "athenacurcfn_main_account"."main_account" 
2WHERE year='2022' and month='1' and product_product_name = 'AmazonCloudWatch' 
3GROUP BY line_item_resource_id
4ORDER BY total_cost DESC
5LIMIT 10
Sample 1: find out the top 10 costly resources in CloudWatch, including Log Groups, Metrics, Synthetics and so on

1SELECT line_item_resource_id, sum(line_item_usage_amount) as usage_amount, sum(line_item_blended_cost) as paid_amount FROM "athenacurcfn_main_account"."main_account"
2    WHERE line_item_product_code='AWSLambda' and product_group='AWS-Lambda-Duration'
3    and year='2022' and month='1'
4    GROUP BY line_item_resource_id
5    ORDER BY usage_amount desc
6    LIMIT 10;
Sample 2: find out the top 10 costly Lambda functions

You can refer to Data dictionary of CUR to understand the field definitions of report.

Posts in this Series

    comments powered by Disqus