0
0
AWScloud~5 mins

AWS Cost Explorer basics - Commands & Configuration

Choose your learning style9 modes available
Introduction
AWS Cost Explorer helps you see and understand your cloud spending. It shows where your money goes and helps you find ways to save.
When you want to check how much your cloud services cost each month.
When you need to find which service or project is using the most money.
When you want to compare costs between different months or years.
When you want to set budgets and alerts to avoid surprises.
When you want to plan your cloud spending for the future.
Commands
This command fetches your total blended cost for May 2024, showing how much you spent in that month.
Terminal
aws ce get-cost-and-usage --time-period Start=2024-05-01,End=2024-05-31 --granularity MONTHLY --metrics BlendedCost
Expected OutputExpected
{ "ResultsByTime": [ { "TimePeriod": { "Start": "2024-05-01", "End": "2024-05-31" }, "Total": { "BlendedCost": { "Amount": "1234.56", "Unit": "USD" } }, "Groups": [], "Estimated": false } ] }
--time-period - Defines the start and end dates for the cost data.
--granularity - Sets how detailed the data is (DAILY, MONTHLY, or HOURLY).
--metrics - Specifies which cost metric to retrieve.
This command shows daily costs for May 2024 grouped by each AWS service, helping you see which services cost the most each day.
Terminal
aws ce get-cost-and-usage --time-period Start=2024-05-01,End=2024-05-31 --granularity DAILY --metrics BlendedCost --group-by Type=DIMENSION,Key=SERVICE
Expected OutputExpected
{ "ResultsByTime": [ { "TimePeriod": { "Start": "2024-05-01", "End": "2024-05-01" }, "Total": {}, "Groups": [ { "Keys": ["AmazonEC2"], "Metrics": { "BlendedCost": { "Amount": "50.00", "Unit": "USD" } } }, { "Keys": ["AmazonS3"], "Metrics": { "BlendedCost": { "Amount": "10.00", "Unit": "USD" } } } ], "Estimated": false } ] }
--group-by - Groups cost data by a specific dimension like service.
This command creates a cost category named 'MyProjectCosts' to group costs by a linked account, helping organize costs by project.
Terminal
aws ce create-cost-category-definition --name "MyProjectCosts" --rule-version "CostCategoryExpression.v1" --rules '[{"Value":"ProjectA","Rule":{"Dimensions":{"Key":"LINKED_ACCOUNT","Values":["123456789012"]}}}]'
Expected OutputExpected
{ "CostCategoryArn": "arn:aws:ce::123456789012:costcategory/MyProjectCosts", "EffectiveStart": "2024-06-01T00:00:00Z" }
--name - Names the cost category.
--rules - Defines how costs are grouped in this category.
This command lists all cost categories you have created, so you can see and manage your cost groups.
Terminal
aws ce list-cost-category-definitions
Expected OutputExpected
{ "CostCategoryReferences": [ { "CostCategoryArn": "arn:aws:ce::123456789012:costcategory/MyProjectCosts", "Name": "MyProjectCosts", "EffectiveStart": "2024-06-01T00:00:00Z" } ] }
Key Concept

If you remember nothing else from this pattern, remember: AWS Cost Explorer lets you see your cloud costs clearly by time and service, helping you control spending.

Common Mistakes
Using incorrect date format in --time-period flag.
The command fails because AWS expects dates in YYYY-MM-DD format.
Always use the exact format like Start=2024-05-01,End=2024-05-31.
Not specifying --metrics flag when running get-cost-and-usage.
The command returns an error or no useful data without metrics specified.
Always include --metrics with values like BlendedCost or UnblendedCost.
Trying to create a cost category without proper JSON syntax in --rules.
The command fails due to invalid JSON format.
Use correct JSON syntax with escaped quotes and brackets as shown.
Summary
Use aws ce get-cost-and-usage to fetch cost data by time and service.
Group costs by service or account to understand spending details.
Create and list cost categories to organize costs by projects or teams.