-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathiam.java
More file actions
60 lines (49 loc) · 2.5 KB
/
iam.java
File metadata and controls
60 lines (49 loc) · 2.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
package aws.example.iam;
import com.amazonaws.services.identitymanagement.AmazonIdentityManagement;
import com.amazonaws.services.identitymanagement.AmazonIdentityManagementClientBuilder;
import com.amazonaws.services.identitymanagement.model.CreatePolicyRequest;
import com.amazonaws.services.identitymanagement.model.CreatePolicyResult;
/**
* Creates a fixed policy with a provided policy name.
*/
public class CreatePolicy {
public static final String POLICY_DOCUMENT = "{" +
" \"Version\": \"2012-10-17\"," +
" \"Statement\": [" +
" {" +
" \"Effect\": \"Allow\"," +
" \"Action\": \"logs:CreateLogGroup\"," +
" \"Resource\": \"%s\"" +
" }," +
" {" +
" \"Effect\": \"Allow\"," +
" \"Action\": [" +
" \"dynamodb:DeleteItem\"," +
" \"dynamodb:GetItem\"," +
" \"dynamodb:PutItem\"," +
" \"dynamodb:Scan\"," +
" \"dynamodb:UpdateItem\"" +
" ]," +
" \"Resource\": \"RESOURCE_ARN\"" +
" }" +
" ]" +
"}";
public static void main(String[] args) {
final String USAGE = "To run this example, supply a policy name\n" +
"Ex: CreatePolicy <policy-name>\n";
if (args.length != 1) {
System.out.println(USAGE);
System.exit(1);
}
String policy_name = args[0];
final AmazonIdentityManagement iam = AmazonIdentityManagementClientBuilder.defaultClient();
CreatePolicyRequest request = new CreatePolicyRequest()
.withPolicyName(policy_name)
.withPolicyDocument(POLICY_DOCUMENT);
CreatePolicyResult response = iam.createPolicy(request);
System.out.println("Successfully created policy: " +
response.getPolicy().getPolicyName());
}
}