

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

# 標記您的 AWS IoT Greengrass Version 2 資源
<a name="tag-resources"></a>

使用標籤，您可以在 AWS IoT Greengrass中組織和管理您的資源。您可以使用標籤將中繼資料指派給資源，也可以在 IAM 政策中使用標籤來定義對資源的條件式存取。

**注意**  
目前， AWS IoT 帳單群組或成本分配報告不支援 Greengrass 資源標籤。

## 在 中使用標籤 AWS IoT Greengrass V2
<a name="tag-basics"></a>

您可以使用標籤， AWS IoT Greengrass 依用途、擁有者、環境或任何其他使用案例的分類來分類資源。當您有許多相同類型的資源時，標籤可協助您更輕鬆地識別特定資源。

每個標籤皆包含由您定義的一個金鑰與一個選用值。例如，您可以為核心裝置定義一組標籤，協助您由擁有裝置的客戶追蹤它們。我們建議您為每種資源類型建立符合您需求的一組標籤金鑰。使用一致的標籤鍵組，可讓您的資源管理更輕鬆。

### 使用 標記 AWS 管理主控台
<a name="use-tag-console"></a>

中的**標籤編輯器** AWS 管理主控台 提供集中、統一的方式，讓您為來自所有 AWS 服務的資源建立和管理標籤。如需詳細資訊，請參閱*AWS Resource Groups 《 使用者指南*》中的[標籤編輯器](https://docs.aws.amazon.com/ARG/latest/userguide/tag-editor.html)。

### 使用 AWS IoT Greengrass V2 API 標記
<a name="use-tag-api"></a>

您也可以使用 AWS IoT Greengrass V2 API 來處理標籤。在建立標籤之前，請注意下列標籤限制。如需詳細資訊，請參閱《》中的[標籤命名和使用慣例](https://docs.aws.amazon.com/general/latest/gr/aws_tagging.html#tag-conventions)*AWS 一般參考*。
+ 若要在建立資源時新增標籤，請在資源的 `tags` 屬性中定義標籤。
+ 若要將標籤新增至現有資源或更新標籤值，請使用 [TagResource](https://docs.aws.amazon.com/greengrass/v2/APIReference/API_TagResource.html) 操作。
+ 若要從資源移除標籤，請使用 [UntagResource](https://docs.aws.amazon.com/greengrass/v2/APIReference/API_UntagResource.html) 操作。
+ 若要擷取與資源建立關聯的標籤，請使用 [ListTagsForResource](https://docs.aws.amazon.com/greengrass/v2/APIReference/API_ListTagsForResource.html) 操作，或描述資源並檢查其 `tags` 屬性。

下表列出您可以使用 AWS IoT Greengrass V2 API 及其對應的 `Create` 和 `Describe`或 `Get`操作來標記的資源。


**可標記 AWS IoT Greengrass V2 的資源**  

| 資源 | 建立操作 | 描述或取得操作 | 
| --- | --- | --- | 
| 核心裝置 |  無。在裝置上執行 AWS IoT Greengrass Core 軟體以建立核心裝置。  |  [GetCoreDevice](https://docs.aws.amazon.com/greengrass/v2/APIReference/API_GetCoreDevice.html)  | 
| 元件 |  [CreateComponentVersion](https://docs.aws.amazon.com/greengrass/v2/APIReference/API_CreateComponentVersion.html)  |  [DescribeComponent](https://docs.aws.amazon.com/greengrass/v2/APIReference/API_DescribeComponent.html)、[GetComponent](https://docs.aws.amazon.com/greengrass/v2/APIReference/API_GetComponent.html)  | 
| 部署 |  [CreateDeployment](https://docs.aws.amazon.com/greengrass/v2/APIReference/API_CreateDeployment.html)  |  [GetDeployment](https://docs.aws.amazon.com/greengrass/v2/APIReference/API_GetDeployment.html)  | 

使用下列操作檢視並管理支援標記之資源的標籤：
+ [TagResource](https://docs.aws.amazon.com/greengrass/v2/APIReference/API_TagResource.html) – 將標籤新增至資源，或更新現有標籤的值。
+ [ListTagsForResource](https://docs.aws.amazon.com/greengrass/v2/APIReference/API_ListTagsForResource.html) – 列出資源的標籤。
+ [UntagResource](https://docs.aws.amazon.com/greengrass/v2/APIReference/API_UntagResource.html) – 從資源移除標籤。

您可以隨時新增或移除資源的標籤。若要變更標籤金鑰的值，請在資源加入定義相同金鑰和新數值的標籤。新值會取代先前的值。您可以將數值設為空白字串，但您無法將數值設為 null。

在您刪除資源時，也會刪除與該資源建立關聯的標籤。

## 搭配 IAM 政策使用標籤
<a name="tags-iam"></a>

在您的 IAM 政策中，您可以使用資源標籤來控制使用者存取和許可。例如，政策可讓使用者僅能建立具有特定標籤的資源。政策也可以限制使用者建立或修改具有特定標籤的資源。

**注意**  
如果您使用標籤來允許或拒絕使用者存取資源，您應該拒絕使用者為相同資源新增或移除這些標籤的能力。否則，使用者可能透過修改標籤來避開您的限制，並取得資源的存取。

您可以在政策陳述式的 `Condition`元素中使用下列條件內容索引鍵和值，也稱為 `Condition`區塊。

`greengrassv2:ResourceTag/tag-key: tag-value`  
允許或拒絕資源對具有特定標籤之資源的動作。

`aws:RequestTag/tag-key: tag-value`  
建立或修改可標記資源時，需要使用或不使用特定標籤。

`aws:TagKeys: [tag-key, ...]`  
建立或修改可標記資源時，需要使用或不使用一組特定的標籤金鑰。

**注意**  
IAM 政策中的條件內容索引鍵和值僅適用於具有可標記資源作為必要參數的動作。例如，您可以為 [GetComponent](https://docs.aws.amazon.com/greengrass/v2/APIReference/API_GetComponent.html) 設定標籤型條件式存取。

如需詳細資訊，請參閱《IAM *使用者指南*》中的[使用 AWS 資源標籤和 IAM JSON 政策參考控制對資源的存取](https://docs.aws.amazon.com/IAM/latest/UserGuide/access_tags.html)。 [https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies.html](https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies.html)