Services or capabilities described in Amazon Web Services documentation might vary by Region. To see the differences applicable to the China Regions,
see Getting Started with Amazon Web Services in China
(PDF).
Use ListEntitiesForPolicy
with an Amazon SDK or command line tool
The following code examples show how to use ListEntitiesForPolicy
.
- CLI
-
- Amazon CLI
-
To list all users, groups, and roles that the specified managed policy is attached to
This example returns a list of IAM groups, roles, and users who have the policy arn:aws:iam::123456789012:policy/TestPolicy
attached.
aws iam list-entities-for-policy \
--policy-arn arn:aws:iam::123456789012:policy/TestPolicy
Output:
{
"PolicyGroups": [
{
"GroupName": "Admins",
"GroupId": "AGPACKCEVSQ6C2EXAMPLE"
}
],
"PolicyUsers": [
{
"UserName": "Alice",
"UserId": "AIDACKCEVSQ6C2EXAMPLE"
}
],
"PolicyRoles": [
{
"RoleName": "DevRole",
"RoleId": "AROADBQP57FF2AEXAMPLE"
}
],
"IsTruncated": false
}
For more information, see Policies and permissions in IAM in the Amazon IAM User Guide.
- PowerShell
-
- Tools for PowerShell
-
Example 1: This example returns a list of IAM groups, roles, and users who have the policy arn:aws:iam::123456789012:policy/TestPolicy
attached.
Get-IAMEntitiesForPolicy -PolicyArn "arn:aws:iam::123456789012:policy/TestPolicy"
Output:
IsTruncated : False
Marker :
PolicyGroups : {}
PolicyRoles : {testRole}
PolicyUsers : {Bob, Theresa}
For a complete list of Amazon SDK developer guides and code examples, see
Using IAM with an Amazon SDK.
This topic also includes information about getting started and details about previous SDK versions.