From b1eb0b5b2719d354c448f07a235006ff7c0dbeee Mon Sep 17 00:00:00 2001 From: scmacdon Date: Wed, 4 Dec 2024 14:40:42 -0500 Subject: [PATCH] rolled in review comments --- .doc_gen/metadata/s3_metadata.yaml | 26 +++++++++++ .../s3/replication/BucketReplication.java | 46 ++++--------------- 2 files changed, 34 insertions(+), 38 deletions(-) diff --git a/.doc_gen/metadata/s3_metadata.yaml b/.doc_gen/metadata/s3_metadata.yaml index 0c4f5c1adde..3067c6a0060 100644 --- a/.doc_gen/metadata/s3_metadata.yaml +++ b/.doc_gen/metadata/s3_metadata.yaml @@ -360,6 +360,32 @@ s3_CopyObject: - aws-cli.bash-linux.s3.CopyObject services: s3: {CopyObject} +s3_GetBucketReplication: + languages: + Java: + versions: + - sdk_version: 2 + github: javav2/example_code/s3 + sdkguide: + excerpts: + - description: + snippet_tags: + - s3.java2.bucket_get.replication.main + services: + s3: {GetBucketReplication} +s3_PutBucketVersioning: + languages: + Java: + versions: + - sdk_version: 2 + github: javav2/example_code/s3 + sdkguide: + excerpts: + - description: + snippet_tags: + - s3.java2.bucket_enable.version.main + services: + s3: {PutBucketVersioning} s3_PutBucketReplication: languages: Java: diff --git a/javav2/example_code/s3/src/main/java/com/example/s3/replication/BucketReplication.java b/javav2/example_code/s3/src/main/java/com/example/s3/replication/BucketReplication.java index d778298ed03..eda9b5251b9 100644 --- a/javav2/example_code/s3/src/main/java/com/example/s3/replication/BucketReplication.java +++ b/javav2/example_code/s3/src/main/java/com/example/s3/replication/BucketReplication.java @@ -17,7 +17,6 @@ import java.util.List; import java.util.Scanner; -// snippet-start:[s3.java2.bucket_replication.main] /** * Before running this Java V2 code example, set up your development * environment, including your credentials. @@ -36,7 +35,7 @@ public class BucketReplication { public static void main(String[] args) throws IOException { final String usage = """ Usage: - + Where: roleName - The name of the IAM role that will be used to access the S3 buckets. @@ -124,11 +123,11 @@ public static void main(String[] args) throws IOException { waitForInputToContinue(scanner); deleteBucket(s3Client, sourceBucketName); deleteBucket(s3Client, destBucketName); - deleteRole(iamClient, roleName); System.out.println("This concludes the Cross-Region Replication example"); System.out.println(DASHES); } + // snippet-start:[s3.java2.bucket_enable.version.main] /** * Enables bucket versioning for the specified S3 bucket. * @@ -148,7 +147,9 @@ public static void enableBucketVersioning(S3Client s3Client, String bucketName){ s3Client.putBucketVersioning(versioningRequest); System.out.println("Bucket versioning has been enabled for "+bucketName); } + // snippet-end:[s3.java2.bucket_enable.version.main] + // snippet-start:[s3.java2.bucket_replication.main] /** * Sets the replication configuration for an Amazon S3 bucket. * @@ -214,7 +215,9 @@ public static void setReplication(S3Client s3Client, String sourceBucketName, St System.err.println("SDK Exception: " + e.getMessage()); } } + // snippet-end:[s3.java2.bucket_replication.main] + // snippet-start:[s3.java2.bucket_get.replication.main] /** * Retrieves the replication details for the specified S3 bucket. * @@ -239,6 +242,7 @@ public static void getReplicationDetails(S3Client s3Client, String sourceBucketN System.err.println("Failed to retrieve replication details: " + e.awsErrorDetails().errorMessage()); } } + // snippet-end:[s3.java2.bucket_get.replication.main] /** * Creates an Amazon S3 bucket. @@ -347,39 +351,6 @@ public static void deleteBucket(S3Client s3Client, String bucket) { } } - /** - * Deletes an IAM role and the inline policy attached to it. - * - * @param iam An instance of the {@link IamClient} used to interact with the IAM service. - * @param roleName The name of the IAM role to be deleted. - * - * @throws IamException if there is an error deleting the role or the inline policy. - */ - public static void deleteRole(IamClient iam, String roleName) { - try { - // First, delete the inline policy attached to the role. - DeleteRolePolicyRequest deleteRolePolicyRequest = DeleteRolePolicyRequest.builder() - .roleName(roleName) - .policyName("crrRolePolicy") // The name you used when adding the policy - .build(); - - iam.deleteRolePolicy(deleteRolePolicyRequest); - System.out.println("Deleted inline policy: crrRolePolicy"); - - // Now delete the role itself. - DeleteRoleRequest deleteRoleRequest = DeleteRoleRequest.builder() - .roleName(roleName) - .build(); - - iam.deleteRole(deleteRoleRequest); - System.out.println("Successfully deleted role: " + roleName); - - } catch (IamException e) { - System.err.println("IAM Exception: " + e.awsErrorDetails().errorMessage()); - System.exit(1); - } - } - /** * Retrieves the account number of the current AWS user using the AWS STS (Security Token Service) * client. @@ -407,5 +378,4 @@ private static void waitForInputToContinue(Scanner scanner) { } } } -} -// snippet-end:[s3.java2.bucket_replication.main] \ No newline at end of file +} \ No newline at end of file