

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

# 为 Amazon OpenSearch 无服务器集合加标签
<a name="tag-collection"></a>

标签允许您将任意信息分配给 Amazon OpenSearch Serverless 集合，这样您就可以对这些信息进行分类和筛选。*标签*是您分配或分配给 AWS 资源的元数据标签。 AWS 

每个标签均包含一个*键* 和一个*值*。对于您分配的标签，需要定义键和值。例如，您可以将键定义为 `stage`，将一个资源的值定义为 `test`。

使用标签，您可以识别和组织您的 AWS 资源。许多 AWS 服务都支持标记，因此您可以为来自不同服务的资源分配相同的标签，以表明这些资源是相关的。例如，您可以为分配给亚马逊 OpenSearch 服务域的 OpenSearch 无服务器集合分配相同的标签。

在 OpenSearch Serverless 中，主要资源是集合。您可以使用 OpenSearch 服务控制台、、 OpenSearch Serverless API 操作或在 AWS SDKs 集合中添加、管理和删除标签。 AWS CLI

## 所需权限
<a name="collection-tag-permissions"></a>

OpenSearch Serverless 使用以下 AWS Identity and Access Management Access Analyzer (IAM) 权限来标记集合：
+ `aoss:TagResource`
+ `aoss:ListTagsForResource`
+ `aoss:UntagResource`

# 标记集合（控制台）
<a name="tag-collection-console"></a>

控制台是标记集合的最简单方法。

****创建标签（控制台）****

1. 在[https://console.aws.amazon.com/aos/家](https://console.aws.amazon.com/aos/home )中登录亚马逊 OpenSearch 服务控制台。

1. 展开左侧导航窗格中的 **Serverless**（无服务器），然后选择 **Collections**（集合）。

1. 选择您要将标签添加到的集合，然后转到 **Tags**（标签）选项卡。

1. 选择 **Manage（管理）**和 **Add new tag（添加新标签）**。

1. 输入一个标签键和可选的值。

1. 选择**保存**。

要删除标签，请按照相同步骤操作并在 **Manage tags（管理标签）**页面中选择 **Remove（删除）**。

有关使用控制台处理标签的更多信息，请参阅《AWS 管理控制台入门指南》**中的[标签编辑器](https://docs.aws.amazon.com/awsconsolehelpdocs/latest/gsg/tag-editor.html)。

# 标记集合（AWS CLI）
<a name="tag-collection-cli"></a>

要使用为集合添加标签 AWS CLI，[TagResource](https://docs.aws.amazon.com/opensearch-service/latest/ServerlessAPIReference/API_TagResource.html)请发送请求：

```
aws opensearchserverless tag-resource
  --resource-arn arn:aws:aoss:us-east-1:123456789012:collection/my-collection 
  --tags Key=service,Value=aoss Key=source,Value=logs
```

使用[ListTagsForResource](https://docs.aws.amazon.com/opensearch-service/latest/ServerlessAPIReference/API_ListTagsForResource.html)以下命令查看集合的现有标签：

```
aws opensearchserverless list-tags-for-resource
  --resource-arn arn:aws:aoss:us-east-1:123456789012:collection/my-collection
```

使用[UntagResource](https://docs.aws.amazon.com/opensearch-service/latest/ServerlessAPIReference/API_UntagResource.html)以下命令从集合中移除标签：

```
aws opensearchserverless untag-resource
  --resource-arn arn:aws:aoss:us-east-1:123456789012:collection/my-collection
  --tag-keys service
```