

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

# 標記網域 (AWS SDKs)
<a name="managedomains-awsresourcetagging-sdk"></a>

 AWS SDKs(Android 和 iOS SDKs除外） 支援 [Amazon OpenSearch Service API 參考](https://docs.aws.amazon.com/opensearch-service/latest/APIReference/Welcome.html)中定義的所有動作，包括 `AddTags`、 `ListTags`和 `RemoveTags`操作。如需安裝和使用 AWS SDKs 的詳細資訊，請參閱[AWS 軟體開發套件](https://aws.amazon.com/code)。

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

此範例使用適用於 Python (Boto) 的 AWS SDK 中的 [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
```