Use ListUserPolicies with an Amazon SDK or CLI - Amazon Identity and Access Management
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 ListUserPolicies with an Amazon SDK or CLI

The following code examples show how to use ListUserPolicies.

CLI
Amazon CLI

To list policies for an IAM user

The following list-user-policies command lists the policies that are attached to the IAM user named Bob.

aws iam list-user-policies \ --user-name Bob

Output:

{ "PolicyNames": [ "ExamplePolicy", "TestPolicy" ] }

For more information, see Creating an IAM user in your Amazon account in the Amazon IAM User Guide.

Go
SDK for Go V2
Note

There's more on GitHub. Find the complete example and learn how to set up and run in the Amazon Code Examples Repository.

// UserWrapper encapsulates user actions used in the examples. // It contains an IAM service client that is used to perform user actions. type UserWrapper struct { IamClient *iam.Client } // ListUserPolicies lists the inline policies for the specified user. func (wrapper UserWrapper) ListUserPolicies(userName string) ([]string, error) { var policies []string result, err := wrapper.IamClient.ListUserPolicies(context.TODO(), &iam.ListUserPoliciesInput{ UserName: aws.String(userName), }) if err != nil { log.Printf("Couldn't list policies for user %v. Here's why: %v\n", userName, err) } else { policies = result.PolicyNames } return policies, err }
PowerShell
Tools for PowerShell

Example 1: This example retrieves the list of names of the inline policies that are embedded in the IAM user named David.

Get-IAMUserPolicyList -UserName David

Output:

Davids_IAM_Admin_Policy
  • For API details, see ListUserPolicies in Amazon Tools for PowerShell Cmdlet Reference.

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.