Search in sources :

Example 1 with CreateAccessKeyResponse

use of software.amazon.awssdk.services.iam.model.CreateAccessKeyResponse in project aws-doc-sdk-examples by awsdocs.

the class CreateAccessKey method createIAMAccessKey.

// snippet-start:[iam.java2.create_access_key.main]
public static String createIAMAccessKey(IamClient iam, String user) {
    try {
        CreateAccessKeyRequest request = CreateAccessKeyRequest.builder().userName(user).build();
        CreateAccessKeyResponse response = iam.createAccessKey(request);
        String keyId = response.accessKey().accessKeyId();
        return keyId;
    } catch (IamException e) {
        System.err.println(e.awsErrorDetails().errorMessage());
        System.exit(1);
    }
    return "";
}
Also used : CreateAccessKeyRequest(software.amazon.awssdk.services.iam.model.CreateAccessKeyRequest) CreateAccessKeyResponse(software.amazon.awssdk.services.iam.model.CreateAccessKeyResponse) IamException(software.amazon.awssdk.services.iam.model.IamException)

Aggregations

CreateAccessKeyRequest (software.amazon.awssdk.services.iam.model.CreateAccessKeyRequest)1 CreateAccessKeyResponse (software.amazon.awssdk.services.iam.model.CreateAccessKeyResponse)1 IamException (software.amazon.awssdk.services.iam.model.IamException)1