

# 标记分配
<a name="tagging"></a>

标签是可用于标识和组织 Amazon 资源的词或短语。您可以向每个资源添加多个标签，并且每个标签都包含您定义的一个键和一个值。例如，键可能是“domain”，值可能是“example.com”。您可以根据添加的标签搜索和筛选您的资源。

您可以在 CloudFront 中使用标签，例如以下示例：
+ 对 CloudFront 分配强制实施基于标签的权限。有关更多信息，请参阅 [ABAC 以及 CloudFront](security_iam_service-with-iam.md#security_iam_service-with-iam-tags)。
+ 跟踪不同类别的账单信息。在您将标签应用于 CloudFront 分配或其他 Amazon 资源（例如 Amazon EC2 实例或 Amazon S3 存储桶）并激活标签时，Amazon 将以逗号分隔值（CSV 文件）格式生成一份成本分配报告，其中包括按活动标签汇总的使用率和成本。

  您可以设置代表业务类别（例如成本中心、应用程序名称或所有者）的标签，以便整理多种服务的成本。有关对成本分配使用标签的更多信息，请参阅《Amazon Billing 用户指南》**中的[使用成本分配标签](https://docs.amazonaws.cn/awsaccountbilling/latest/aboutv2/cost-alloc-tags.html)。

**备注**  
您可以为分配添加标签，但不能为源访问身份或失效添加标签。
CloudFront 当前不支持[标签编辑器](https://docs.amazonaws.cn/ARG/latest/userguide/tag-editor.html)和[资源组](https://docs.amazonaws.cn/ARG/latest/userguide/resource-groups.html)。
有关可以向分配添加的最大标签数，请参阅[常规配额](cloudfront-limits.md#limits-general)。

**Contents**
+ [标签限制](#tagging-restrictions)
+ [为分配添加、编辑和删除标签](#tagging-add-edit-delete)
+ [编程标记](#tagging-related-information)

## 标签限制
<a name="tagging-restrictions"></a>

下面是适用于标签的基本限制：
+ 要了解每个分配的最大标签数，请参阅[常规配额](cloudfront-limits.md#limits-general)。
+ 最大密钥长度 – 128 个 Unicode 字符
+ 最大值长度 – 256 个 Unicode 字符
+ 键和值的有效值 – a-z、A-Z、0-9、空格和以下字符：\$1 . : / = \$1 - 和 @
+ 标签键和值区分大小写
+ 请不要使用 `aws:` 作为键的前缀。此前缀是专为 Amazon 使用而预留。

## 为分配添加、编辑和删除标签
<a name="tagging-add-edit-delete"></a>

您可以使用 CloudFront 控制台管理分配标签。<a name="tagging-add-edit-delete-procedure"></a>

**为分配添加、编辑或删除标签**

1. 登录 Amazon Web Services 管理控制台，并通过以下网址打开 CloudFront 控制台：[https://console.amazonaws.cn/cloudfront/v4/home](https://console.amazonaws.cn/cloudfront/v4/home)。

1. 为要更新的分配选择 ID。

1. 选择**标签**选项卡。

1. 选择**管理标签**。

1. 在 **Manage tags**（管理标签）页面上，可以执行以下操作：
   + 要添加标签，请输入该标签的键和（可选）值。要添加更多标签，请选择**添加新标签**。
   + 要编辑标签，请更改标签的键或值，或者同时更改两者。您可以删除标签的值，但键是必需的。
   + 要删除标签，请选择**删除**。

1. 选择**保存更改**。

## 编程标记
<a name="tagging-related-information"></a>

您也可以使用 CloudFront API、Amazon Command Line Interface（Amazon CLI）、Amazon SDK 和 Amazon Tools for Windows PowerShell 来应用标签。有关更多信息，请参阅以下主题：
+ CloudFront API 操作：
  + [ListTagsForResource](https://docs.amazonaws.cn/cloudfront/latest/APIReference/API_ListTagsForResource.html) 
  + [TagResource](https://docs.amazonaws.cn/cloudfront/latest/APIReference/API_TagResource.html) 
  + [UntagResource](https://docs.amazonaws.cn/cloudfront/latest/APIReference/API_UntagResource.html) 
+ Amazon CLI – 请参阅 *Amazon CLI 命令参考*中的 [cloudfront](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/cloudfront/index.html)
+ Amazon SDK – 请参阅 [Amazon 文档](https://docs.amazonaws.cn/index.html)页面上的适用 SDK 文档
+ Tools for Windows PowerShell – 请参阅 [Amazon Tools for PowerShell Cmdlet 参考](https://docs.amazonaws.cn/powershell/latest/reference/)中的 [Amazon CloudFront](https://docs.amazonaws.cn/powershell/latest/reference/items/CloudFront_cmdlets.html)。