use of software.amazon.awssdk.services.iam.model.AccessKeyMetadata 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);
}
}
Aggregations