Tagging Amazon OpenSearch Service domains - Amazon OpenSearch Service
Services or capabilities described in Amazon Web Services documentation might vary by Region. To see the differences applicable to the China Regions, see Getting Started with Amazon Web Services in China (PDF).

Tagging Amazon OpenSearch Service domains

Tags let you assign arbitrary information to an Amazon OpenSearch Service domain so you can categorize and filter on that information. A tag is a key-value pair that you define and associate with an OpenSearch Service domain. You can use these tags to track costs by grouping expenses for similarly tagged resources. Amazon doesn't apply any semantic meaning to your tags. Tags are interpreted strictly as character strings. All tags have the following elements:

Tag Element Description Required
Tag key

The tag key is the name of the tag. Key must be unique to the OpenSearch Service domain to which they're attached. For a list of basic restrictions on tag keys and values, see User-Defined Tag Restrictions.

Yes
Tag value

The tag value is the string value of the tag. Tag values can be null and don't have to be unique in a tag set. For example, you can have a key-value pair in a tag set of project/Trinity and cost-center/Trinity. For a list of basic restrictions on tag keys and values, see User-Defined Tag Restrictions.

No

Each OpenSearch Service domain has a tag set, which contains all the tags assigned to that OpenSearch Service domain. Amazon doesn't automatically assign any tags to OpenSearch Service domains. A tag set can contain between 0 and 50 tags. If you add a tag to a domain with the same key as an existing tag, the new value overwrites the old value.

Tagging examples

You can use a key to define a category, and the value could be an item in that category. For example, you could define a tag key of project and a tag value of Salix, indicating that the OpenSearch Service domain is assigned to the Salix project. You could also use tags to designate OpenSearch Service domains as being used for test or production by using a key such as environment=test or environment=production. Try to use a consistent set of tag keys to make it easier to track metadata that is associated with OpenSearch Service domains.

You also can use tags to organize your Amazon bill to reflect your own cost structure. To do this, sign up to get your Amazon Web Services account bill with tag key values included. Then, organize your billing information according to resources with the same tag key values to see the cost of combined resources. For example, you can tag several OpenSearch Service domains with key-value pairs, and then organize your billing information to see the total cost for each domain across several services. For more information, see Using Cost Allocation Tags in the Amazon Billing and Cost Management documentation.

Note

Tags are cached for authorization purposes. Because of this, additions and updates to tags on OpenSearch Service domains might take several minutes before they're available.

Working with tags (console)

The console is the simplest way to tag a domain.

To create a tag (console)
  1. Go to https://aws.amazon.com, and then choose Sign In to the Console.

  2. Under Analytics, choose Amazon OpenSearch Service.

  3. Select the domain you want to add tags to and go to the Tags tab.

  4. Choose Manage and Add new tag.

  5. Enter a tag key and an optional value.

  6. Choose Save.

To delete a tag, follow the same steps and choose Remove on the Manage tags page.

For more information about using the console to work with tags, see Tag Editor in the Amazon Management Console Getting Started Guide.

Working with tags (Amazon CLI)

You can create resource tags using the Amazon CLI with the --add-tags command.

Syntax

add-tags --arn=<domain_arn> --tag-list Key=<key>,Value=<value>

Parameter Description
--arn Amazon resource name for the OpenSearch Service domain to which the tag is attached.
--tag-list Set of space-separated key-value pairs in the following format: Key=<key>,Value=<value>

Example

The following example creates two tags for the logs domain:

aws opensearch add-tags --arn arn:aws:es:us-east-1:379931976431:domain/logs --tag-list Key=service,Value=OpenSearch Key=instances,Value=m3.2xlarge

You can remove tags from an OpenSearch Service domain using the --remove-tags command.

Syntax

remove-tags --arn=<domain_arn> --tag-keys Key=<key>,Value=<value>

Parameter Description
--arn Amazon Resource Name (ARN) for the OpenSearch Service domain to which the tag is attached.
--tag-keys Set of space-separated key-value pairs that you want to remove from the OpenSearch Service domain.

Example

The following example removes two tags from the logs domain that were created in the preceding example:

aws opensearch remove-tags --arn arn:aws:es:us-east-1:379931976431:domain/logs --tag-keys service instances

You can view the existing tags for an OpenSearch Service domain with the --list-tags command:

Syntax

list-tags --arn=<domain_arn>

Parameter Description
--arn Amazon Resource Name (ARN) for the OpenSearch Service domain to which the tags are attached.

Example

The following example lists all resource tags for the logs domain:

aws opensearch list-tags --arn arn:aws:es:us-east-1:379931976431:domain/logs

Working with tags (Amazon SDKs)

The Amazon SDKs (except the Android and iOS SDKs) support all the actions defined in the Amazon OpenSearch Service API Reference, including the AddTags, ListTags, and RemoveTags operations. For more information about installing and using the Amazon SDKs, see Amazon Software Development Kits.

Python

This example uses the OpenSearchService low-level Python client from the AWS SDK for Python (Boto) to add a tag to a domain, list the tag attached to the domain, and remove a tag from the domain. You must provide values for DOMAIN_ARN, TAG_KEY, and 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