AWS Tags


1. Why Tags Matter#

AWS tags 不是装饰字段。它们是资源治理、成本归属、权限控制、自动化和监控发现的基础 metadata。

Name:
    human-readable label
    good for console display

Tags:
    structured metadata
    used by billing, IAM, automation, inventory, dashboards, alert routing, backup, cleanup

Practical rule:

do not parse resource name for important metadata
put stable metadata in tags

2. Main Use Cases#

Use Case How Tags Are Used Example
Resource search filter resources by project / service / env find all Service=order-api resources
Cost allocation split AWS cost by business dimension CostCenter=fin-001, Environment=prod
IAM / ABAC allow or deny actions based on resource/request/principal tags only operate resources with Environment=dev
Automation select resources for jobs, cleanup, backup, patching delete expired sandbox resources by ExpiresOn
Monitoring discovery exporters discover tagged resources YACE auto discovery for DynamoDB / SQS / RDS
Dashboard grouping build Grafana filters and folders around service/env Service=checkout, Environment=prod
Alert routing route alarms to owning team / runbook Team=platform, Criticality=p0
Governance detect or standardize required tags Organizations tag policies, AWS Config
Security context describe data sensitivity and compliance scope DataClass=pii, Compliance=pci
Ownership make accountable owner clear Owner=platform, ManagedBy=terraform

Minimum tags for most resources:

Tag Example Why
Name prod-order-api-alb readable in console and alerts
Project commerce product / workload boundary
Service order-api dashboard, alert and ownership grouping
Environment prod dev / uat / prod filtering
ManagedBy terraform identify automation owner

Production tags:

Tag Example Why
Owner platform accountable owner
Team checkout-platform alert routing
CostCenter fin-042 billing reports
Criticality p0 / p1 / p2 incident priority
DataClass public / internal / pii security and compliance
BackupPolicy daily-35d backup automation
RunbookUrl https://docs.example.com/runbooks/order-api incident response
DashboardUrl https://grafana.example.com/d/order-api incident response

Temporary / sandbox tags:

Tag Example Why
ExpiresOn 2026-07-01 cleanup automation
Purpose load-test explain why it exists
CreatedBy alice owner for temporary resources

Do not put these in tags:

secrets
tokens
passwords
customer PII
raw ticket comments
high-cardinality values such as request id or timestamp

4. Monitoring Discovery#

YACE auto discovery is a concrete example of why tags must exist before monitoring is built.

YACE discovery:
    uses AWS Resource Groups Tagging API to find tagged resources
    then queries CloudWatch metrics for those resources

if resource has no tag:
    discovery may not find it

if searchTags do not match:
    resource is filtered out

Common YACE error:

No tagged resources made it through filtering

Meaning:

YACE queried the namespace and region,
but no tagged resource matched the discovery filter.

Example:

discovery:
  jobs:
    - type: AWS/DynamoDB
      regions:
        - ap-northeast-1
      customTags:
        - key: environment
          value: uat
      searchTags:
        - key: Service
          value: order-api
        - key: Environment
          value: prod

Rules:

searchTags key is case-sensitive:
    Environment != environment

searchTags value is regex:
    prod|staging matches prod or staging

Tags As Metric Labels#

searchTags 只负责发现和过滤资源。AWS tags 在 YACE 输出中通常会以 tag_<TagKey> label 的形式出现,具体出现在哪些 metrics 上取决于 YACE 版本和配置。

Practical rule:

searchTags:
    controls which AWS resources are discovered

tag_* labels:
    tags exported by YACE, for example tag_Env="uat"

exportedTagsOnMetrics:
    explicitly controls which AWS tags are attached to normal CloudWatch metrics
    use it when dashboards / alerts depend on these labels

customTags:
    adds static labels to metrics collected by this YACE job
    for example custom_tag_environment="uat"

Relationship:

Setting Controls Does Not Control
searchTags which AWS resources enter YACE discovery whether tags appear as metric labels
exportedTagsOnMetrics which AWS tags are attached to exported CloudWatch metrics whether a resource is discovered
customTags static labels added by YACE config, exported as custom_tag_* labels resource discovery or AWS resource tags

Mental model:

searchTags:
    input filter
    decides resource in / out

exportedTagsOnMetrics:
    output label control
    decides which resource tags appear as tag_* labels on metrics

customTags:
    static output label
    adds config-defined labels such as custom_tag_environment="uat"

AWS resource tags:

AWS Tag Key AWS Tag Value
Env uat
ManagedBy Terraform
Service order-api

YACE config for explicit tag labels on metrics:

apiVersion: v1alpha1
sts-region: ap-northeast-1
discovery:
  exportedTagsOnMetrics:
    AWS/DynamoDB:
      - Env
      - ManagedBy
      - Service
  jobs:
    - type: AWS/DynamoDB
      regions:
        - ap-northeast-1
      customTags:
        - key: environment
          value: uat
      searchTags:
        - key: Env
          value: uat
      metrics:
        - name: ConsumedReadCapacityUnits
          statistics: [Sum]
          period: 300
          length: 600

Resulting metric labels may look like:

tag_Env="uat"
tag_ManagedBy="Terraform"
tag_Service="order-api"
custom_tag_environment="uat"

Example PromQL:

sum by (dimension_TableName, tag_Env, tag_ManagedBy, custom_tag_environment) (
  aws_dynamodb_consumed_read_capacity_units_sum{
    tag_Env="uat",
    tag_ManagedBy="Terraform",
    custom_tag_environment="uat"
  }
)

Notes:

exportedTagsOnMetrics:
    not the same thing as searchTags
    makes tag labels predictable on metrics used by dashboards / alerts

customTags:
    not read from AWS resources
    useful when one YACE job has a known static context
    key: environment is exported as custom_tag_environment="uat"

Grafana filters:
    can use tag_Env / tag_Service / tag_ManagedBy / custom_tag_environment only if those labels exist in the queried metrics

If the AWS resource has no tags:

YACE Mode Does Metric Collection Work? Does exportedTagsOnMetrics Help? Does customTags Help?
discovery Usually no. Auto-discovery is based on tagged resources. No. It does not make untagged resources discoverable. No. It only adds labels after metrics are collected.
discovery with searchTags No. There are no tags to match. No. No.
static/manual resource config Metrics can work if the resource is explicitly configured. It cannot export tags that do not exist. Yes. It can add static labels such as custom_tag_environment="uat".

Conclusion:

exportedTagsOnMetrics is not a replacement for AWS resource tags.
customTags is not a replacement for discovery tags.
For YACE discovery, add tags when creating the AWS resource.
For Grafana tag filters, verify the tag_* labels exist on the actual metrics.

Check where the tag labels exist:

{__name__=~"aws_dynamodb_.*", tag_Env="uat"}
{__name__=~"aws_dynamodb_.*_info", tag_Env="uat"}

Verify discovery input:

aws resourcegroupstaggingapi get-resources \
  --region ap-northeast-1 \
  --resource-type-filters dynamodb:table

5. Cost Allocation#

Tags only become useful for cost reporting after they are activated as cost allocation tags.

Recommended cost dimensions:

Project
Service
Environment
CostCenter
Team

Notes:

activate cost allocation tags in Billing
new tags may need time before they appear in cost reports
tag historical coverage matters; missing tags create unallocated cost

Good reports:

cost by Project
cost by Environment
cost by Service inside prod
shared platform cost by Stack or Team

6. IAM And ABAC#

ABAC means Attribute-Based Access Control. In AWS this often means IAM policies use tags as attributes.

Common condition keys:

Condition Key Meaning
aws:ResourceTag/<TagKey> tag on existing resource
aws:RequestTag/<TagKey> tag requested during create/update
aws:TagKeys tag keys included in the request
aws:PrincipalTag/<TagKey> tag on IAM principal or session

Example intent:

developer can manage dev resources
only when resource tag Environment=dev
and create requests include Project and Environment tags

Use ABAC only after tag quality is stable:

inconsistent tags become inconsistent permissions
some AWS services have partial tag-on-create support
test deny policies before applying to prod OUs

7. Governance#

Use multiple layers. No single feature solves tag quality alone.

Layer Tool Purpose
Provisioning Terraform default_tags apply common tags by default
Organization standard AWS Organizations tag policies standardize keys and allowed values
Detection AWS Config required-tags find resources missing required tags
Prevention IAM / SCP conditions deny create without required tags where supported
Inventory Tag Editor / Resource Groups Tagging API search and audit tags
CI review Terraform plan checks catch missing tags before apply

Tag policies:

standardize spelling and allowed values
good for organization-wide consistency
do not grant IAM permissions

AWS Config required-tags:

detect resources missing required tags
useful for audit and remediation
not every AWS resource type is covered

SCP / IAM deny:

use carefully
can block resource creation if service does not support tag-on-create
roll out in dev first

8. Terraform Pattern#

Keep common tags in one local value and apply them through provider default_tags.

locals {
  common_tags = {
    Project     = "commerce"
    Service     = "order-api"
    Environment = "prod"
    ManagedBy   = "terraform"
    Owner       = "platform"
    Team        = "checkout-platform"
    CostCenter  = "fin-042"
    Criticality = "p1"
  }
}

provider "aws" {
  region = "ap-northeast-1"

  default_tags {
    tags = local.common_tags
  }
}

Add resource-specific tags only when they help filtering or automation:

tags = {
  Name         = "prod-order-events"
  MessageType  = "domain-event"
  Producer     = "order-api"
  Consumer     = "order-worker"
}

9. Practical Standard#

For production, start with this:

required:
    Name
    Project
    Service
    Environment
    ManagedBy

recommended:
    Owner
    Team
    CostCenter
    Criticality

conditional:
    DataClass
    BackupPolicy
    RunbookUrl
    DashboardUrl
    ExpiresOn

Checklist:

new AWS resource:
    has standard tags at creation time
    has Service and Environment for monitoring discovery
    has CostCenter if cost allocation matters
    has Owner or Team for incident routing
    has ManagedBy to distinguish Terraform/manual resources

new monitoring dashboard:
    can group by Service and Environment
    can filter discovered AWS resources by tags
    does not depend on parsing Name

new IAM/ABAC policy:
    uses only stable and enforced tags
    tests service tag-on-create behavior first