use of software.amazon.awssdk.services.iam.model.IAMException in project aws-doc-sdk-examples by awsdocs.
the class ListAccessKeys method listKeys.
// snippet-start:[iam.java2.list_access_keys.main]
public static void listKeys(IamClient iam, String userName) {
try {
boolean done = false;
String newMarker = null;
while (!done) {
ListAccessKeysResponse response;
if (newMarker == null) {
ListAccessKeysRequest request = ListAccessKeysRequest.builder().userName(userName).build();
response = iam.listAccessKeys(request);
} else {
ListAccessKeysRequest request = ListAccessKeysRequest.builder().userName(userName).marker(newMarker).build();
response = iam.listAccessKeys(request);
}
for (AccessKeyMetadata metadata : response.accessKeyMetadata()) {
System.out.format("Retrieved access key %s", metadata.accessKeyId());
}
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 ListServerCertificates method listCertificates.
// snippet-start:[iam.java2.list_server_certificates.main]
public static void listCertificates(IamClient iam) {
try {
boolean done = false;
String newMarker = null;
while (!done) {
ListServerCertificatesResponse response;
if (newMarker == null) {
ListServerCertificatesRequest request = ListServerCertificatesRequest.builder().build();
response = iam.listServerCertificates(request);
} else {
ListServerCertificatesRequest request = ListServerCertificatesRequest.builder().marker(newMarker).build();
response = iam.listServerCertificates(request);
}
for (ServerCertificateMetadata metadata : response.serverCertificateMetadataList()) {
System.out.printf("Retrieved server certificate %s", metadata.serverCertificateName());
}
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 UpdateAccessKey method updateKey.
// snippet-start:[iam.java2.update_access_key.main]
public static void updateKey(IamClient iam, String username, String accessId, String status) {
try {
if (status.toLowerCase().equalsIgnoreCase("active")) {
statusType = StatusType.ACTIVE;
} else if (status.toLowerCase().equalsIgnoreCase("inactive")) {
statusType = StatusType.INACTIVE;
} else {
statusType = StatusType.UNKNOWN_TO_SDK_VERSION;
}
UpdateAccessKeyRequest request = UpdateAccessKeyRequest.builder().accessKeyId(accessId).userName(username).status(statusType).build();
iam.updateAccessKey(request);
System.out.printf("Successfully updated the status of access key %s to" + "status %s for user %s", accessId, status, 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 UpdateUser method updateIAMUser.
// snippet-start:[iam.java2.update_user.main]
public static void updateIAMUser(IamClient iam, String curName, String newName) {
try {
UpdateUserRequest request = UpdateUserRequest.builder().userName(curName).newUserName(newName).build();
iam.updateUser(request);
System.out.printf("Successfully updated user to username %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 DeleteAccessKey method deleteKey.
// snippet-start:[iam.java2.delete_access_key.main]
public static void deleteKey(IamClient iam, String username, String accessKey) {
try {
DeleteAccessKeyRequest request = DeleteAccessKeyRequest.builder().accessKeyId(accessKey).userName(username).build();
iam.deleteAccessKey(request);
System.out.println("Successfully deleted access key " + accessKey + " from user " + username);
} catch (IamException e) {
System.err.println(e.awsErrorDetails().errorMessage());
System.exit(1);
}
}
Aggregations