Search in sources :

Example 11 with IAMException

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

the class DetachRolePolicy method detachPolicy.

// snippet-start:[iam.java2.detach_role_policy.main]
public static void detachPolicy(IamClient iam, String roleName, String policyArn) {
    try {
        DetachRolePolicyRequest request = DetachRolePolicyRequest.builder().roleName(roleName).policyArn(policyArn).build();
        iam.detachRolePolicy(request);
        System.out.println("Successfully detached policy " + policyArn + " from role " + roleName);
    } catch (IamException e) {
        System.err.println(e.awsErrorDetails().errorMessage());
        System.exit(1);
    }
}
Also used : DetachRolePolicyRequest(software.amazon.awssdk.services.iam.model.DetachRolePolicyRequest) IamException(software.amazon.awssdk.services.iam.model.IamException)

Example 12 with IAMException

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

the class ListUsers method listAllUsers.

// snippet-start:[iam.java2.list_users.main]
public static void listAllUsers(IamClient iam) {
    try {
        boolean done = false;
        String newMarker = null;
        while (!done) {
            ListUsersResponse response;
            if (newMarker == null) {
                ListUsersRequest request = ListUsersRequest.builder().build();
                response = iam.listUsers(request);
            } else {
                ListUsersRequest request = ListUsersRequest.builder().marker(newMarker).build();
                response = iam.listUsers(request);
            }
            for (User user : response.users()) {
                System.out.format("\n Retrieved user %s", user.userName());
            }
            if (!response.isTruncated()) {
                done = true;
            } else {
                newMarker = response.marker();
            }
        }
    } catch (IamException e) {
        System.err.println(e.awsErrorDetails().errorMessage());
        System.exit(1);
    }
}
Also used : ListUsersRequest(software.amazon.awssdk.services.iam.model.ListUsersRequest) User(software.amazon.awssdk.services.iam.model.User) ListUsersResponse(software.amazon.awssdk.services.iam.model.ListUsersResponse) IamException(software.amazon.awssdk.services.iam.model.IamException)

Example 13 with IAMException

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

the class UpdateServerCertificate method updateCertificate.

// snippet-start:[iam.java2.update_server_certificate.main]
public static void updateCertificate(IamClient iam, String curName, String newName) {
    try {
        UpdateServerCertificateRequest request = UpdateServerCertificateRequest.builder().serverCertificateName(curName).newServerCertificateName(newName).build();
        UpdateServerCertificateResponse response = iam.updateServerCertificate(request);
        System.out.printf("Successfully updated server certificate to name %s", newName);
    } catch (IamException e) {
        System.err.println(e.awsErrorDetails().errorMessage());
        System.exit(1);
    }
}
Also used : IamException(software.amazon.awssdk.services.iam.model.IamException) UpdateServerCertificateRequest(software.amazon.awssdk.services.iam.model.UpdateServerCertificateRequest) UpdateServerCertificateResponse(software.amazon.awssdk.services.iam.model.UpdateServerCertificateResponse)

Example 14 with IAMException

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

the class GetPolicy method getIAMPolicy.

// snippet-start:[iam.java2.get_policy.main]
public static void getIAMPolicy(IamClient iam, String policyArn) {
    try {
        GetPolicyRequest request = GetPolicyRequest.builder().policyArn(policyArn).build();
        GetPolicyResponse response = iam.getPolicy(request);
        System.out.format("Successfully retrieved policy %s", response.policy().policyName());
    } catch (IamException e) {
        System.err.println(e.awsErrorDetails().errorMessage());
        System.exit(1);
    }
}
Also used : GetPolicyRequest(software.amazon.awssdk.services.iam.model.GetPolicyRequest) GetPolicyResponse(software.amazon.awssdk.services.iam.model.GetPolicyResponse) IamException(software.amazon.awssdk.services.iam.model.IamException)

Example 15 with IAMException

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

the class GetServerCertificate method getCertificate.

// snippet-start:[iam.java2.get_server_certificate.main]
public static void getCertificate(IamClient iam, String certName) {
    try {
        GetServerCertificateRequest request = GetServerCertificateRequest.builder().serverCertificateName(certName).build();
        GetServerCertificateResponse response = iam.getServerCertificate(request);
        System.out.format("Successfully retrieved certificate with body %s", response.serverCertificate().certificateBody());
    } catch (IamException e) {
        System.err.println(e.awsErrorDetails().errorMessage());
        System.exit(1);
    }
}
Also used : GetServerCertificateResponse(software.amazon.awssdk.services.iam.model.GetServerCertificateResponse) GetServerCertificateRequest(software.amazon.awssdk.services.iam.model.GetServerCertificateRequest) IamException(software.amazon.awssdk.services.iam.model.IamException)

Aggregations

IamException (software.amazon.awssdk.services.iam.model.IamException)24 AttachedPolicy (software.amazon.awssdk.services.iam.model.AttachedPolicy)3 GetPolicyRequest (software.amazon.awssdk.services.iam.model.GetPolicyRequest)3 GetPolicyResponse (software.amazon.awssdk.services.iam.model.GetPolicyResponse)3 IamWaiter (software.amazon.awssdk.services.iam.waiters.IamWaiter)3 AttachRolePolicyRequest (software.amazon.awssdk.services.iam.model.AttachRolePolicyRequest)2 CreatePolicyRequest (software.amazon.awssdk.services.iam.model.CreatePolicyRequest)2 CreatePolicyResponse (software.amazon.awssdk.services.iam.model.CreatePolicyResponse)2 EntityAlreadyExistsException (software.amazon.awssdk.services.iam.model.EntityAlreadyExistsException)2 ListAttachedRolePoliciesRequest (software.amazon.awssdk.services.iam.model.ListAttachedRolePoliciesRequest)2 ListAttachedRolePoliciesResponse (software.amazon.awssdk.services.iam.model.ListAttachedRolePoliciesResponse)2 IOException (java.io.IOException)1 DefaultParser (org.apache.commons.cli.DefaultParser)1 Options (org.apache.commons.cli.Options)1 ParseException (org.apache.commons.cli.ParseException)1 AccessKeyMetadata (software.amazon.awssdk.services.iam.model.AccessKeyMetadata)1 CreateAccessKeyRequest (software.amazon.awssdk.services.iam.model.CreateAccessKeyRequest)1 CreateAccessKeyResponse (software.amazon.awssdk.services.iam.model.CreateAccessKeyResponse)1 CreateAccountAliasRequest (software.amazon.awssdk.services.iam.model.CreateAccountAliasRequest)1 CreateRoleRequest (software.amazon.awssdk.services.iam.model.CreateRoleRequest)1