Sub topic 6
Tags on AWS resources
This chapter assumes you know the AWS Management Console, what an AWS account is, and common services such as EC2, S3 and RDS. The CLI example is optional.
What a tag is
A tag is a key-value pair attached to an AWS resource. Cost Explorer can later group spend by tag keys, so tags are how you tie a bill to a project, team or environment.
Here are three example tags on one EC2 instance:
| Key | Value |
|---|---|
| Project | checkout |
| Environment | prod |
| Owner | payments-team |
The key names the dimension, such as Project. The value says which member of that dimension the resource belongs to, such as checkout.
Rules to know
These limits apply to most resources. Check the documentation for your service, because some differ.
- Keys and values are case sensitive.
Projectandprojectare different keys, andProdandprodare different values. - A resource can have up to 50 user-defined tags, and each key can appear only once per resource.
- A key can be up to 128 characters. A value can be up to 256 characters, and it can be empty.
- Keys that start with
aws:are reserved for AWS. You cannot create or edit them. - Tags attach to individual resources, not to accounts. Child resources do not inherit tags from a parent. For example, an EBS volume does not copy the tags of the instance it is attached to.
Adding tags
In the console, open the resource, find its Tags section, and choose Manage tags. You can also set tags when you create a resource. Tagging at creation is better, because spend is attributed from the start.
From the CLI, create-tags adds tags to an EC2 instance:
aws ec2 create-tags \
--resources i-0123456789abcdef0 \
--tags Key=Project,Value=checkout Key=Environment,Value=prodIf a key already exists on the resource, this command replaces its value. Other services have their own tagging commands. For S3 buckets it is aws s3api put-bucket-tagging, and many services support the generic aws resourcegroupstaggingapi tag-resources.
Tags do not change the bill by themselves
A tag on a resource is not enough to see it in Cost Explorer. The tag key must also be activated as a cost allocation tag, which is covered in a later chapter. Activation also is not retroactive. Usage from before activation is not grouped by that tag.
Not every resource type supports tags, and some charges, such as data transfer or support fees, cannot be tagged at all. This is one reason some spend always appears as untagged.
Common errors
- Inconsistent spelling or capitalization of keys and values.
- Tagging only the instance and forgetting its volumes, snapshots and load balancers.
- Assuming a tag set today explains last month's costs.
- Putting sensitive data in tags. Tags are visible to many services and users, so do not store secrets in them.
Exercise
A team tags an EC2 instance with project=checkout, while another team uses Project=checkout on its instances. Why is this a problem for cost reports, and what is the fix?
Show answer
Tag keys are case sensitive, so project and Project are two different keys. Cost Explorer treats them as separate tags, and each must be activated separately, so spend for the same project is split. The fix is to agree on one spelling, such as Project, retag the resources that use the other form, and activate only the agreed key.
Exercise
You tag an existing EBS volume today and activate the tag key today. Will last month's cost for that volume appear under the tag in Cost Explorer?
Show answer
No. Cost allocation tags are not applied retroactively, so only usage after activation carries the tag.