Amazon Simple Queue Service
Developer Guide

Tutorial: Adding, Updating, and Removing Cost Allocation Tags for an Amazon SQS Queue

You can add cost allocation tags to your Amazon SQS queues to help organize and identify them. The following example show how to add, update, and remove tags for a queue. For a more information, see Amazon SQS Cost Allocation Tags.

AWS Management Console

The following steps assume that you already created an Amazon SQS queue.

  1. Sign in to the Amazon SQS console.

  2. From the queue list, select a queue.

							A list of queues in the Amazon SQS console
  3. Choose the Tags tab.

    The tags added to the queue are listed.

							A list of tags on the Tags tab in the Amazon SQS
  4. Choose Add/Edit Tags.

  5. Modify queue tags:

    • To add a tag, choose Add New Tag, enter a Key and Value, and then choose Apply Changes.

    • To update a tag, change its Key and Value and then choose Apply Changes.

    • To remove a tag, choose next to a key-value pair and then choose Apply Changes.

    The queue tag changes are applied.

AWS SDK for Java

Before you begin working with the example code, specify your AWS credentials. For more information, see Set up AWS Credentials and Region for Development in the AWS SDK for Java Developer Guide.

To add, update, and remove tags from a queue

  1. Copy the example program for a standard queue or a FIFO queue.

  2. To list the tags added to a queue, add the following code which uses the ListQueueTags action:

    final ListQueueTagsRequest listQueueTagsRequest = new ListQueueTagsRequest(queueUrl); final ListQueueTagsResult listQueueTagsResult = SQSClientFactory.newSQSClient() .listQueueTags(listQueueTagsRequest); System.out.println(String.format("ListQueueTags: \tTags for queue %s are %s.\n", QUEUE_NAME, listQueueTagsResult.getTags()));
  3. To add or update the values of the queue's tags using the tag's key, add the following code which uses the TagQueue action:

    final Map<String, String> addedTags = new HashMap<>(); addedTags.put("Team", "Development"); addedTags.put("Priority", "Beta"); addedTags.put("Accounting ID", "456def"); final TagQueueRequest tagQueueRequest = new TagQueueRequest(queueUrl, addedTags); System.out.println(String.format("TagQueue: \t\tAdd tags %s to queue %s.\n", addedTags, QUEUE_NAME)); SQSClientFactory.newSQSClient().tagQueue(tagQueueRequest);
  4. To remove a tag from the queue using the tag's key, add the following code which uses the UntagQueue action:

    final List<String> tagKeys = Arrays.asList("Accounting ID"); final UntagQueueRequest untagQueueRequest = new UntagQueueRequest(queueUrl, tagKeys); System.out.println(String.format("UntagQueue: \tRemove tags %s from queue %s.\n", tagKeys, QUEUE_NAME)); SQSClientFactory.newSQSClient().untagQueue(untagQueueRequest);
  5. Compile and run your program.

    The existing tags are listed, three are updated, and one tag is removed from the queue.