Search in sources :

Example 1 with TagQueueRequest

use of software.amazon.awssdk.services.sqs.model.TagQueueRequest in project aws-doc-sdk-examples by awsdocs.

the class AddQueueTags method addTags.

// snippet-start:[sqs.java2.add_tags.main]
public static void addTags(SqsClient sqsClient, String queueName) {
    try {
        GetQueueUrlRequest urlRequest = GetQueueUrlRequest.builder().queueName(queueName).build();
        GetQueueUrlResponse getQueueUrlResponse = sqsClient.getQueueUrl(urlRequest);
        String queueUrl = getQueueUrlResponse.queueUrl();
        HashMap<String, String> addedTags = new HashMap<>();
        addedTags.put("Team", "Development");
        addedTags.put("Priority", "Beta");
        addedTags.put("Accounting ID", "456def");
        TagQueueRequest tagQueueRequest = TagQueueRequest.builder().queueUrl(queueUrl).tags(addedTags).build();
        sqsClient.tagQueue(tagQueueRequest);
        System.out.println("Tags have been applied to " + queueName);
    } catch (SqsException e) {
        System.err.println(e.awsErrorDetails().errorMessage());
        System.exit(1);
    }
}
Also used : GetQueueUrlRequest(software.amazon.awssdk.services.sqs.model.GetQueueUrlRequest) TagQueueRequest(software.amazon.awssdk.services.sqs.model.TagQueueRequest) SqsException(software.amazon.awssdk.services.sqs.model.SqsException) HashMap(java.util.HashMap) GetQueueUrlResponse(software.amazon.awssdk.services.sqs.model.GetQueueUrlResponse)

Aggregations

HashMap (java.util.HashMap)1 GetQueueUrlRequest (software.amazon.awssdk.services.sqs.model.GetQueueUrlRequest)1 GetQueueUrlResponse (software.amazon.awssdk.services.sqs.model.GetQueueUrlResponse)1 SqsException (software.amazon.awssdk.services.sqs.model.SqsException)1 TagQueueRequest (software.amazon.awssdk.services.sqs.model.TagQueueRequest)1