use of software.amazon.awssdk.services.iam.model.IAMException 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.model.IAMException in project aws-doc-sdk-examples by awsdocs.
the class DeleteServerCertificate method deleteCert.
// snippet-start:[iam.java2.delete_server_certificate.main]
public static void deleteCert(IamClient iam, String certName) {
try {
DeleteServerCertificateRequest request = DeleteServerCertificateRequest.builder().serverCertificateName(certName).build();
iam.deleteServerCertificate(request);
System.out.println("Successfully deleted server certificate " + certName);
} catch (IamException e) {
System.err.println(e.awsErrorDetails().errorMessage());
System.exit(1);
}
}
use of software.amazon.awssdk.services.iam.model.IAMException 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 "";
}
use of software.amazon.awssdk.services.iam.model.IAMException 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.model.IAMException in project aws-doc-sdk-examples by awsdocs.
the class DeleteAccountAlias method deleteIAMAccountAlias.
// snippet-start:[iam.java2.delete_account_alias.main]
public static void deleteIAMAccountAlias(IamClient iam, String alias) {
try {
DeleteAccountAliasRequest request = DeleteAccountAliasRequest.builder().accountAlias(alias).build();
iam.deleteAccountAlias(request);
System.out.println("Successfully deleted account alias " + alias);
} catch (IamException e) {
System.err.println(e.awsErrorDetails().errorMessage());
System.exit(1);
}
System.out.println("Done");
}
Aggregations