Sub topic 3
Seeing your spend with billing and cost-analysis tools
This chapter assumes you can run AWS CLI commands with credentials that can read billing data, and that you can read JSON. It also assumes you know the chapter on cost drivers: compute, storage and data transfer. Here you learn which tools show your spend, how to query them, and which settings make the numbers misleading.
Why visibility comes first
You cannot lower a cost you cannot see. The earlier chapter on cost drivers told you what usually costs money. Cost visibility tells you what costs money in your accounts, in which service, in which Region, and for which owner.
AWS offers three layers of tooling. They read the same underlying billing data but differ in detail, delay, and how you use them.
| Tool | Best for | Detail level | Access |
|---|---|---|---|
| Billing console and invoices | Checking what you will be charged | Monthly totals by service | Console |
| Cost Explorer | Interactive and scripted analysis | Daily or monthly, grouped by dimensions | Console and API |
| Data Exports (Cost and Usage Report) | Custom analysis and chargeback | Line items per resource and usage type | Files in S3, queried with SQL |
Cost Explorer
Cost Explorer is the first tool to use. It shows spend over time and lets you filter and group it. The main controls are the same in the console and the API:
- Time period and granularity. Choose monthly or daily. Hourly granularity exists, but you must opt in, and it covers only a recent window.
- Metric. This is the definition of "cost" (see the next section).
- Group by. Split the total by a dimension such as service, linked account, Region, usage type, or instance type. You can also group by a cost allocation tag.
- Filter. Keep only some of the data, for example one account or one service.
Cost Explorer keeps about the last 13 months of data, and its figures refresh at least once per day. A charge from this morning may not show yet. For that reason, treat Cost Explorer as a trend tool, not a real-time meter.
Choosing the right cost metric
The metric you choose changes the number. A team that compares figures from two different metrics will argue about a difference that does not exist.
| Metric | What it shows | Typical use |
|---|---|---|
| UnblendedCost | The charge as it appears on the day of usage or purchase | Default view of what was billed |
| BlendedCost | An average rate across accounts in an organization | Rarely useful for analysis |
| AmortizedCost | Upfront commitment fees spread across the term | Comparing spend when you hold Savings Plans or Reserved Instances |
| NetUnblendedCost | Unblended cost after discounts such as private pricing | Seeing what you actually pay |
| UsageQuantity | Units used, such as GB-months or instance hours | Checking whether usage or price changed |
Querying spend from the CLI
The Cost Explorer API lets you script the same analysis. This command returns October 2026 unblended cost grouped by service, which shows your largest cost drivers.
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=SERVICESeveral details matter:
- The end date is exclusive.
End=2026-11-01covers all of October and nothing from November. - The Cost Explorer endpoint is in us-east-1. The CLI normally handles this for you, but if you see endpoint errors, set
--region us-east-1. - Each API request is billed. Cost Explorer API requests cost a small fee per paginated request, so avoid running a query in a tight loop or from a dashboard that refreshes every few seconds.
- Results are paginated. If the response includes a
NextPageToken, repeat the call with--next-page-tokento get the rest. - You can group by at most two keys. To group by more, use Data Exports and SQL.
The raw response is long. To print only the service names and amounts, sort them, and show the biggest first, use the CLI's --query option together with --output table, or pipe the JSON through jq:
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 \
--output json |
jq -r '.ResultsByTime[0].Groups
| map({service: .Keys[0], usd: (.Metrics.UnblendedCost.Amount | tonumber)})
| sort_by(-.usd)
| .[:5][]
| "\(.service)\t\(.usd)"'The result is your top five services for the month. In most accounts a few services account for most of the bill, so the top five are where to start looking.
Filtering out credits, refunds and tax
By default, Cost Explorer includes credits, refunds, and taxes in its totals. A large credit can hide a real increase in usage, and a tax line can look like growth. To see underlying usage, filter on the RECORD_TYPE dimension. Save this as filter.json:
{
"Not": {
"Dimensions": {
"Key": "RECORD_TYPE",
"Values": ["Credit", "Refund", "Tax"]
}
}
}Then apply it:
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 \
--filter file://filter.jsonKeep both views. The filtered one tells you how your usage is changing. The unfiltered one tells you what you will pay.
Grouping by tag
Grouping by service answers "what are we buying." It does not answer "who is buying it." For that you group by a cost allocation tag:
aws ce get-cost-and-usage \
--time-period Start=2026-10-01,End=2026-11-01 \
--granularity MONTHLY \
--metrics UnblendedCost \
--group-by Type=TAG,Key=teamThis only works after you do two things, which the next chapter covers in full:
- Put the tag on your resources.
- Activate the tag as a cost allocation tag in the Billing console.
Two limits catch people out. Tags apply from the day you activate them and are not retroactive, and activation can take up to a day to show in reports. Also, spend on resources that lack the tag appears in a group with an empty tag value. The size of that group is a useful measure of how complete your tagging is.
Data Exports for line-item detail
Cost Explorer shows totals. When you need to know which specific resource caused a charge, use Data Exports (the Cost and Usage Report). It writes line items to an S3 bucket, with one row per resource and usage type per time period. Each row includes the service, usage type, resource ID, Region, tags, and cost columns.
A typical workflow is:
- Create an export in the Billing console and choose an S3 bucket and daily or hourly time granularity.
- Include resource IDs if you need per-resource detail.
- Wait for the first delivery. This can take up to a day.
- Query the files with Athena, or load them into a warehouse.
With the data in Athena, a SQL query can group by any column and combine as many as you want. The cost is that you now own a small data pipeline, and large accounts produce a lot of data. Start with Cost Explorer, and use exports when its two-key grouping or its level of detail is not enough.
Common mistakes
- Reading a partial month as a total. Compare full months with full months, or compare equal day ranges.
- Mixing metrics. Note which metric each report uses, as shown above.
- Forgetting the exclusive end date. This silently drops a day.
- Trusting tag groups before activation. Early results undercount tagged spend.
- Looking only at the total. A flat total can hide one service growing while another shrinks. Group before you conclude anything.
A routine to start with
Once you have the commands, a simple routine gives you visibility without much effort:
- Each week, run the by-service query for the last full month and the current month so far.
- Compare the top five services with the previous month, using usage quantity if cost has moved.
- Group by team tag and check the size of the untagged group.
- Record anything that changed by more than an agreed margin, and find the owner.
The following chapters build on this: tags make the grouping meaningful, and budgets turn the same numbers into alerts.
Exercise
You run a Cost Explorer query for 2026-10-01 to 2026-10-31 with UnblendedCost, and the total is lower than the invoice you expect. Name two likely causes.
Show answer
First, the end date is exclusive, so End=2026-10-31 leaves out October 31. Use End=2026-11-01 to cover the whole month. Second, the chosen metric or filters differ from the invoice. For example, the invoice includes taxes, and a query that excludes Tax, Credit or Refund records, or that uses AmortizedCost, will not match it.
Exercise
You group a month of spend by the tag team, but the largest group has an empty tag value. What does this mean, and what do you do?
Show answer
The empty group holds spend on resources that have no team tag, or that were created before the tag was activated as a cost allocation tag, because activation is not retroactive. Find which services and accounts make up that group, tag those resources, confirm the tag is activated in the Billing console, and track the size of the group over time as a measure of tagging coverage.