Search in sources :

Example 1 with GetUserRequest

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

the class CreateUser method createIAMUser.

// snippet-start:[iam.java2.create_user.main]
public static String createIAMUser(IamClient iam, String username) {
    try {
        // Create an IamWaiter object
        IamWaiter iamWaiter = iam.waiter();
        CreateUserRequest request = CreateUserRequest.builder().userName(username).build();
        CreateUserResponse response = iam.createUser(request);
        // Wait until the user is created
        GetUserRequest userRequest = GetUserRequest.builder().userName(response.user().userName()).build();
        WaiterResponse<GetUserResponse> waitUntilUserExists = iamWaiter.waitUntilUserExists(userRequest);
        waitUntilUserExists.matched().response().ifPresent(System.out::println);
        return response.user().userName();
    } catch (IamException e) {
        System.err.println(e.awsErrorDetails().errorMessage());
        System.exit(1);
    }
    return "";
}
Also used : GetUserRequest(software.amazon.awssdk.services.iam.model.GetUserRequest) GetUserResponse(software.amazon.awssdk.services.iam.model.GetUserResponse) CreateUserResponse(software.amazon.awssdk.services.iam.model.CreateUserResponse) CreateUserRequest(software.amazon.awssdk.services.iam.model.CreateUserRequest) IamException(software.amazon.awssdk.services.iam.model.IamException) IamWaiter(software.amazon.awssdk.services.iam.waiters.IamWaiter)

Aggregations

CreateUserRequest (software.amazon.awssdk.services.iam.model.CreateUserRequest)1 CreateUserResponse (software.amazon.awssdk.services.iam.model.CreateUserResponse)1 GetUserRequest (software.amazon.awssdk.services.iam.model.GetUserRequest)1 GetUserResponse (software.amazon.awssdk.services.iam.model.GetUserResponse)1 IamException (software.amazon.awssdk.services.iam.model.IamException)1 IamWaiter (software.amazon.awssdk.services.iam.waiters.IamWaiter)1