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 "";
}
Aggregations