AWS / FinOps

AWS cost allocation tags: a tagging strategy that works

Most tagging projects start with a long spreadsheet of keys and end with half the bill marked untagged. A short tag set, activated early and enforced at creation time, does more than a long one that nobody applies.

Two kinds of cost allocation tags

A tag is a key and a value attached to a resource. A cost allocation tag is a tag key that you have activated for billing, so that Cost Explorer and the cost reports can group spend by it. AWS describes two types, and both must be activated separately before they appear in cost data.

User-defined tags are the ones you create, such as environment or cost-center. In the cost allocation report their keys carry a user: prefix.

AWS-generated tags carry the reserved aws: prefix. The main one is aws:createdBy, which records the account, user or role that created a resource. It is applied only to resources created after you activate it, only for a listed set of services, API calls and Regions, and on a best-effort basis. It is visible only in Billing and Cost Management, not in Tag Editor. It helps with attribution of forgotten resources, but it does not replace your own tags.

Activate early, because activation is not retroactive

In an AWS Organization, only the management account can open the cost allocation tags page and activate tag keys. Activation works per key: activating environment covers every value of that key. The UpdateCostAllocationTagsStatus API can activate keys in bulk.

The delays add up. After you apply a new tag, it can take up to 24 hours for the key to appear on the page, then up to 24 hours more for it to become active.

Cost data before activation stays unallocated unless you request a backfill. The management account can backfill up to twelve months, one request every 24 hours. A backfill only helps for periods when the tag was actually on the resource. Tag first, activate the same week, and you avoid the gap.

One more trap: when an account moves to another organization, its previously activated tags lose their active status and the new management account must activate them again.

A minimal tag set

Four keys answer most cost questions: which environment, who owns it, who pays for it, and what it belongs to.

KeyValuesUsed for
environmentproduction, staging, development, testShowback by environment, scheduling, production exclusion
ownerA team alias, not a person's e-mailWho to ask before a change or deletion
cost-centerThe finance code, for example cc-1042Chargeback and budget ownership
applicationcheckout, search, data-platformCost per product or service

Keep values in a closed list. A free-text environment tag soon contains prod, Prod, production and live, and each one becomes a separate line in Cost Explorer. Do not put personal or confidential data in tags; AWS warns that many services, including billing, can read them.

Naming conventions and case sensitivity

Tag keys and values are case sensitive. Environment and environment are two different keys, so a mixed estate splits its own costs in two. AWS's tagging best practices suggest lowercase words separated by hyphens, optionally with an organization prefix such as anycompany:cost-center.

The basic limits are the same for all of them:

  • Up to 50 user-created tags per resource. Tags starting with aws: are reserved and do not count.
  • Keys of 1 to 128 characters, values of 0 to 256 characters.
  • One value per key on each resource.
  • Allowed characters vary by service. Letters, numbers, spaces and _ . : / = + - @ are generally safe.

Pick one convention, write it down, and fix existing variants before you activate the keys for billing.

Enforce tags where resources are created

Cleaning up tags after the fact is slow. Three controls work at creation time, and each covers a different gap.

Tag policies in AWS Organizations

Tag policies define the expected capitalization of a key and its allowed values. With enforced_for, noncompliant tagging operations on the listed resource types are refused. The report_required_tag_for field marks keys as required, which CloudFormation, Terraform and Pulumi can check at deployment time once you enable that validation.

{
  "tags": {
    "environment": {
      "tag_key": { "@@assign": "environment" },
      "tag_value": {
        "@@assign": ["production", "staging", "development", "test"]
      },
      "enforced_for": { "@@assign": ["ec2:ALL_SUPPORTED"] },
      "report_required_tag_for": {
        "@@assign": ["ec2:instance", "rds:db"]
      }
    }
  }
}

The limit matters: untagged resources and keys not defined in the policy are not evaluated for compliance. A tag policy keeps tags consistent; it does not, on its own, stop someone from launching an instance with no tags.

Service control policies

To block creation without a tag, AWS publishes an SCP example that denies the create action when aws:RequestTag/<key> is null. AWS notes that its example is not compatible with CloudFormation as written, because some resources are created and tagged in two separate steps. Test such a policy in one account first.

Default tags in infrastructure code

The Terraform AWS provider's default_tags block adds the same tags to every resource that supports them. A resource can override a value but cannot remove a provider tag. The read-only tags_all attribute shows the merged result. aws_autoscaling_group is the documented exception and needs its own tag blocks.

provider "aws" {
  default_tags {
    tags = {
      environment   = "staging"
      owner         = "orders-team"
      cost-center   = "cc-1042"
      application   = "checkout"
    }
  }
}
A staging RDS database with environment, owner, cost-center and application tags feeds both a showback chart grouped by environment and a schedule that stops staging at night while excluding production.
The same four tags split the bill by environment and tell automation what it may stop.

Find what is untagged

The Resource Groups Tagging API is the usual starting point, but its GetResources operation returns only resources that are tagged or were tagged before. A resource that never had a tag does not appear. It is still useful to list what carries a given value:

aws resourcegroupstaggingapi get-resources \
  --tag-filters Key=environment,Values=production,prod

For resources with no tags at all, AWS points to Resource Explorer and its tag:none filter. A leading - inverts a filter, so you can also list databases missing one key. The view you search must include tag data, and a query returns at most 1,000 resources.

aws resource-explorer-2 search \
  --query-string "resourcetype:ec2:instance tag:none"

aws resource-explorer-2 search \
  --query-string "resourcetype:rds:db -tag.key:environment"

Run these per Region, assign each result to an owner, and fix tags in the infrastructure code that created the resource, not only in the console.

Use Cost Categories for spend tags cannot reach

Some charges never carry a resource tag: support, tax, credits, or a shared networking account. Cost Categories map those costs with rules on account, service, Region, charge type, usage type, billing entity or cost allocation tag. An inherited-value rule can take its values straight from a tag key, and a default value catches whatever no rule matches.

A new or edited category applies from the start of the current month and can take up to 24 hours to process. Split charge rules can spread a shared cost across other values proportionally, by fixed percentages or evenly. Those split amounts appear only on the cost category details page, not in Cost Explorer or the Cost and Usage Report.

Showback by environment

Once environment is active, group Cost Explorer by that tag key. For a cleaner view, create an Environment cost category: inherit values from the environment tag, map dedicated non-production accounts by account ID, and send the rest to a default such as unallocated. Track the size of unallocated every month; it measures how well the tagging strategy is working.

The split also shows where savings are. Development and staging capacity that runs through nights and weekends is often the largest line that nobody uses. The development environment cost guide covers how to reduce it.

The same tag drives automation

An environment tag is not only a billing label. AWS lists automation, such as stopping development instances outside business hours, as a standard tagging use. A scheduler needs the same answer as finance: is this production or not?

SnoozeDB reads AWS tags during synchronization. A resource with an env, environment, snoozedb:env, snoozedb:environment, snoozedb:tag:env or snoozedb:tag:environment tag set to prod or production, in any capitalization, is protected and is not scheduled. The tag snoozedb:enabled=false excludes a single resource directly from AWS.

For other conventions, organization settings accept up to 20 custom key/value exclusion rules, such as tier=critical. These rules match the key and value exactly as written, including case, so a rule for Tier=Critical does not match tier=critical. That is one more reason to settle the naming convention first.

Owners and admins can also add and remove snoozedb:tag: classification tags on RDS databases, standalone EC2 instances, EKS clusters and managed node groups from the Tags page, and add snoozedb:env=production to protect a running resource. Other tags stay read-only. The resource management documentation describes exclusion tags and organization rules in detail.

A short rollout plan

  • Agree on four keys, lowercase, with closed value lists for environment.
  • Add them to default_tags or your CloudFormation templates.
  • Activate the keys in the management account the same week, and backfill if the tags already existed.
  • Attach a tag policy in report mode, then enforce it on the resource types you rely on.
  • Search for untagged resources monthly and route each one to an owner.
  • Use a cost category for the costs tags cannot reach.

Tags only describe resources; they do not reduce the bill by themselves. Their value comes from the decisions they make possible, including which environments can safely stop at night.