Reputation: 3406
Is it possible to get the daily costs using the AWS CLI tool?
I am looking for an output similar to the information available via the Cost Explorer in the AWS Web Console. I need a simple way to quickly check the expenses in my AWS account for the last several days.
Upvotes: 7
Views: 2591
Reputation: 3406
It is possible to get the daily expenses for the last days using the aws ce
subcommand:
aws ce get-cost-and-usage \
--time-period Start=$(date +"%Y-%m-%d" --date="-240 hours"),End=$(date +"%Y-%m-%d") \
--granularity=DAILY \
--metrics BlendedCost \
--query "ResultsByTime[].[TimePeriod.Start, Total.BlendedCost.[Amount][0], Total.BlendedCost.[Unit][0]]" \
--output text
Output:
2021-07-11 1.9959926052 USD
2021-07-12 2.0098551581 USD
2021-07-13 1.9654925302 USD
2021-07-14 1.9829672821 USD
2021-07-15 1.996039161 USD
2021-07-16 2.0303596042 USD
2021-07-17 2.0193637439 USD
2021-07-18 2.0282529061 USD
2021-07-19 3.1817841617 USD
2021-07-20 5.0995626964 USD
Upvotes: 8