use of software.amazon.awssdk.services.iam.model.IamException in project aws-doc-sdk-examples by awsdocs.
the class DeletePolicy method deleteIAMPolicy.
// snippet-start:[iam.java2.delete_policy.main]
public static void deleteIAMPolicy(IamClient iam, String policyARN) {
try {
DeletePolicyRequest request = DeletePolicyRequest.builder().policyArn(policyARN).build();
iam.deletePolicy(request);
System.out.println("Successfully deleted the policy");
} catch (IamException e) {
System.err.println(e.awsErrorDetails().errorMessage());
System.exit(1);
}
System.out.println("Done");
}
use of software.amazon.awssdk.services.iam.model.IamException in project aws-doc-sdk-examples by awsdocs.
the class DeleteUser method deleteIAMUser.
// snippet-start:[iam.java2.delete_user.main]
public static void deleteIAMUser(IamClient iam, String userName) {
try {
DeleteUserRequest request = DeleteUserRequest.builder().userName(userName).build();
iam.deleteUser(request);
System.out.println("Successfully deleted IAM user " + userName);
} catch (IamException e) {
System.err.println(e.awsErrorDetails().errorMessage());
System.exit(1);
}
}
use of software.amazon.awssdk.services.iam.model.IamException 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 "";
}
use of software.amazon.awssdk.services.iam.model.IamException in project aws-doc-sdk-examples by awsdocs.
the class DemoUtils method createPersonalizeRole.
public static String createPersonalizeRole(IamClient iamClient, String roleName) {
String roleArn = checkRoleExists(iamClient, roleName);
String minimumPersonalizeAccessPolicyArn;
try {
if (roleArn.length() == 0) {
CreateRoleRequest createRoleRequest = CreateRoleRequest.builder().roleName(roleName).assumeRolePolicyDocument(ASSUME_ROLE_POLICY).description("PersonalizeRole").build();
CreateRoleResponse response = iamClient.createRole(createRoleRequest);
roleArn = response.role().arn();
System.out.println("The ARN of your Amazon Personalize service role is " + roleArn);
}
minimumPersonalizeAccessPolicyArn = createPersonalizeIamPolicy(iamClient, "minimumPersonalizeAccessPolicy");
attachIamPolicyToRole(iamClient, roleName, minimumPersonalizeAccessPolicyArn);
attachIamPolicyToRole(iamClient, roleName, "arn:aws:iam::aws:policy/AmazonS3FullAccess");
return roleArn;
} catch (IamException e) {
System.err.println(e.awsErrorDetails().errorMessage());
System.exit(1);
} catch (Exception e) {
e.printStackTrace();
System.exit(1);
}
return roleArn;
}
use of software.amazon.awssdk.services.iam.model.IamException in project aws-doc-sdk-examples by awsdocs.
the class DemoUtils method getIamPolicyArn.
private static String getIamPolicyArn(IamClient iamClient, String policyName) {
try {
ListPoliciesRequest listPoliciesRequest = ListPoliciesRequest.builder().build();
ListPoliciesResponse listPoliciesResponse = iamClient.listPolicies(listPoliciesRequest);
for (Policy policy : listPoliciesResponse.policies()) {
if (policy.policyName().equals(policyName)) {
return policy.arn();
}
}
} catch (IamException e) {
System.err.println(e.awsErrorDetails().errorMessage());
System.exit(1);
}
return null;
}
Aggregations