use of software.amazon.awssdk.services.iam.model.IAMException in project janusgraph by JanusGraph.
the class AwsCodePipelinesCi method main.
public static void main(String[] args) {
int status = 0;
try {
final Options options = new Options();
OPTIONS.forEach(options::addOption);
new AwsCodePipelinesCi(new DefaultParser().parse(options, args)).run();
} catch (ParseException | IllegalArgumentException e) {
log.error(e.getMessage(), e);
// EINVAL
status = 22;
} catch (IAMException e) {
log.error(e.getMessage(), e);
// EPERM
status = 1;
} catch (Exception e) {
log.error(e.getMessage(), e);
// EAGAIN
status = 11;
}
System.exit(status);
}
use of software.amazon.awssdk.services.iam.model.IAMException in project aws-doc-sdk-examples by awsdocs.
the class DemoUtils method attachIamPolicyToRole.
public static void attachIamPolicyToRole(IamClient iam, String roleName, String policyArn) {
String policyName = policyArn.substring(policyArn.indexOf("/") + 1);
try {
ListAttachedRolePoliciesRequest request = ListAttachedRolePoliciesRequest.builder().roleName(roleName).build();
ListAttachedRolePoliciesResponse response = iam.listAttachedRolePolicies(request);
List<AttachedPolicy> attachedPolicies = response.attachedPolicies();
// Ensure that the policy is not attached to this role
String polArn;
for (AttachedPolicy policy : attachedPolicies) {
polArn = policy.policyArn();
if (polArn.compareTo(policyArn) == 0) {
System.out.println("The " + policyName + " policy is already attached to this role.");
return;
}
}
AttachRolePolicyRequest attachRequest = AttachRolePolicyRequest.builder().roleName(roleName).policyArn(policyArn).build();
iam.attachRolePolicy(attachRequest);
System.out.println("Successfully attached policy " + policyArn + " to role " + roleName);
} catch (IamException e) {
System.err.println(e.awsErrorDetails().errorMessage());
System.exit(1);
}
System.out.println("Done");
}
use of software.amazon.awssdk.services.iam.model.IAMException in project aws-doc-sdk-examples by awsdocs.
the class AccessKeyLastUsed method getAccessKeyLastUsed.
// snippet-start:[iam.java2.access_key_last_used.main]
public static void getAccessKeyLastUsed(IamClient iam, String accessId) {
try {
GetAccessKeyLastUsedRequest request = GetAccessKeyLastUsedRequest.builder().accessKeyId(accessId).build();
GetAccessKeyLastUsedResponse response = iam.getAccessKeyLastUsed(request);
System.out.println("Access key was last used at: " + response.accessKeyLastUsed().lastUsedDate());
} catch (IamException e) {
System.err.println(e.awsErrorDetails().errorMessage());
System.exit(1);
}
System.out.println("Done");
}
use of software.amazon.awssdk.services.iam.model.IAMException in project aws-doc-sdk-examples by awsdocs.
the class AttachRolePolicy method attachIAMRolePolicy.
// snippet-start:[iam.java2.attach_role_policy.main]
public static void attachIAMRolePolicy(IamClient iam, String roleName, String policyArn) {
try {
ListAttachedRolePoliciesRequest request = ListAttachedRolePoliciesRequest.builder().roleName(roleName).build();
ListAttachedRolePoliciesResponse response = iam.listAttachedRolePolicies(request);
List<AttachedPolicy> attachedPolicies = response.attachedPolicies();
// Ensure that the policy is not attached to this role
String polArn = "";
for (AttachedPolicy policy : attachedPolicies) {
polArn = policy.policyArn();
if (polArn.compareTo(policyArn) == 0) {
System.out.println(roleName + " policy is already attached to this role.");
return;
}
}
// snippet-start:[iam.java2.attach_role_policy.attach]
AttachRolePolicyRequest attachRequest = AttachRolePolicyRequest.builder().roleName(roleName).policyArn(policyArn).build();
iam.attachRolePolicy(attachRequest);
// snippet-end:[iam.java2.attach_role_policy.attach]
System.out.println("Successfully attached policy " + policyArn + " to role " + roleName);
} catch (IamException e) {
System.err.println(e.awsErrorDetails().errorMessage());
System.exit(1);
}
System.out.println("Done");
}
use of software.amazon.awssdk.services.iam.model.IAMException in project aws-doc-sdk-examples by awsdocs.
the class CreateAccountAlias method createIAMAccountAlias.
// snippet-start:[iam.java2.create_account_alias.main]
public static void createIAMAccountAlias(IamClient iam, String alias) {
try {
CreateAccountAliasRequest request = CreateAccountAliasRequest.builder().accountAlias(alias).build();
iam.createAccountAlias(request);
System.out.println("Successfully created account alias: " + alias);
} catch (IamException e) {
System.err.println(e.awsErrorDetails().errorMessage());
System.exit(1);
}
}
Aggregations