AWS rekognition documentation change
Summary
Updated code example to use S3 bucket references instead of local files, added parameter documentation, changed region, and simplified exception handling
Security assessment
Changes focus on switching from local file access to S3 storage and code cleanup. No explicit security vulnerability fixes or security feature documentation added
Diff
diff --git a/rekognition/latest/dg/example_rekognition_DetectModerationLabels_section.md b/rekognition/latest/dg/example_rekognition_DetectModerationLabels_section.md index b2592d505..34d12fc37 100644 --- a//rekognition/latest/dg/example_rekognition_DetectModerationLabels_section.md +++ b//rekognition/latest/dg/example_rekognition_DetectModerationLabels_section.md @@ -131 +130,0 @@ There's more on GitHub. Find the complete example and learn how to set up and ru - import software.amazon.awssdk.core.SdkBytes; @@ -134,5 +133,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.*; + @@ -156,2 +152 @@ There's more on GitHub. Find the complete example and learn how to set up and ru - - Usage: <sourceImage> + Usage: <bucketName> <sourceImage> @@ -160 +155,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 @@ -163 +159 @@ 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) { @@ -168,2 +164,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; @@ -174 +171 @@ There's more on GitHub. Find the complete example and learn how to set up and ru - detectModLabels(rekClient, sourceImage); + detectModLabels(rekClient, bucketName, sourceImage); @@ -178 +175,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) { @@ -180,4 +186,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) @@ -187 +196 @@ There's more on GitHub. Find the complete example and learn how to set up and ru - .image(souImage) + .image(targetImage) @@ -201 +210 @@ There's more on GitHub. Find the complete example and learn how to set up and ru - } catch (RekognitionException | FileNotFoundException e) { + } catch (RekognitionException e) {