software.amazon.awssdk.services.sqs.model.GetQueueAttributesRequest Java Examples
The following examples show how to use
software.amazon.awssdk.services.sqs.model.GetQueueAttributesRequest.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AwsSqsScanner.java From clouditor with Apache License 2.0 | 6 votes |
@Override protected Asset transform(Queue queue) throws ScanException { var asset = super.transform(queue); asset.setProperty( "queueAttributes", this.api .getQueueAttributes( GetQueueAttributesRequest.builder() .queueUrl(queue.url()) .attributeNames(QueueAttributeName.ALL) .build()) .attributesAsStrings()); return asset; }
Example #2
Source File: AwsSqsScannerTest.java From clouditor with Apache License 2.0 | 5 votes |
@BeforeAll static void setUpOnce() throws IOException { discoverAssets( SqsClient.class, AwsSqsScanner::new, api -> { when(api.listQueues()) .thenReturn( ListQueuesResponse.builder() .queueUrls("123456789012/MyQueue1", "123456789012/MyQueue2") .build()); when(api.getQueueAttributes( GetQueueAttributesRequest.builder() .queueUrl("123456789012/MyQueue1") .attributeNames(QueueAttributeName.ALL) .build())) .thenReturn( GetQueueAttributesResponse.builder() .attributesWithStrings(Map.of("VisibilityTimeout", "30")) .build()); when(api.getQueueAttributes( GetQueueAttributesRequest.builder() .queueUrl("123456789012/MyQueue2") .attributeNames(QueueAttributeName.ALL) .build())) .thenReturn( GetQueueAttributesResponse.builder() .attributesWithStrings(Map.of("VisibilityTimeout", "60")) .build()); }); }
Example #3
Source File: Topics.java From aws-sdk-java-v2 with Apache License 2.0 | 4 votes |
/** * Subscribes an existing Amazon SQS queue to an existing Amazon SNS topic. * <p> * The specified Amazon SNS client will be used to send the subscription * request, and the Amazon SQS client will be used to modify the policy on * the queue to allow it to receive messages from the SNS topic. * <p> * The policy applied to the SQS queue is similar to this: * <pre> * { * "Version" : "2008-10-17", * "Statement" : [{ * "Sid" : "topic-subscription-arn:aws:sns:us-west-2:599109622955:myTopic", * "Effect" : "Allow", * "Principal" : { * "AWS":["*"] * }, * "Action" : ["sqs:SendMessage"], * "Resource":["arn:aws:sqs:us-west-2:599109622955:myQueue"], * "Condition" : { * "ArnLike":{ * "aws:SourceArn":["arn:aws:sns:us-west-2:599109622955:myTopic"] * } * } * }] * } * </pre> * <p> * <b>IMPORTANT</b>: There might be a small time period immediately after * subscribing the SQS queue to the SNS topic and updating the SQS queue's * policy, where messages are not able to be delivered to the queue. After a * moment, the new queue policy will propagate and the queue will be able to * receive messages. This delay only occurs immediately after initially * subscribing the queue. * <p> * <b>IMPORTANT</b>: The specified queue and topic (as well as the SNS and * SQS client) should both be located in the same AWS region. * * @param sns * The Amazon SNS client to use when subscribing the queue to the * topic. * @param sqs * The Amazon SQS client to use when applying the policy to allow * subscribing to the topic. * @param snsTopicArn * The Amazon Resource Name (ARN) uniquely identifying the Amazon * SNS topic. This value is returned form Amazon SNS when * creating the topic. * @param sqsQueueUrl * The URL uniquely identifying the Amazon SQS queue. This value * is returned from Amazon SQS when creating the queue. * @param extendPolicy * Decides behavior to overwrite the existing policy or extend it. * * @return The subscription ARN as returned by Amazon SNS when the queue is * successfully subscribed to the topic. * * @throws SdkClientException * If any internal errors are encountered inside the client * while attempting to make the request or handle the response. * For example if a network connection is not available. * @throws SdkServiceException * If an error response is returned by SnsClient indicating * either a problem with the data in the request, or a server * side issue. */ public static String subscribeQueue(SnsClient sns, SqsClient sqs, String snsTopicArn, String sqsQueueUrl, boolean extendPolicy) throws SdkClientException, SdkServiceException { List<String> sqsAttrNames = Arrays.asList(QueueAttributeName.QUEUE_ARN.toString(), QueueAttributeName.POLICY.toString()); Map<String, String> sqsAttrs = sqs.getQueueAttributes(GetQueueAttributesRequest.builder() .queueUrl(sqsQueueUrl) .attributeNamesWithStrings(sqsAttrNames) .build()) .attributesAsStrings(); String sqsQueueArn = sqsAttrs.get(QueueAttributeName.QUEUE_ARN.toString()); String policyJson = sqsAttrs.get(QueueAttributeName.POLICY.toString()); Policy policy = extendPolicy && policyJson != null && policyJson.length() > 0 ? Policy.fromJson(policyJson) : new Policy(); policy.getStatements().add(new Statement(Effect.Allow) .withId("topic-subscription-" + snsTopicArn) .withPrincipals(Principal.ALL_USERS) .withActions(new Action("sqs:SendMessage")) .withResources(new Resource(sqsQueueArn)) .withConditions(ConditionFactory.newSourceArnCondition(snsTopicArn))); Map<String, String> newAttrs = new HashMap<String, String>(); newAttrs.put(QueueAttributeName.POLICY.toString(), policy.toJson()); sqs.setQueueAttributes(SetQueueAttributesRequest.builder().queueUrl(sqsQueueUrl).attributesWithStrings(newAttrs).build()); SubscribeResponse subscribeResult = sns.subscribe(SubscribeRequest.builder() .topicArn(snsTopicArn).protocol("sqs") .endpoint(sqsQueueArn) .build()); return subscribeResult.subscriptionArn(); }