use of software.amazon.awssdk.services.iam.model.CreatePolicyResponse in project aws-doc-sdk-examples by awsdocs.
the class CreatePolicy method createIAMPolicy.
// snippet-start:[iam.java2.create_policy.main]
public static String createIAMPolicy(IamClient iam, String policyName) {
try {
// Create an IamWaiter object
IamWaiter iamWaiter = iam.waiter();
CreatePolicyRequest request = CreatePolicyRequest.builder().policyName(policyName).policyDocument(PolicyDocument).build();
CreatePolicyResponse response = iam.createPolicy(request);
// Wait until the policy is created
GetPolicyRequest polRequest = GetPolicyRequest.builder().policyArn(response.policy().arn()).build();
WaiterResponse<GetPolicyResponse> waitUntilPolicyExists = iamWaiter.waitUntilPolicyExists(polRequest);
waitUntilPolicyExists.matched().response().ifPresent(System.out::println);
return response.policy().arn();
} catch (IamException e) {
System.err.println(e.awsErrorDetails().errorMessage());
System.exit(1);
}
return "";
}
use of software.amazon.awssdk.services.iam.model.CreatePolicyResponse in project aws-doc-sdk-examples by awsdocs.
the class DemoUtils method createPersonalizeIamPolicy.
public static String createPersonalizeIamPolicy(IamClient iam, String policyName) {
String policyArn = getIamPolicyArn(iam, policyName);
if (policyArn != null) {
return policyArn;
}
try {
// Create an IamWaiter object
IamWaiter iamWaiter = iam.waiter();
CreatePolicyRequest request = CreatePolicyRequest.builder().policyName(policyName).policyDocument(PERSONALIZE_POLICY).build();
CreatePolicyResponse response = iam.createPolicy(request);
// Wait until the policy is created
GetPolicyRequest polRequest = GetPolicyRequest.builder().policyArn(response.policy().arn()).build();
WaiterResponse<GetPolicyResponse> waitUntilPolicyExists = iamWaiter.waitUntilPolicyExists(polRequest);
waitUntilPolicyExists.matched().response().ifPresent(System.out::println);
return response.policy().arn();
} catch (EntityAlreadyExistsException ex) {
return "";
} catch (IamException e) {
System.err.println(e.awsErrorDetails().errorMessage());
System.exit(1);
}
return "";
}
Aggregations