- Newest
- Most votes
- Most comments
Hello,
Did you consider Cost and Usage Report (CUR)? This is the most detailed and granular data you can get about AWS usage. Enabling CUR won't create any additional cost, data is stored in S3, and you'll have to pay for the amount of data stored there. https://docs.aws.amazon.com/cur/latest/userguide/cur-create.html There are several ways to access data, from SQL queries leveraging Athena, to dashboards built on AWS services (QuickSight, Managed Grafana) or 3rd party tools. https://aws.amazon.com/blogs/mt/visualize-and-gain-insights-into-your-aws-cost-and-usage-with-amazon-managed-grafana/
Cheers.
Hello Again,
You don't have to use Athena console to query data. There are several alternatives, SDKs (EG boto3 for Python), JDBC access, AWS CLI, to name a few. Here an example using AWS CLI
- Run your query (in this case I want to know the most expensive CloudWatch resource in my organization for November 2023
aws athena start-query-execution \
--query-string "SELECT line_item_resource_id, SUM(line_item_unblended_cost) FROM customer_all WHERE year = '2023' AND month = '11' AND line_item_product_code = 'AmazonCloudWatch' GROUP BY 1 ORDER BY 2 DESC" \
--work-group "primary" \
--query-execution-context Database=customer_cur_data,Catalog=AwsDataCatalog
The result is the execution ID
{ "QueryExecutionId": "b00ea88a-ae00-4020-81cf-3310bd9f9556" }
You can then access the result from the S3 (defined in Athena as query result location)
`aws s3 cp s3://aws-athena-query-results-11111111111-us-east-1/b11ea11a-ae11-1111-11cf-1110bd1f1111.csv .`
A couple of lines from the cvs file:
line_item_resource_id _col1
arn:aws:logs:ap-southeast-2:111111111111:log-group:/prefix/name1 2454.3543
arn:aws:logs:ap-southeast-2:111111111111:log-group:/prefix/name2 2193.3111
Some references: https://awscli.amazonaws.com/v2/documentation/api/latest/reference/athena/start-query-execution.html https://docs.aws.amazon.com/athena/latest/ug/querying.html#query-results-specify-location
Relevant content
- asked 2 years ago
- AWS OFFICIALUpdated 2 years ago
- AWS OFFICIALUpdated 2 years ago
- AWS OFFICIALUpdated 2 years ago
- How do I resolve the "failed to obtain in-memory shard lock" exception in Amazon OpenSearch Service?AWS OFFICIALUpdated a year ago
Hello,
Thank you for your suggestion. I have considered Cost and Usage Reports (CUR) previously, but I'm specifically looking for an API, SDK, or AWS CLI solution to automate the extraction of detailed cost breakdowns based on individual resources. I want to avoid any clickable actions or manual steps to ensure a seamless integration into my existing workflow.
If there are any specific AWS CLI commands or API calls that can provide resource-based cost breakdowns without the need for granularity activation, I would greatly appreciate the guidance.
Thank you for your continued assistance.
Thank you for the response; the provided solution works seamlessly!