

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

# 标记域（Amazon SDKs）
<a name="managedomains-awsresourcetagging-sdk"></a>

 Amazon SDKs （Android 和 iOS 除外 SDKs）支持《[亚马逊 OpenSearch 服务 API 参考](https://docs.amazonaws.cn/opensearch-service/latest/APIReference/Welcome.html)》中定义的所有操作，包括`AddTags``ListTags`、和`RemoveTags`操作。有关安装和使用的更多信息 Amazon SDKs，请参阅[Amazon 软件开发套件](https://www.amazonaws.cn/code)。

## **Python**
<a name="pythonsample"></a>

此示例使用适用于 Python 的 Amazon 开发工具包 (Boto) 中的[OpenSearchService](https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/opensearch.html)低级 Python 客户端向域添加标签，列出附加到该域的标签，并从域中移除标签。必须提供 `DOMAIN_ARN`、`TAG_KEY` 和 `TAG_VALUE` 的值。

```
import boto3
from botocore.config import Config  # import configuration

DOMAIN_ARN = ''  # ARN for the domain. i.e "arn:aws:es:us-east-1:123456789012:domain/my-domain
TAG_KEY = ''  # The name of the tag key. i.e 'Smileyface'
TAG_VALUE = ''  # The value assigned to the tag. i.e 'Practicetag'

# defines the configurations parameters such as region

my_config = Config(region_name='us-east-1')
client = boto3.client('opensearch', config=my_config)


# defines the client variable

def addTags():
    """Adds tags to the domain"""

    response = client.add_tags(ARN=DOMAIN_ARN,
                               TagList=[{'Key': TAG_KEY,
                                         'Value': TAG_VALUE}])

    print(response)


def listTags():
    """List tags that have been added to the domain"""

    response = client.list_tags(ARN=DOMAIN_ARN)
    print(response)


def removeTags():
    """Remove tags that have been added to the domain"""

    response = client.remove_tags(ARN=DOMAIN_ARN, TagKeys=[TAG_KEY])

    print('Tag removed')
    return response
```