

Doc AWS SDK Examples GitHub リポジトリには、他にも SDK の例があります。 [AWS](https://github.com/awsdocs/aws-doc-sdk-examples)

翻訳は機械翻訳により提供されています。提供された翻訳内容と英語版の間で齟齬、不一致または矛盾がある場合、英語版が優先します。

# AWS SDK または CLI `ListUserPolicies`で を使用する
<a name="iam_example_iam_ListUserPolicies_section"></a>

次のサンプルコードは、`ListUserPolicies` を使用する方法を説明しています。

------
#### [ CLI ]

**AWS CLI**  
**IAM ユーザーのポリシーを一覧表示するには**  
次の `list-user-policies` コマンドは、`Bob` という名前の IAM ユーザーにアタッチされているポリシーを一覧表示します。  

```
aws iam list-user-policies \
    --user-name Bob
```
出力:  

```
{
    "PolicyNames": [
        "ExamplePolicy",
        "TestPolicy"
    ]
}
```
詳細については、[「IAM ユーザーガイド」の AWS 「アカウントでの IAM ユーザーの作成](https://docs.aws.amazon.com/IAM/latest/UserGuide/id_users_create.html)」を参照してください。 *AWS *  
+  API の詳細については、「AWS CLI API リファレンス」の「[ListUserPolicies](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/iam/list-user-policies.html)」を参照してください。

------
#### [ Go ]

**SDK for Go V2**  
 GitHub には、その他のリソースもあります。用例一覧を検索し、[AWS コード例リポジトリ](https://github.com/awsdocs/aws-doc-sdk-examples/tree/main/gov2/iam#code-examples)での設定と実行の方法を確認してください。

```
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
}
```
+  API の詳細については、「*AWS SDK for Go API リファレンス*」の「[ListUserPolicies](https://pkg.go.dev/github.com/aws/aws-sdk-go-v2/service/iam#Client.ListUserPolicies)」を参照してください。

------
#### [ PowerShell ]

**Tools for PowerShell V4**  
**例 1: この例では、`David` という名前の IAM ユーザーに埋め込まれているインラインポリシーの名前のリストを取得します。**  

```
Get-IAMUserPolicyList -UserName David
```
**出力:**  

```
Davids_IAM_Admin_Policy
```
+  API の詳細については、*AWS Tools for PowerShell コマンドレットリファレンス (V4)* の「[ListUserPolicies](https://docs.aws.amazon.com/powershell/v4/reference)」を参照してください。

**Tools for PowerShell V5**  
**例 1: この例では、`David` という名前の IAM ユーザーに埋め込まれているインラインポリシーの名前のリストを取得します。**  

```
Get-IAMUserPolicyList -UserName David
```
**出力:**  

```
Davids_IAM_Admin_Policy
```
+  API の詳細については、AWS Tools for PowerShell コマンドレットリファレンス (V5) の「[ListUserPolicies](https://docs.aws.amazon.com/powershell/v5/reference)」を参照してください。**

------