将 ListUserPolicies 与 Amazon SDK 或命令行工具配合使用 - Amazon Identity and Access Management
Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅 中国的 Amazon Web Services 服务入门 (PDF)

ListUserPolicies 与 Amazon SDK 或命令行工具配合使用

以下代码示例演示如何使用 ListUserPolicies

CLI
Amazon CLI

要列出 IAM 用户的策略

以下 list-user-policies 命令将列出附加到名为 Bob 的 IAM 用户的策略。

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

输出:

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

有关更多信息,请参阅《Amazon IAM 用户指南》中的在 Amazon 账户中创建 IAM 用户

  • 有关 API 详细信息,请参阅《Amazon CLI 命令参考》中的 ListUserPolicies

Go
适用于 Go V2 的 SDK
注意

查看 GitHub,了解更多信息。查找完整示例,学习如何在 Amazon 代码示例存储库中进行设置和运行。

// 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 }
  • 有关 API 详细信息,请参阅《Amazon SDK for Go API 参考》中的 ListUserPolicies

PowerShell
适用于 PowerShell 的工具

示例 1:此示例检索嵌入在名为 David 的 IAM 用户中的内联策略名称列表。

Get-IAMUserPolicyList -UserName David

输出:

Davids_IAM_Admin_Policy
  • 有关 API 详细信息,请参阅《Amazon Tools for PowerShell Cmdlet 参考》中的 ListUserPolicies

有关 Amazon SDK 开发人员指南和代码示例的完整列表,请参阅 将 IAM 与 Amazon 开发工具包配合使用。本主题还包括有关入门的信息以及有关先前的 SDK 版本的详细信息。