As a part of the daily job, I have to open the AWS cost explorer and extract the last 7 days of service-wise costing.
I want to automate the whole process and the output format should be a CSV as below
Service,EC2-Instances($),EC2-Other($),Relational Database Service($),S3($) 2021-12-21,50,100,200,12 2021-12-22,52,98,156,21
I have found one command which gives me the total costing of the last 7 days but can’t figure out how to get this type of result insted.
The current command I am using:
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], Total.BlendedCost.[Unit]]" \ --output text