

本文属于机器翻译版本。若本译文内容与英语原文存在差异，则一律以英文原文为准。

# AWS Organizations — 标签政策
<a name="aws-organizations-tag-policies"></a>

 中的策略 AWS Organizations 允许您在组织 AWS 账户 中应用其他类型的治理。[https://docs.aws.amazon.com/organizations/latest/userguide/orgs_manage_policies_tag-policies.html](https://docs.aws.amazon.com/organizations/latest/userguide/orgs_manage_policies_tag-policies.html)是您如何以 JSON 形式表达您的标记架构，以便平台可以在您的 AWS 环境中报告和选择性地强制执行该架构。标签策略定义了特定资源类型的标签密钥可接受的值。该策略可以采用值列表的形式，也可以采用前缀后加通配符 (`*`) 的形式。简单前缀法不如离散值列表严格，但维护要求较低。

 以下示例说明了如何定义标记策略来验证给定密钥可接受的值。根据架构的人性化表格定义，您可以将这些信息转录到一个或多个标签策略中。可以使用单独的策略来支持授权所有权，或者某些策略可能仅适用于特定场景。

## ExampleInc-CostAllocation .json
<a name="exampleinc-costallocation.json"></a>

 以下是报告成本分配标签的标签策略示例：

```
{
  "tags": {
    "example-inc:cost-allocation:ApplicationId": {
      "tag_key": {
        "@@assign": "example-inc:cost-allocation:ApplicationId"
      },
      "tag_value": {
        "@@assign": [
          "DataLakeX",
          "RetailSiteX"
        ]
      }
    },
    "example-inc:cost-allocation:BusinessUnitId": {
      "tag_key": {
        "@@assign": "example-inc:cost-allocation:BusinessUnitId"
      },
      "tag_value": {
        "@@assign": [
          "Architecture",
          "DevOps",
          "FinanceDataLakeX"
        ]
      }
    },
    "example-inc:cost-allocation:CostCenter": {
      "tag_key": {
        "@@assign": "example-inc:cost-allocation:CostCenter"
      },
      "tag_value": {
        "@@assign": [
          "123-*"
        ]
      }
    }
  }
}
```

## ExampleInc-DisasterRecovery .json
<a name="exampleinc-disasterrecovery.json"></a>

 以下是报告灾难恢复标签的标签策略示例：

```
{
    "tags": {
        "example-inc:disaster-recovery:rpo": {
            "tag_key": {
                "@@assign": "example-inc:disaster-recovery:rpo"
            },
            "tag_value": {
                "@@assign": [
                    "6h",
                    "24h"
                ]
            }
        }        
    }
}
```

 在此示例中，`ExampleInc-CostAllocation`标签策略附加到 `Workloads` OU，因此适用于`Prod`和`Test`子账号中的所有账户 OUs。同样，`ExampleInc-DisasterRecovery` 标签策略附加到 `Prod` OU，因此仅适用于该 OU 以下的账户。[使用多个账户组织环境](https://docs.aws.amazon.com/whitepapers/latest/organizing-your-aws-environment/organizing-your-aws-environment.html)白皮书更详细地探讨了推荐的 OU 结构。

![\[该图显示了将标签策略附加到 OU 结构和有效策略\]](http://docs.aws.amazon.com/zh_cn/whitepapers/latest/tagging-best-practices/images/adding-tagging-to-policies-in-ou-structure.png)


 查看图中的 `marketing-prod` 账户，两个标签策略都适用于该账户，因此我们就有了*有效策略*的概念，即适用于账户的特定类型的策略的卷积。如果您主要是手动管理资源，则可以通过访问控制台中的[资源组和标签编辑器：标签策略](https://console.aws.amazon.com/resource-groups/tag-policies)来查看有效策略。如果您使用基础设施即代码 (IaC) 或脚本来管理资源，则可以使用 [https://docs.aws.amazon.com/organizations/latest/APIReference/API_DescribeEffectivePolicy.html](https://docs.aws.amazon.com/organizations/latest/APIReference/API_DescribeEffectivePolicy.html) API 调用。