Skip to content

Commit

Permalink
rolled in review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
scmacdon committed Dec 4, 2024
1 parent 787e8ec commit b1eb0b5
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 38 deletions.
26 changes: 26 additions & 0 deletions .doc_gen/metadata/s3_metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -36,7 +35,7 @@ public class BucketReplication {
public static void main(String[] args) throws IOException {
final String usage = """
Usage:
<roleName> <bucketRegion> <sourceBucketName> <destBucketName> <roleARN> <destinationBucketARN>
<roleName> <bucketRegion> <sourceBucketName> <destBucketName>
Where:
roleName - The name of the IAM role that will be used to access the S3 buckets.
Expand Down Expand Up @@ -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.
*
Expand All @@ -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.
*
Expand Down Expand Up @@ -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.
*
Expand All @@ -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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -407,5 +378,4 @@ private static void waitForInputToContinue(Scanner scanner) {
}
}
}
}
// snippet-end:[s3.java2.bucket_replication.main]
}

0 comments on commit b1eb0b5

Please sign in to comment.