Search in sources :

Example 1 with ListAccessKeysResponse

use of software.amazon.awssdk.services.iam.model.ListAccessKeysResponse 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);
    }
}
Also used : ListAccessKeysResponse(software.amazon.awssdk.services.iam.model.ListAccessKeysResponse) AccessKeyMetadata(software.amazon.awssdk.services.iam.model.AccessKeyMetadata) ListAccessKeysRequest(software.amazon.awssdk.services.iam.model.ListAccessKeysRequest) IamException(software.amazon.awssdk.services.iam.model.IamException)

Aggregations

AccessKeyMetadata (software.amazon.awssdk.services.iam.model.AccessKeyMetadata)1 IamException (software.amazon.awssdk.services.iam.model.IamException)1 ListAccessKeysRequest (software.amazon.awssdk.services.iam.model.ListAccessKeysRequest)1 ListAccessKeysResponse (software.amazon.awssdk.services.iam.model.ListAccessKeysResponse)1