use of software.amazon.awssdk.services.iam.waiters.IamWaiter in project aws-doc-sdk-examples by awsdocs.
the class IAMScenario method createIAMPolicy.
public static String createIAMPolicy(IamClient iam, String policyName) {
try {
// Create an IamWaiter object
IamWaiter iamWaiter = iam.waiter();
CreatePolicyRequest request = CreatePolicyRequest.builder().policyName(policyName).policyDocument(PolicyDocument).build();
CreatePolicyResponse response = iam.createPolicy(request);
// Wait until the policy is created
GetPolicyRequest polRequest = GetPolicyRequest.builder().policyArn(response.policy().arn()).build();
WaiterResponse<GetPolicyResponse> waitUntilPolicyExists = iamWaiter.waitUntilPolicyExists(polRequest);
waitUntilPolicyExists.matched().response().ifPresent(System.out::println);
return response.policy().arn();
} catch (IamException e) {
System.err.println(e.awsErrorDetails().errorMessage());
System.exit(1);
}
return "";
}
use of software.amazon.awssdk.services.iam.waiters.IamWaiter 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 "";
}
use of software.amazon.awssdk.services.iam.waiters.IamWaiter in project aws-doc-sdk-examples by awsdocs.
the class CreatePolicy method createIAMPolicy.
// snippet-start:[iam.java2.create_policy.main]
public static String createIAMPolicy(IamClient iam, String policyName) {
try {
// Create an IamWaiter object
IamWaiter iamWaiter = iam.waiter();
CreatePolicyRequest request = CreatePolicyRequest.builder().policyName(policyName).policyDocument(PolicyDocument).build();
CreatePolicyResponse response = iam.createPolicy(request);
// Wait until the policy is created
GetPolicyRequest polRequest = GetPolicyRequest.builder().policyArn(response.policy().arn()).build();
WaiterResponse<GetPolicyResponse> waitUntilPolicyExists = iamWaiter.waitUntilPolicyExists(polRequest);
waitUntilPolicyExists.matched().response().ifPresent(System.out::println);
return response.policy().arn();
} catch (IamException e) {
System.err.println(e.awsErrorDetails().errorMessage());
System.exit(1);
}
return "";
}
use of software.amazon.awssdk.services.iam.waiters.IamWaiter in project aws-doc-sdk-examples by awsdocs.
the class IAMScenario method createIAMUser.
public static Boolean createIAMUser(IamClient iam, String username) {
try {
// Create an IamWaiter object
IamWaiter iamWaiter = iam.waiter();
CreateUserRequest request = CreateUserRequest.builder().userName(username).build();
// Wait until the user is created.
CreateUserResponse response = iam.createUser(request);
GetUserRequest userRequest = GetUserRequest.builder().userName(response.user().userName()).build();
WaiterResponse<GetUserResponse> waitUntilUserExists = iamWaiter.waitUntilUserExists(userRequest);
waitUntilUserExists.matched().response().ifPresent(System.out::println);
return true;
} catch (IamException e) {
System.err.println(e.awsErrorDetails().errorMessage());
System.exit(1);
}
return false;
}
use of software.amazon.awssdk.services.iam.waiters.IamWaiter in project aws-doc-sdk-examples by awsdocs.
the class DemoUtils method createPersonalizeIamPolicy.
public static String createPersonalizeIamPolicy(IamClient iam, String policyName) {
String policyArn = getIamPolicyArn(iam, policyName);
if (policyArn != null) {
return policyArn;
}
try {
// Create an IamWaiter object
IamWaiter iamWaiter = iam.waiter();
CreatePolicyRequest request = CreatePolicyRequest.builder().policyName(policyName).policyDocument(PERSONALIZE_POLICY).build();
CreatePolicyResponse response = iam.createPolicy(request);
// Wait until the policy is created
GetPolicyRequest polRequest = GetPolicyRequest.builder().policyArn(response.policy().arn()).build();
WaiterResponse<GetPolicyResponse> waitUntilPolicyExists = iamWaiter.waitUntilPolicyExists(polRequest);
waitUntilPolicyExists.matched().response().ifPresent(System.out::println);
return response.policy().arn();
} catch (EntityAlreadyExistsException ex) {
return "";
} catch (IamException e) {
System.err.println(e.awsErrorDetails().errorMessage());
System.exit(1);
}
return "";
}
Aggregations