Search in sources :

Example 1 with ListPoliciesRequest

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

the class DemoUtils method getIamPolicyArn.

private static String getIamPolicyArn(IamClient iamClient, String policyName) {
    try {
        ListPoliciesRequest listPoliciesRequest = ListPoliciesRequest.builder().build();
        ListPoliciesResponse listPoliciesResponse = iamClient.listPolicies(listPoliciesRequest);
        for (Policy policy : listPoliciesResponse.policies()) {
            if (policy.policyName().equals(policyName)) {
                return policy.arn();
            }
        }
    } catch (IamException e) {
        System.err.println(e.awsErrorDetails().errorMessage());
        System.exit(1);
    }
    return null;
}
Also used : ListPoliciesResponse(software.amazon.awssdk.services.iam.model.ListPoliciesResponse) AttachedPolicy(software.amazon.awssdk.services.iam.model.AttachedPolicy) Policy(software.amazon.awssdk.services.iam.model.Policy) ListPoliciesRequest(software.amazon.awssdk.services.iam.model.ListPoliciesRequest) IamException(software.amazon.awssdk.services.iam.model.IamException)

Aggregations

AttachedPolicy (software.amazon.awssdk.services.iam.model.AttachedPolicy)1 IamException (software.amazon.awssdk.services.iam.model.IamException)1 ListPoliciesRequest (software.amazon.awssdk.services.iam.model.ListPoliciesRequest)1 ListPoliciesResponse (software.amazon.awssdk.services.iam.model.ListPoliciesResponse)1 Policy (software.amazon.awssdk.services.iam.model.Policy)1