Z
Z
zugzug2014-11-15 13:15:04
API
zugzug, 2014-11-15 13:15:04

How to get a list of IAM Roles available to an account via the Amazon EC2 API?

Hello. I ask the help of specialists in Amazon EC2. Is there a way to get the list of IAM roles entered in the EC2 console via Java SDK or Amazon EC2 API (normal queries)? Thank you.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Z
zugzug, 2014-11-15
@zugzug

public Collection<String> getIAMRolesRange() {
        AmazonIdentityManagementClient identityManagementClient = new AmazonIdentityManagementClient(new BasicAWSCredentials(awsAccount.getAccessKeyId(), awsAccount.getAccessSecret()));
        ListInstanceProfilesResult listInstanceProfilesResult = identityManagementClient.listInstanceProfiles();
        List<String> iamRoles = new LinkedList<String>();
        for(InstanceProfile instanceProfile: listInstanceProfilesResult.getInstanceProfiles()) {
            iamRoles.addAll(Collections2.transform(instanceProfile.getRoles(), iamRoleToStringFunction));
        }

        return iamRoles;
    }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question