キューにタグを設定する - Amazon Simple Queue Service

翻訳は機械翻訳により提供されています。提供された翻訳内容と英語版の間で齟齬、不一致または矛盾がある場合、英語版が優先します。

キューにタグを設定する

Amazon SQS キューを整理および識別するには、コスト配分タグを使用します。を使用してタグを設定する方法を以下の例に示します。AWS SDK for Java。詳細については、「Amazon SQSコスト配分タグ」を参照してください。

サンプルコードを実行する前に AWS の認証情報を設定したことをご確認ください。詳しい情報については、AWS SDK for Java 2.x デベロッパーガイド開発用 AWS の認証情報およびリージョンのセットアップをご参照ください。

タグをリスト表示する

キューのタグを一覧表示するには、ListQueueTags方法。

// Create an SqsClient for the specified region. SqsClient sqsClient = SqsClient.builder().region(Region.US_WEST_1).build(); // Get the queue URL. String queueName = "MyStandardQ1"; GetQueueUrlResponse getQueueUrlResponse = sqsClient.getQueueUrl(GetQueueUrlRequest.builder().queueName(queueName).build()); String queueUrl = getQueueUrlResponse.queueUrl(); // Create the ListQueueTagsRequest. final ListQueueTagsRequest listQueueTagsRequest = ListQueueTagsRequest.builder().queueUrl(queueUrl).build(); // Retrieve the list of queue tags and print them. final ListQueueTagsResponse listQueueTagsResponse = sqsClient.listQueueTags(listQueueTagsRequest); System.out.println(String.format("ListQueueTags: \tTags for queue %s are %s.\n", queueName, listQueueTagsResponse.tags() ));

タグの追加または更新

キューのタグ値を追加または更新するには、TagQueue方法。

// Create an SqsClient for the specified Region. SqsClient sqsClient = SqsClient.builder().region(Region.US_WEST_1).build(); // Get the queue URL. String queueName = "MyStandardQ1"; GetQueueUrlResponse getQueueUrlResponse = sqsClient.getQueueUrl(GetQueueUrlRequest.builder().queueName(queueName).build()); String queueUrl = getQueueUrlResponse.queueUrl(); // Build a hashmap of the tags. final HashMap<String, String> addedTags = new HashMap<>(); addedTags.put("Team", "Development"); addedTags.put("Priority", "Beta"); addedTags.put("Accounting ID", "456def"); //Create the TagQueueRequest and add them to the queue. final TagQueueRequest tagQueueRequest = TagQueueRequest.builder() .queueUrl(queueUrl) .tags(addedTags) .build(); sqsClient.tagQueue(tagQueueRequest);

タグの削除

キューから 1 つ以上のタグを削除するには、UntagQueue方法。次の例では、Accounting IDタグ。

// Create the UntagQueueRequest. final UntagQueueRequest untagQueueRequest = UntagQueueRequest.builder() .queueUrl(queueUrl) .tagKeys("Accounting ID") .build(); // Remove the tag from this queue. sqsClient.untagQueue(untagQueueRequest);