

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# 標記您的 Amazon CloudWatch 資源
<a name="CloudWatch-Tagging"></a>

 *標籤*是一種自訂屬性標籤，可由您或 AWS 指派給 AWS 資源。

 標籤可協助您執行以下操作：
+  識別和組織您的 AWS 資源。許多 AWS 服務支援標記功能。可以對來自不同服務的資源指派相同的標籤，指出資源是相關的。例如，可以將指派給 CloudWatch 規則的標籤指派給 EC2 執行個體。

 標籤分兩個部分：
+  *標籤鍵* (例如，`CostCenter`、`Environment` 或 `Project`)。標籤鍵會區分大小寫。
+  選用欄位，稱為*標籤值* (例如 `111122223333` 或 `Production`)。忽略標籤值基本上等同於使用空字串。與標籤鍵相同，標籤值會區分大小寫。

 以下各節提供有關 CloudWatch 中標籤的詳細資訊。

## CloudWatch 中支援的資源
<a name="supported-resources"></a>

CloudWatch 中的下列資源支援標記：
+ 警示 – 您可以使用 [tag-resource](https://docs.aws.amazon.com/cli/latest/reference/cloudwatch/tag-resource.html) AWS CLI 命令和 [TagResource](https://docs.aws.amazon.com/AmazonCloudWatch/latest/APIReference/API_TagResource.html) API 來標記警示。您也可以使用 CloudWatch 主控台中的*警示*詳細資訊頁面，檢視和管理警示標籤。
+ Canary – 您可使用 CloudWatch 主控台標記 Canary。如需更多詳細資訊，請參閱 [建立 Canary](CloudWatch_Synthetics_Canaries_Create.md)。
+ Contributor Insights 規則 – 您可在建立時使用 [put-insight-rule](https://docs.aws.amazon.com/cli/latest/reference/cloudwatch/put-insight-rule.html) AWS CLI 命令和 [PutInsightRule](https://docs.aws.amazon.com/AmazonCloudWatch/latest/APIReference/API_PutInsightRule.html) API 來標記 Contributor Insights 規則。您可使用 [tag-resource](https://docs.aws.amazon.com/cli/latest/reference/cloudwatch/tag-resource.html) AWS CLI 命令和 [TagResource](https://docs.aws.amazon.com/AmazonCloudWatch/latest/APIReference/API_TagResource.html) API，將標記新增至現有規則。
+ 指標串流 – 您可以在建立指標串流時使用 [put-metric-stream](https://docs.aws.amazon.com/cli/latest/reference/cloudwatch/put-metric-stream.html) AWS CLI 命令和 [PutMetricStream](https://docs.aws.amazon.com/AmazonCloudWatch/latest/APIReference/API_PutMetricStream.html) API 對其進行標記。您可使用 [tag-resource](https://docs.aws.amazon.com/cli/latest/reference/cloudwatch/tag-resource.html) AWS CLI 命令和 [TagResource](https://docs.aws.amazon.com/AmazonCloudWatch/latest/APIReference/API_TagResource.html) API，將標記新增至現有指標串流。

如需新增和管理標籤的詳細資訊，請參閱[管理標籤](#CloudWatch-tagging-add-edit-delete)。

## 管理標籤
<a name="CloudWatch-tagging-add-edit-delete"></a>

標籤是由資源上的 `Key` 和 `Value` 屬性組成。您可以使用 CloudWatch 主控台、AWS CLI 或 CloudWatch API 來新增、編輯或刪除這些屬性的值。如需使用標籤的資訊，請參閱下列內容：
+ *Amazon CloudWatch API 參考*中的 [TagResource](https://docs.aws.amazon.com/AmazonCloudWatch/latest/APIReference/API_TagResource.html)、[UntagResource](https://docs.aws.amazon.com/AmazonCloudWatch/latest/APIReference/API_UntagResource.html) 及 [ListTagsForResource](https://docs.aws.amazon.com/AmazonCloudWatch/latest/APIReference/API_ListTagsForResource.html)
+ *Amazon CloudWatch CLI 參考*中的 [tag-resource](https://docs.aws.amazon.com/cli/latest/reference/cloudwatch/tag-resource.html)、[untag-resource](https://docs.aws.amazon.com/cli/latest/reference/cloudwatch/untag-resource.html) 及 [list-tags-for-resource](https://docs.aws.amazon.com/cli/latest/reference/cloudwatch/list-tags-for-resource.html)
+ *《Resource Groups 使用者指南》*中的[使用標籤編輯器](https://docs.aws.amazon.com/ARG/latest/userguide/tag-editor.html)

## 標籤命名和使用慣例
<a name="tagging-restrictions"></a>

下列基本命名和使用慣例適用於搭配 CloudWatch 資源使用標籤：
+ 每個資源的上限為 50 個標籤。
+ 對於每一個資源，每個標籤金鑰必須是唯一的，且每個標籤金鑰只能有一個值。
+ 最大標籤索引鍵長度為 128 個 UTF-8 形式的 Unicode 字元。
+ 最大標籤值長度為 256 個 UTF-8 形式的 Unicode 字元。
+ 允許的字元包括可用 UTF-8 表示的英文字母、數字、空格，還有以下特殊字元：***. : \+ = @ \_ / -*** (連字號)。
+ 標籤鍵與值皆區分大小寫。做為最佳實務，請決定大寫標籤的策略，並一致地在所有資源類型中實作該策略。例如，決定要使用 `Costcenter`、`costcenter` 還是 `CostCenter`，並針對所有標籤使用相同的慣例。避免針對相似的標籤使用不一致的大小寫處理。
+ 標籤禁止使用 `aws:` 前綴，因為它會保留給 AWS 使用。您不可編輯或刪除具此字首的標籤金鑰或值。具此字首的標籤，不算在受資源限制的標籤計數內。