AWS 文檔 AWS SDK示例 GitHub 回購中有更多SDK示例
本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。
搭ListUserPolicies
配 AWS SDK或使用 CLI
下列程式碼範例會示範如何使用ListUserPolicies
。
- CLI
-
- AWS CLI
-
若要列出IAM使用者的策略
下列
list-user-policies
命令會列出附加至名為之IAM使用者的策略Bob
。aws iam list-user-policies \ --user-name
Bob
輸出:
{ "PolicyNames": [ "ExamplePolicy", "TestPolicy" ] }
如需詳細資訊,請參閱《IAM使用指南》中的「在您的 AWS 帳戶中建立AWS IAM使用者」。
-
如需詳API細資訊,請參閱AWS CLI 指令參考ListUserPolicies
中的。
-
- Go
-
- SDK對於轉到 V2
-
注意
還有更多關於 GitHub。尋找完整範例,並了解如何在 AWS 程式碼範例儲存庫
中設定和執行。 // 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細資訊,請參閱AWS SDK for Go API參考ListUserPolicies
中的。
-
- PowerShell
-
- 適用的工具 PowerShell
-
範例 1:此範例會擷取內嵌在名為之IAM使用者中的內嵌原則名稱清單
David
。Get-IAMUserPolicyList -UserName David
輸出:
Davids_IAM_Admin_Policy
-
如需詳API細資訊,請參閱AWS Tools for PowerShell 指令程ListUserPolicies式參考中的。
-
ListSigningCertificates
ListUserTags