use of software.amazon.awssdk.services.iam.model.IamException in project aws-doc-sdk-examples by awsdocs.
the class DetachRolePolicy method detachPolicy.
// snippet-start:[iam.java2.detach_role_policy.main]
public static void detachPolicy(IamClient iam, String roleName, String policyArn) {
try {
DetachRolePolicyRequest request = DetachRolePolicyRequest.builder().roleName(roleName).policyArn(policyArn).build();
iam.detachRolePolicy(request);
System.out.println("Successfully detached policy " + policyArn + " from role " + roleName);
} 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 ListUsers method listAllUsers.
// snippet-start:[iam.java2.list_users.main]
public static void listAllUsers(IamClient iam) {
try {
boolean done = false;
String newMarker = null;
while (!done) {
ListUsersResponse response;
if (newMarker == null) {
ListUsersRequest request = ListUsersRequest.builder().build();
response = iam.listUsers(request);
} else {
ListUsersRequest request = ListUsersRequest.builder().marker(newMarker).build();
response = iam.listUsers(request);
}
for (User user : response.users()) {
System.out.format("\n Retrieved user %s", user.userName());
}
if (!response.isTruncated()) {
done = true;
} else {
newMarker = response.marker();
}
}
} 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 UpdateServerCertificate method updateCertificate.
// snippet-start:[iam.java2.update_server_certificate.main]
public static void updateCertificate(IamClient iam, String curName, String newName) {
try {
UpdateServerCertificateRequest request = UpdateServerCertificateRequest.builder().serverCertificateName(curName).newServerCertificateName(newName).build();
UpdateServerCertificateResponse response = iam.updateServerCertificate(request);
System.out.printf("Successfully updated server certificate to name %s", newName);
} 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 GetPolicy method getIAMPolicy.
// snippet-start:[iam.java2.get_policy.main]
public static void getIAMPolicy(IamClient iam, String policyArn) {
try {
GetPolicyRequest request = GetPolicyRequest.builder().policyArn(policyArn).build();
GetPolicyResponse response = iam.getPolicy(request);
System.out.format("Successfully retrieved policy %s", response.policy().policyName());
} 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 GetServerCertificate method getCertificate.
// snippet-start:[iam.java2.get_server_certificate.main]
public static void getCertificate(IamClient iam, String certName) {
try {
GetServerCertificateRequest request = GetServerCertificateRequest.builder().serverCertificateName(certName).build();
GetServerCertificateResponse response = iam.getServerCertificate(request);
System.out.format("Successfully retrieved certificate with body %s", response.serverCertificate().certificateBody());
} catch (IamException e) {
System.err.println(e.awsErrorDetails().errorMessage());
System.exit(1);
}
}
Aggregations