Sub topic 4
Tagging and allocating costs to owners
This chapter assumes you can read a monthly AWS bill by service, as covered in the previous chapter on cost visibility. It also assumes you can run AWS CLI commands and read JSON. The examples use AWS. Azure and Google Cloud have similar features, called tags and labels respectively.
Why service-level views are not enough
A bill grouped by service tells you that Amazon EC2 cost 40,000 USD last month. It does not tell you which team or product caused that cost. Without an owner, nobody has a reason to act on the number.
Allocation links each charge to an owner, such as a team, product, environment, or cost center. AWS gives you three main ways to do this:
- Account structure. Each team or environment gets its own AWS account, and the bill splits by account with no extra work.
- Cost allocation tags. Key-value labels on resources are carried into billing data, so you can group spend by them.
- Cost categories. Rules in AWS Cost Categories map accounts, services, and tags into named groups, such as "Platform" or "Customer-facing".
Most organizations combine all three. Accounts give a hard boundary. Tags give detail inside an account. Cost categories roll the results up into business units.
How tags reach your bill
A tag is a key-value pair attached to a resource, such as team=checkout. Tags are not billing data by default. A tag has to pass through several steps before it appears in a cost report.
Three points about this pipeline cause most of the confusion:
- Activation is required. A tag key must be activated as a cost allocation tag in the Billing and Cost Management console, or through the API. Tagging a resource alone is not enough.
- It is not retroactive. Cost data is tagged only from the moment of activation. Spend from before that point stays untagged.
- It is delayed. After activation, it can take up to 24 hours for the key to show up in Cost Explorer.
Activate a key from the CLI like this:
aws ce update-cost-allocation-tags-status \
--region us-east-1 \
--cost-allocation-tags-status TagKey=team,Status=Active TagKey=env,Status=ActiveThe Cost Explorer API is served from us-east-1, so pass that region explicitly if your default differs. Run this from the management account of an organization, or from a standalone account. Member accounts in an organization cannot activate tags themselves.
Design a small, enforced tag schema
Teams often fail by inventing too many tags. A small schema that people follow beats a large one that nobody does. A good starting set is:
| Key | Purpose | Example values |
|---|---|---|
| `team` | Who answers for the spend | `checkout`, `search` |
| `env` | Lifecycle stage | `prod`, `staging`, `dev` |
| `product` | Which product or service the resource supports | `web-store`, `mobile-api` |
| `cost-center` | Finance mapping | `cc-4120` |
Some rules keep the data usable:
- Tag keys and values are case-sensitive.
Team=Checkoutandteam=checkoutare different tags, and your report will show them as separate rows. Pick one convention, such as lowercase with hyphens, and write it down. - Use a controlled list of values. Free-text values produce
prod,Prod,production, andprd. AWS Organizations tag policies can define allowed keys, capitalization, and values. - Do not put secrets or personal data in tags. Tags are visible in many places, including billing reports.
- Avoid the
aws:prefix. It is reserved for AWS. AWS-generated tags such asaws:createdBymust be activated separately, and you cannot edit them. - Know the limits. A resource can have up to 50 user-defined tags. Keys can be up to 128 characters, and values up to 256.
Apply tags when you create resources
Tagging at creation is more reliable than tagging afterward, because there is no window where the resource is untagged. Many create calls accept tags directly. For EC2, use --tag-specifications:
aws ec2 run-instances \
--image-id ami-0123456789abcdef0 \
--instance-type t3.micro \
--tag-specifications 'ResourceType=instance,Tags=[{Key=team,Value=checkout},{Key=env,Value=dev}]' 'ResourceType=volume,Tags=[{Key=team,Value=checkout},{Key=env,Value=dev}]'Note the second specification. Tags on an instance do not automatically copy to its attached EBS volumes at launch, so tag the volume too. Volumes are a frequent source of untagged spend.
Infrastructure as code is a better long-term answer than CLI calls. In Terraform, the AWS provider's default_tags block applies a standard set of tags to every resource it creates. In CloudFormation, stack-level tags propagate to supported resources. Both mean developers do not need to remember tags on each resource.
To fix existing resources, use the Resource Groups Tagging API, which works across many services:
aws resourcegroupstaggingapi tag-resources \
--resource-arn-list arn:aws:s3:::my-example-bucket \
--tags team=checkout,env=prodPrevent untagged resources
Tags applied by convention decay over time. To enforce them, you can deny creation of a resource unless the tag is present. This service control policy (SCP) blocks ec2:RunInstances when the team tag is missing from the request:
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "DenyInstanceWithoutTeamTag",
"Effect": "Deny",
"Action": "ec2:RunInstances",
"Resource": "arn:aws:ec2:*:*:instance/*",
"Condition": {
"Null": { "aws:RequestTag/team": "true" }
}
}
]
}The Null condition is true when the key is absent from the request, so the deny fires only for untagged launches.
Report spend by tag
Once a key is active and has collected data, group by it in Cost Explorer. The console works, and so does the CLI:
aws ce get-cost-and-usage \
--region us-east-1 \
--time-period Start=2026-10-01,End=2026-11-01 \
--granularity MONTHLY \
--metrics UnblendedCost \
--group-by Type=TAG,Key=teamEach group key comes back in the form team$checkout. Spend with no team tag appears under the key team$, with an empty value after the dollar sign. That row is your untagged remainder. Track it as a percentage of total spend. It is the most useful measure of how well your tagging works. A common target is under 5 to 10 percent for tagged-capable services.
To find resources missing a tag in one region, filter the Tagging API output with a JMESPath query:
aws resourcegroupstaggingapi get-resources \
--region eu-west-1 \
--query 'ResourceTagMappingList[?length(Tags[?Key==`team`]) == `0`].ResourceARN' \
--output textThis has a caveat. The API returns resources that are tagged now or were tagged in the past. A resource that has never had a tag may not be listed. Use AWS Config's required-tags rule or Tag Editor to find those.
What tags cannot cover
Tags have limits that no schema removes:
- Some charges cannot be tagged. Support fees, taxes, and some data transfer charges have no resource to tag. Many credits and refunds behave the same way.
- Shared resources have several owners. A shared Kubernetes cluster, a NAT gateway, or a central logging bucket serves many teams. A tag on the resource names only one owner.
- Tags describe intent, not usage. A tag says who is responsible, and does not measure who used the resource.
For shared costs, pick an explicit rule and apply it consistently. Common rules are an even split, a split proportional to each team's direct spend, or a split by a usage metric such as requests or CPU hours. AWS Cost Categories supports split charge rules for this purpose. For Amazon EKS, container-level tools can allocate node cost by pod resource requests. Whichever rule you choose, publish it. Teams accept a fair-looking rule they understand more readily than a clever one they do not.
Common errors
- Tags exist but the report shows nothing. The key was never activated, or fewer than 24 hours have passed since activation.
- The same team appears as several rows. Capitalization or spelling varies. Fix the values with a tag policy and retag the old resources.
- Old months still show as untagged. Activation is not retroactive. Cost Explorer can backfill allocation tags for up to 12 months in some configurations, but you should confirm this in the current console before relying on it.
- New resources are untagged even though the policy exists. The resource was created by a service that did not pass tags. Check the creating service's tag-propagation settings.
Exercise
Your team tagged all EC2 instances with Team=search last week, but Cost Explorer shows no spend grouped under a team tag. Name two likely causes and one fix for each.
Show answer
First, the tag key was never activated as a cost allocation tag, so it is not in the billing data. Fix: activate it with aws ce update-cost-allocation-tags-status from the management account, then wait up to 24 hours. Second, the key is capitalized differently. Tag keys are case-sensitive, so Team is a different key from team, and the key you are grouping by does not match the key on the resources. Fix: activate and group by Team, or retag the resources to the agreed lowercase team and enforce it with a tag policy.