Skip to content

Commit 293d232

Browse files
scmacdonrlhagerm
authored andcommitted
rolled in review comments
1 parent d135839 commit 293d232

File tree

1 file changed

+45
-30
lines changed

1 file changed

+45
-30
lines changed

javav2/example_code/s3/src/main/java/com/example/s3/lockscenario/CreateObjectLockRole.java

Lines changed: 45 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -15,45 +15,60 @@ public static void main(String[] args) {
1515
}
1616

1717
// snippet-start:[S3Lock.javav2.lock.role.main]
18+
1819
/**
1920
* Creates an IAM role for AWS S3 Batch Operations to manage object locks.
2021
*/
2122
public static void createLockRole() {
2223
final String roleName = "batch_operations-object-lock1";
2324

2425
// Trust policy
25-
final String trustPolicy = "{"
26-
+ "\"Version\":\"2012-10-17\","
27-
+ "\"Statement\":[{"
28-
+ "\"Effect\":\"Allow\","
29-
+ "\"Principal\":{"
30-
+ "\"Service\":\"batchoperations.s3.amazonaws.com\""
31-
+ "},"
32-
+ "\"Action\":\"sts:AssumeRole\""
33-
+ "}]"
34-
+ "}";
26+
final String trustPolicy = """
27+
{
28+
"Version": "2012-10-17",
29+
"Statement": [
30+
{
31+
"Effect": "Allow",
32+
"Principal": {
33+
"Service": "batchoperations.s3.amazonaws.com"
34+
},
35+
"Action": "sts:AssumeRole"
36+
}
37+
]
38+
}
39+
""";
40+
3541

3642
// Permissions policy
37-
final String bopsPermissions = "{"
38-
+ "\"Version\":\"2012-10-17\","
39-
+ "\"Statement\":["
40-
+ "{"
41-
+ "\"Effect\":\"Allow\","
42-
+ "\"Action\":\"s3:GetBucketObjectLockConfiguration\","
43-
+ "\"Resource\":\"arn:aws:s3:::amzn-s3-demo-manifest-bucket\""
44-
+ "},"
45-
+ "{"
46-
+ "\"Effect\":\"Allow\","
47-
+ "\"Action\":[\"s3:GetObject\",\"s3:GetObjectVersion\",\"s3:GetBucketLocation\"],"
48-
+ "\"Resource\":\"arn:aws:s3:::amzn-s3-demo-manifest-bucket/*\""
49-
+ "},"
50-
+ "{"
51-
+ "\"Effect\":\"Allow\","
52-
+ "\"Action\":[\"s3:PutObject\",\"s3:GetBucketLocation\"],"
53-
+ "\"Resource\":\"arn:aws:s3:::amzn-s3-demo-completion-report-bucket/*\""
54-
+ "}"
55-
+ "]"
56-
+ "}";
43+
final String bopsPermissions = """
44+
{
45+
"Version": "2012-10-17",
46+
"Statement": [
47+
{
48+
"Effect": "Allow",
49+
"Action": "s3:GetBucketObjectLockConfiguration",
50+
"Resource": "arn:aws:s3:::amzn-s3-demo-manifest-bucket"
51+
},
52+
{
53+
"Effect": "Allow",
54+
"Action": [
55+
"s3:GetObject",
56+
"s3:GetObjectVersion",
57+
"s3:GetBucketLocation"
58+
],
59+
"Resource": "arn:aws:s3:::amzn-s3-demo-manifest-bucket/*"
60+
},
61+
{
62+
"Effect": "Allow",
63+
"Action": [
64+
"s3:PutObject",
65+
"s3:GetBucketLocation"
66+
],
67+
"Resource": "arn:aws:s3:::amzn-s3-demo-completion-report-bucket/*"
68+
}
69+
]
70+
}
71+
""";
5772

5873
// Create IAM client
5974
final IamClient iam = IamClient.builder()

0 commit comments

Comments
 (0)