

# AWS CLI を使用した Amazon Cognito ID の例
<a name="cli_cognito-identity_code_examples"></a>

次のコード例は、Amazon Cognito ID で AWS Command Line Interface を使用してアクションを実行し、一般的なシナリオを実装する方法を示しています。

*アクション*はより大きなプログラムからのコードの抜粋であり、コンテキスト内で実行する必要があります。アクションは個々のサービス機能を呼び出す方法を示していますが、コンテキスト内のアクションは、関連するシナリオで確認できます。

各例には完全なソースコードへのリンクが含まれており、コードの設定方法と実行方法に関する手順を確認できます。

**Topics**
+ [アクション](#actions)

## アクション
<a name="actions"></a>

### `create-identity-pool`
<a name="cognito-identity_CreateIdentityPool_cli_topic"></a>

次のコード例は、`create-identity-pool` を使用する方法を示しています。

**AWS CLI**  
**Cognito アイデンティティプールプロバイダーを含むアイデンティティプールを作成するには**  
この例では MyIdentityPool という名前のアイデンティティプールを作成します。これには Cognito アイデンティティプールプロバイダーが含まれます。認証されていないアイデンティティは許可されません。  
コマンド:  

```
aws cognito-identity create-identity-pool --identity-pool-name MyIdentityPool --no-allow-unauthenticated-identities --cognito-identity-providers ProviderName="cognito-idp.us-west-2.amazonaws.com/us-west-2_aaaaaaaaa",ClientId="3n4b5urk1ft4fl3mg5e62d9ado",ServerSideTokenCheck=false
```
出力:  

```
{
  "IdentityPoolId": "us-west-2:11111111-1111-1111-1111-111111111111",
  "IdentityPoolName": "MyIdentityPool",
  "AllowUnauthenticatedIdentities": false,
  "CognitoIdentityProviders": [
      {
          "ProviderName": "cognito-idp.us-west-2.amazonaws.com/us-west-2_111111111",
          "ClientId": "3n4b5urk1ft4fl3mg5e62d9ado",
          "ServerSideTokenCheck": false
      }
  ]
}
```
+  API の詳細については、「*AWS CLI コマンドリファレンス*」の「[CreateIdentityPool](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/cognito-identity/create-identity-pool.html)」を参照してください。

### `delete-identities`
<a name="cognito-identity_DeleteIdentities_cli_topic"></a>

次のコード例は、`delete-identities` を使用する方法を示しています。

**AWS CLI**  
**アイデンティティプールを削除するには**  
この例ではアイデンティティプールを削除しています。  
コマンド:  

```
aws cognito-identity delete-identity-pool --identity-ids-to-delete "us-west-2:11111111-1111-1111-1111-111111111111"
```
出力:  

```
{
  "UnprocessedIdentityIds": []
}
```
+  API の詳細については、「*AWS CLI コマンドリファレンス*」の「[DeleteIdentities](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/cognito-identity/delete-identities.html)」を参照してください。

### `delete-identity-pool`
<a name="cognito-identity_DeleteIdentityPool_cli_topic"></a>

次のコード例は、`delete-identity-pool` を使用する方法を示しています。

**AWS CLI**  
**アイデンティティプールを削除するには**  
次の `delete-identity-pool` 例では、指定したアイデンティティプールを削除します。  
コマンド:  

```
aws cognito-identity delete-identity-pool \
    --identity-pool-id "us-west-2:11111111-1111-1111-1111-111111111111"
```
このコマンドでは何も出力されません。  
+  API の詳細については、AWS CLI コマンドリファレンスの「[DeleteIdentityPool](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/cognito-identity/delete-identity-pool.html)」を参照してください。**

### `describe-identity-pool`
<a name="cognito-identity_DescribeIdentityPool_cli_topic"></a>

次のコード例は、`describe-identity-pool` を使用する方法を示しています。

**AWS CLI**  
**アイデンティティプールを記述するには**  
この例では、アイデンティティプールをを記述します。  
コマンド:  

```
aws cognito-identity describe-identity-pool --identity-pool-id "us-west-2:11111111-1111-1111-1111-111111111111"
```
出力:  

```
{
  "IdentityPoolId": "us-west-2:11111111-1111-1111-1111-111111111111",
  "IdentityPoolName": "MyIdentityPool",
  "AllowUnauthenticatedIdentities": false,
  "CognitoIdentityProviders": [
      {
          "ProviderName": "cognito-idp.us-west-2.amazonaws.com/us-west-2_111111111",
          "ClientId": "3n4b5urk1ft4fl3mg5e62d9ado",
          "ServerSideTokenCheck": false
      }
  ]
}
```
+  API の詳細については、「*AWS CLI コマンドリファレンス*」の「[DescribeIdentityPool](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/cognito-identity/describe-identity-pool.html)」を参照してください。

### `get-identity-pool-roles`
<a name="cognito-identity_GetIdentityPoolRoles_cli_topic"></a>

次のコード例は、`get-identity-pool-roles` を使用する方法を示しています。

**AWS CLI**  
**アイデンティティプールのロールを取得するには**  
この例ではアイデンティティプールのロールを取得しています。  
コマンド:  

```
aws cognito-identity get-identity-pool-roles --identity-pool-id "us-west-2:11111111-1111-1111-1111-111111111111"
```
出力:  

```
{
  "IdentityPoolId": "us-west-2:11111111-1111-1111-1111-111111111111",
  "Roles": {
      "authenticated": "arn:aws:iam::111111111111:role/Cognito_MyIdentityPoolAuth_Role",
      "unauthenticated": "arn:aws:iam::111111111111:role/Cognito_MyIdentityPoolUnauth_Role"
  }
}
```
+  API の詳細については、「*AWS CLI コマンドリファレンス*」の「[GetIdentityPoolRoles](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/cognito-identity/get-identity-pool-roles.html)」を参照してください。

### `list-identity-pools`
<a name="cognito-identity_ListIdentityPools_cli_topic"></a>

次のコード例は、`list-identity-pools` を使用する方法を示しています。

**AWS CLI**  
**アイデンティティプールを一覧表示するには**  
この例ではアイデンティティプールを一覧表示します。最大 20 個のアイデンティティが一覧表示されます。  
コマンド:  

```
aws cognito-identity list-identity-pools --max-results 20
```
出力:  

```
{
  "IdentityPools": [
      {
          "IdentityPoolId": "us-west-2:11111111-1111-1111-1111-111111111111",
          "IdentityPoolName": "MyIdentityPool"
      },
      {
          "IdentityPoolId": "us-west-2:11111111-1111-1111-1111-111111111111",
          "IdentityPoolName": "AnotherIdentityPool"
      },
      {
          "IdentityPoolId": "us-west-2:11111111-1111-1111-1111-111111111111",
          "IdentityPoolName": "IdentityPoolRegionA"
      }
  ]
}
```
+  API の詳細については、「*AWS CLI コマンドリファレンス*」の「[ListIdentityPools](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/cognito-identity/list-identity-pools.html)」を参照してください。

### `set-identity-pool-roles`
<a name="cognito-identity_SetIdentityPoolRoles_cli_topic"></a>

次のコード例は、`set-identity-pool-roles` を使用する方法を示しています。

**AWS CLI**  
**アイデンティティプールのロールを設定するには**  
次の `set-identity-pool-roles` の例では、アイデンティティプールのロールを設定しています。  

```
aws cognito-identity set-identity-pool-roles \
    --identity-pool-id "us-west-2:11111111-1111-1111-1111-111111111111" \
    --roles authenticated="arn:aws:iam::111111111111:role/Cognito_MyIdentityPoolAuth_Role"
```
+  API の詳細については、「*AWS CLI コマンドリファレンス*」の「[SetIdentityPoolRoles](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/cognito-identity/set-identity-pool-roles.html)」を参照してください。

### `update-identity-pool`
<a name="cognito-identity_UpdateIdentityPool_cli_topic"></a>

次のコード例は、`update-identity-pool` を使用する方法を示しています。

**AWS CLI**  
**アイデンティティプールを更新するには**  
この例では、アイデンティティプールを更新しています。名前を「MyIdentityPool」に設定します。Cognito をアイデンティティプロバイダとして追加します。認証されていないアイデンティティは許可されません。  
コマンド:  

```
aws cognito-identity update-identity-pool --identity-pool-id "us-west-2:11111111-1111-1111-1111-111111111111" --identity-pool-name "MyIdentityPool" --no-allow-unauthenticated-identities --cognito-identity-providers ProviderName="cognito-idp.us-west-2.amazonaws.com/us-west-2_111111111",ClientId="3n4b5urk1ft4fl3mg5e62d9ado",ServerSideTokenCheck=false
```
出力:  

```
{
  "IdentityPoolId": "us-west-2:11111111-1111-1111-1111-111111111111",
  "IdentityPoolName": "MyIdentityPool",
  "AllowUnauthenticatedIdentities": false,
  "CognitoIdentityProviders": [
      {
          "ProviderName": "cognito-idp.us-west-2.amazonaws.com/us-west-2_111111111",
          "ClientId": "3n4b5urk1ft4fl3mg5e62d9ado",
          "ServerSideTokenCheck": false
      }
  ]
}
```
+  API の詳細については、「*AWS CLI コマンドリファレンス*」の「[UpdateIdentityPool](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/cognito-identity/update-identity-pool.html)」を参照してください。