Configuring Amazon SNS topic tags - Amazon Simple Notification Service

Configuring Amazon SNS topic tags

This page shows how you can use the AWS Management Console, an AWS SDK, and the AWS CLI to configure tags for an Amazon SNS topic.

Important

Do not add personally identifiable information (PII) or other confidential or sensitive information in tags. Tags are accessible to other Amazon Web Services, including billing. Tags are not intended to be used for private or sensitive data.

Listing, adding, and removing tags for an Amazon SNS topic using the AWS Management Console

  1. Sign in to the Amazon SNS console.

  2. On the navigation panel, choose Topics.

  3. On the Topics page, choose a topic and then choose Edit.

  4. Expand the Tags section.

    The tags added to the topic are listed.

  5. Modify topic tags:

    • To add a tag, choose Add tag and enter a Key and Value (optional).

    • To remove a tag, choose Remove tag next to a key-value pair.

  6. Choose Save changes.

Adding tags to a topic using an AWS SDK

To use an AWS SDK, you must configure it with your credentials. For more information, see The shared config and credentials files in the AWS SDKs and Tools Reference Guide.

The following code examples show how to add tags to an Amazon SNS topic.

Java
SDK for Java 2.x
Note

There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository.

public static void addTopicTags(SnsClient snsClient, String topicArn) { try { Tag tag = Tag.builder() .key("Team") .value("Development") .build(); Tag tag2 = Tag.builder() .key("Environment") .value("Gamma") .build(); List<Tag> tagList = new ArrayList<>(); tagList.add(tag); tagList.add(tag2); TagResourceRequest tagResourceRequest = TagResourceRequest.builder() .resourceArn(topicArn) .tags(tagList) .build(); snsClient.tagResource(tagResourceRequest); System.out.println("Tags have been added to "+topicArn); } catch (SnsException e) { System.err.println(e.awsErrorDetails().errorMessage()); System.exit(1); } }
  • For API details, see TagResource in AWS SDK for Java 2.x API Reference.

Kotlin
SDK for Kotlin
Note

This is prerelease documentation for a feature in preview release. It is subject to change.

Note

There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository.

suspend fun addTopicTags(topicArn: String) { val tag = Tag { key = "Team" value = "Development" } val tag2 = Tag { key = "Environment" value = "Gamma" } val tagList = mutableListOf<Tag>() tagList.add(tag) tagList.add(tag2) val request = TagResourceRequest { resourceArn = topicArn tags = tagList } SnsClient { region = "us-east-1" }.use { snsClient -> snsClient.tagResource(request) println("Tags have been added to $topicArn") } }
  • For API details, see TagResource in AWS SDK for Kotlin API reference.

Managing tags with Amazon SNS API actions

To manage tags using the Amazon SNS API, use the following API actions:

API actions that support ABAC

The following is a list of API actions that support attribute-based access control (ABAC). For more details about ABAC, see What is ABAC for AWS? in the IAM User Guide.