How do you get last month's cost by service from the CLI?
IntermediateProductionRapid-Fire AWS CLI
Answer
aws ce get-cost-and-usage \
--time-period Start=2026-10-01,End=2026-11-01 \
--granularity MONTHLY --metrics UnblendedCost \
--group-by Type=DIMENSION,Key=SERVICE \
--query 'ResultsByTime[0].Groups[].[Keys[0],Metrics.UnblendedCost.Amount]' --output text | sort -k2 -nr | head
Use Type=TAG,Key=cost-center to group by an activated cost allocation tag. The End date is exclusive.
More on Rapid-Fire AWS CLI
How do you check which identity and account the CLI is using?BeginnerHow do you log in with Identity Center (SSO) from the CLI?BeginnerHow do you assume a role manually and export the credentials?IntermediateHow do you list running instances with name, ID, type and private IP in a table?BeginnerHow do you find the latest Amazon Linux 2023 AMI without hard-coding an ID?BeginnerHow do you open a shell or port-forward to a private instance without SSH?Beginner