AWS AWSSimpleQueueService documentation change
Summary
Restructured Java code example for SSE configuration, added error handling, logging, and resource cleanup. Changed KMS key alias to be parameterized and updated attribute configuration syntax.
Security assessment
The changes improve code quality and demonstrate proper error handling for SSE configuration, but don't address a specific security vulnerability. The documentation continues to explain security features (SSE with KMS) but doesn't indicate a security fix.
Diff
diff --git a/AWSSimpleQueueService/latest/SQSDeveloperGuide/sqs-java-configure-sse.md b/AWSSimpleQueueService/latest/SQSDeveloperGuide/sqs-java-configure-sse.md index f9c821ca8..eb259d1ec 100644 --- a/AWSSimpleQueueService/latest/SQSDeveloperGuide/sqs-java-configure-sse.md +++ b/AWSSimpleQueueService/latest/SQSDeveloperGuide/sqs-java-configure-sse.md @@ -22,2 +22,2 @@ Before you run the example code, make sure that you have set your AWS credential - // Create an SqsClient for the specified Region. - SqsClient sqsClient = SqsClient.builder().region(Region.US_WEST_1).build(); + public static void addEncryption(String queueName, String kmsMasterKeyAlias) { + SqsClient sqsClient = SqsClient.create(); @@ -25,4 +25,11 @@ Before you run the example code, make sure that you have set your AWS credential - // Get the URL of your queue. - String myQueueName = "my queue"; - GetQueueUrlResponse getQueueUrlResponse = - sqsClient.getQueueUrl(GetQueueUrlRequest.builder().queueName(myQueueName).build()); + GetQueueUrlRequest urlRequest = GetQueueUrlRequest.builder() + .queueName(queueName) + .build(); + + GetQueueUrlResponse getQueueUrlResponse; + try { + getQueueUrlResponse = sqsClient.getQueueUrl(urlRequest); + } catch (QueueDoesNotExistException e) { + LOGGER.error(e.getMessage(), e); + throw new RuntimeException(e); + } @@ -31,5 +37,0 @@ Before you run the example code, make sure that you have set your AWS credential - // Create a hashmap for the attributes. Add the key alias and reuse period to the hashmap. - HashMap<QueueAttributeName, String> attributes = new HashMap<QueueAttributeName, String>(); - final String kmsMasterKeyAlias = "alias/aws/sqs"; // the alias of the AWS managed KMS key for Amazon SQS. - attributes.put(QueueAttributeName.KMS_MASTER_KEY_ID, kmsMasterKeyAlias); - attributes.put(QueueAttributeName.KMS_DATA_KEY_REUSE_PERIOD_SECONDS, "140"); @@ -37,2 +39,6 @@ Before you run the example code, make sure that you have set your AWS credential - // Create the SetQueueAttributesRequest. - SetQueueAttributesRequest set_attrs_request = SetQueueAttributesRequest.builder() + Map<QueueAttributeName, String> attributes = Map.of( + QueueAttributeName.KMS_MASTER_KEY_ID, kmsMasterKeyAlias, + QueueAttributeName.KMS_DATA_KEY_REUSE_PERIOD_SECONDS, "140" // Set the data key reuse period to 140 seconds. + ); // This is how long SQS can reuse the data key before requesting a new one from KMS. + + SetQueueAttributesRequest attRequest = SetQueueAttributesRequest.builder() @@ -42,2 +48,10 @@ Before you run the example code, make sure that you have set your AWS credential - - sqsClient.setQueueAttributes(set_attrs_request); + try { + sqsClient.setQueueAttributes(attRequest); + LOGGER.info("The attributes have been applied to {}", queueName); + } catch (InvalidAttributeNameException | InvalidAttributeValueException e) { + LOGGER.error(e.getMessage(), e); + throw new RuntimeException(e); + } finally { + sqsClient.close(); + } + }