Select your cookie preferences

We use essential cookies and similar tools that are necessary to provide our site and services. We use performance cookies to collect anonymous statistics, so we can understand how customers use our site and make improvements. Essential cookies cannot be deactivated, but you can choose “Customize” or “Decline” to decline performance cookies.

If you agree, AWS and approved third parties will also use cookies to provide useful site features, remember your preferences, and display relevant content, including relevant advertising. To accept or decline all non-essential cookies, choose “Accept” or “Decline.” To make more detailed choices, choose “Customize.”

Use ListUserPolicies with an AWS SDK or CLI

Focus mode
Use ListUserPolicies with an AWS SDK or CLI - AWS Identity and Access Management

The following code examples show how to use ListUserPolicies.

CLI
AWS 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 AWS account in the AWS 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 AWS Code Examples Repository.

import ( "context" "encoding/json" "errors" "log" "github.com/aws/aws-sdk-go-v2/aws" "github.com/aws/aws-sdk-go-v2/service/iam" "github.com/aws/aws-sdk-go-v2/service/iam/types" "github.com/aws/smithy-go" ) // 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(ctx context.Context, userName string) ([]string, error) { var policies []string result, err := wrapper.IamClient.ListUserPolicies(ctx, &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 AWS Tools for PowerShell Cmdlet Reference.

AWS 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 AWS account in the AWS IAM User Guide.

For a complete list of AWS SDK developer guides and code examples, see Using this service with an AWS SDK. This topic also includes information about getting started and details about previous SDK versions.

PrivacySite termsCookie preferences
© 2025, Amazon Web Services, Inc. or its affiliates. All rights reserved.