AWS code-library documentation change
Summary
Modified Rekognition moderation detection example to use S3 bucket storage. Added bucketName parameter, updated region, changed exception handling, and switched to S3 object references instead of local files.
Security assessment
While moderation labels relate to content safety, the changes focus on storage method rather than introducing new security controls. No evidence of addressing a specific security vulnerability.
Diff
diff --git a/code-library/latest/ug/rekognition_example_rekognition_DetectModerationLabels_section.md b/code-library/latest/ug/rekognition_example_rekognition_DetectModerationLabels_section.md index b53382b08..36259b94e 100644 --- a//code-library/latest/ug/rekognition_example_rekognition_DetectModerationLabels_section.md +++ b//code-library/latest/ug/rekognition_example_rekognition_DetectModerationLabels_section.md @@ -133 +132,0 @@ There's more on GitHub. Find the complete example and learn how to set up and ru - import software.amazon.awssdk.core.SdkBytes; @@ -136,5 +135,2 @@ There's more on GitHub. Find the complete example and learn how to set up and ru - import software.amazon.awssdk.services.rekognition.model.RekognitionException; - import software.amazon.awssdk.services.rekognition.model.Image; - import software.amazon.awssdk.services.rekognition.model.DetectModerationLabelsRequest; - import software.amazon.awssdk.services.rekognition.model.DetectModerationLabelsResponse; - import software.amazon.awssdk.services.rekognition.model.ModerationLabel; + import software.amazon.awssdk.services.rekognition.model.*; + @@ -158,2 +154 @@ There's more on GitHub. Find the complete example and learn how to set up and ru - - Usage: <sourceImage> + Usage: <bucketName> <sourceImage> @@ -162 +157,2 @@ There's more on GitHub. Find the complete example and learn how to set up and ru - sourceImage - The path to the image (for example, C:\\AWS\\pic1.png).\s + bucketName - The name of the S3 bucket where the images are stored. + sourceImage - The name of the image (for example, pic1.png).\s @@ -165 +161 @@ There's more on GitHub. Find the complete example and learn how to set up and ru - if (args.length < 1) { + if (args.length != 2) { @@ -170,2 +166,3 @@ There's more on GitHub. Find the complete example and learn how to set up and ru - String sourceImage = args[0]; - Region region = Region.US_EAST_1; + String bucketName = args[0]; + String sourceImage = args[1]; + Region region = Region.US_WEST_2; @@ -176 +173 @@ There's more on GitHub. Find the complete example and learn how to set up and ru - detectModLabels(rekClient, sourceImage); + detectModLabels(rekClient, bucketName, sourceImage); @@ -180 +177,10 @@ There's more on GitHub. Find the complete example and learn how to set up and ru - public static void detectModLabels(RekognitionClient rekClient, String sourceImage) { + /** + * Detects moderation labels in an image stored in an Amazon S3 bucket. + * + * @param rekClient the Amazon Rekognition client to use for the detection + * @param bucketName the name of the Amazon S3 bucket where the image is stored + * @param sourceImage the name of the image file to be analyzed + * + * @throws RekognitionException if there is an error during the image detection process + */ + public static void detectModLabels(RekognitionClient rekClient, String bucketName, String sourceImage) { @@ -182,4 +188,7 @@ There's more on GitHub. Find the complete example and learn how to set up and ru - InputStream sourceStream = new FileInputStream(sourceImage); - SdkBytes sourceBytes = SdkBytes.fromInputStream(sourceStream); - Image souImage = Image.builder() - .bytes(sourceBytes) + S3Object s3ObjectTarget = S3Object.builder() + .bucket(bucketName) + .name(sourceImage) + .build(); + + Image targetImage = Image.builder() + .s3Object(s3ObjectTarget) @@ -189 +198 @@ There's more on GitHub. Find the complete example and learn how to set up and ru - .image(souImage) + .image(targetImage) @@ -203 +212 @@ There's more on GitHub. Find the complete example and learn how to set up and ru - } catch (RekognitionException | FileNotFoundException e) { + } catch (RekognitionException e) {