

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

# Amazon Cognito リソースのタグ付け
<a name="tagging"></a>

*タグ*は、 リソース AWS に割り当てるメタデータラベルです AWS 。各タグは、*キー*と*値*から構成されます。ユーザーが割り当てるタグでは、ユーザーがキーと値を定義します。たとえば、1 つのリソースのキーを `stage` と定義し、値を `test` と定義します。

タグは、以下のことに役立ちます。
+  AWS リソースを特定して整理します。多くの AWS サービスはタグ付けをサポートしているため、異なるサービスのリソースに同じタグを割り当てることができます。タグは、どのリソースが関連しているかを示すのに役立ちます。例えば、Amazon DynamoDB テーブルに割り当てるタグと同じものを Amazon Cognito ユーザープールに割り当てることができます。
+  AWS コストを追跡します。 AWS Billing and Cost Management ダッシュボードでこれらのタグをアクティブ化できます。 AWS はコスト配分タグを使用してコストを分類し、毎月のコスト配分レポートを配信します。詳細については、*「AWS Billing ユーザーガイド」*の[「Use cost allocation tags」](https://docs.aws.amazon.com/awsaccountbilling/latest/aboutv2/cost-alloc-tags.html)(コスト配分タグの使用) を参照してください。
+ リソースに割り当てられたタグに基づいて、リソースへのアクセスをコントロールします。 AWS Identity and Access Management (IAM) ポリシーの条件でキーと値を指定することによってアクセスをコントロールできます。例えば、ユーザープールの更新をユーザーに許可しても、そのユーザープールに `owner` タグと、そのユーザーの名前の値がある場合のみに限定することができます。詳細については、*IAM ユーザーガイド*の「[タグを使用したアクセス制御](https://docs.aws.amazon.com/IAM/latest/UserGuide/access_tags.html)」を参照してください。

 AWS Command Line Interface または Amazon Cognito API を使用して、ユーザープールと ID プールの両方のタグを追加、編集、または削除できます。Amazon Cognito コンソールを使用して、ユーザープールのタグを管理することもできます。

タグの使用方法のヒントについては、*AWS の回答*ブログの[AWS タグ付け戦略](https://aws.amazon.com/answers/account-management/aws-tagging-strategies/)記事を参照してください。

以下のセクションでは、Amazon Cognito のタグに関する詳細が説明されています。

## Amazon Cognito でサポートされるリソース
<a name="tagging-supported-resources"></a>

Amazon Cognito の以下のリソースがタグ付けをサポートしています。
+ ユーザープール
+ ID プール

## タグの制限
<a name="tagging-restrictions"></a>

Amazon Cognito リソースのタグには、以下の制限が適用されます。
+ リソースに割り当てることができるタグの最大数: 50 
+ キーの最大長 – 128 文字 (Unicode) 
+ 値の最大長 – 256 文字 (Unicode) 
+ キーと値の有効な文字 – a～z、A～Z、0～9、スペース、および特殊文字 (\$1 . : / = \$1 - @)
+ キーと値では大文字と小文字が区別されます
+ `aws:` をキーのプレフィックスとして使用しないでください。 AWS 用に予約済みです。

## Amazon Cognito コンソールを使用したタグの管理
<a name="tagging-console"></a>

Amazon Cognito コンソールを使用して、ユーザープールに割り当てられたタグを管理することができます。

**ユーザープールにタグを追加するには**

1. [[Amazon Cognito console]](https://console.aws.amazon.com/cognito/home) (Amazon Connect コンソール) に移動します。プロンプトが表示されたら、 AWS 認証情報を入力します。

1. **[User Pools]** (ユーザープール) を選択します。

1. リストから既存のユーザープールを選択するか、[ユーザープールを作成](https://docs.aws.amazon.com/cognito/latest/developerguide/cognito-user-pool-as-user-directory.html)します。

1. **[設定]** メニューを選択し、**[タグ]** タブを見つけます。

1. **[Add tags]** (タグを追加する) を選択し、最初のタグを追加します。以前このユーザープールにタグを割り当てたことがある場合は、**[Manage tags]** (タグの管理) を選び、**[Add another]** (別のタグを追加) を選択します。

1. **[Tag Key]** (タグキー) と **[Tag Value]**] (タグ値) に値を入力します。

1. 追加するタグごとに、**[Add another tag]** (別のタグを追加) を選択します。

1. タグの追加を完了したら、**[Save changes]** (変更の保存) を選択します。

アイデンティティプールにタグを付けるには、**[ID プール]** メニューに移動し、アイデンティティプールを選択または作成します。**[ID プールのプロパティ]** タブで、**[タグ]** を見つけます。**[タグを追加]** を選択します。

## AWS CLI 例
<a name="tagging-cli-examples"></a>

 AWS CLI には、Amazon Cognito ユーザープールと ID プールに割り当てるタグの管理に役立つコマンドが用意されています。

### タグの割り当て
<a name="tagging-cli-examples-assigning"></a>

次のコマンドを使用して、既存のユーザープールと ID プールにタグを割り当てます。

**Example `tag-resource` ユーザープール向けのコマンド**  
コマンドの `cognito-idp` セット内の [https://docs.aws.amazon.com/cli/latest/reference/cognito-idp/tag-resource.html](https://docs.aws.amazon.com/cli/latest/reference/cognito-idp/tag-resource.html) 使用して、ユーザープールにタグを割り当てます。  

```
$ aws cognito-idp tag-resource \
> --resource-arn user-pool-arn \
> --tags Stage=Test
```
このコマンドには次のパラメータが含まれます。  
+ `resource-arn` – タグを割り当てるユーザープールの Amazon リソースネーム (ARN)。ARN を調べるには、Amazon Cognito コンソールでユーザープールを選択し、**[General settings]** (一般設定) タブの **[Pool ARN]** (プール ARN) 値を表示します。
+ `tags` — 形式`key=value`のタグのキーバリューペアです。
一度に複数のタグを割り当てるには、カンマ区切りリストで指定します。  

```
$ aws cognito-idp tag-resource \
> --resource-arn user-pool-arn \
> --tags Stage=Test,CostCenter=80432,Owner=SysEng
```

**Example `tag-resource` ID プール向けのコマンド**  
コマンドの `cognito-identity` セット内の [https://docs.aws.amazon.com/cli/latest/reference/cognito-identity/tag-resource.html](https://docs.aws.amazon.com/cli/latest/reference/cognito-identity/tag-resource.html) 使用して、ID プールにタグを割り当てます。  

```
$ aws cognito-identity tag-resource \
> --resource-arn identity-pool-arn \
> --tags Stage=Test
```
このコマンドには次のパラメータが含まれます。  
+ `resource-arn` – タグを割り当てる ID プールの Amazon リソースネーム (ARN)。ARN を調べるには、Amazon Cognito コンソールで ID プールを選択し、**[Edit identity pool]** (ID プールの編集) をクリックします。その後、**[Identity pool ID]** (ID プールの ID) で **[Show ARN]** (ARN の表示) をクリックします。
+ `tags` — 形式`key=value`のタグのキーバリューペアです。
一度に複数のタグを割り当てるには、カンマ区切りリストで指定します。  

```
$ aws cognito-identity tag-resource \
> --resource-arn identity-pool-arn \
> --tags Stage=Test,CostCenter=80432,Owner=SysEng
```

### タグの表示
<a name="tagging-cli-examples-viewing"></a>

次のコマンドを使用して、ユーザープールと ID プールに割り当てたタグを表示します。

**Example `list-tags-for-resource` ユーザープール向けのコマンド**  
コマンドの `cognito-idp` セット内の [https://docs.aws.amazon.com/cli/latest/reference/cognito-idp/list-tags-for-resource.html](https://docs.aws.amazon.com/cli/latest/reference/cognito-idp/list-tags-for-resource.html) 使用して、ユーザープールにタグを割り当てます。  

```
$ aws cognito-idp list-tags-for-resource --resource-arn user-pool-arn
```

**Example `list-tags-for-resource` ID プール向けのコマンド**  
コマンドの `cognito-identity` セット内の [https://docs.aws.amazon.com/cli/latest/reference/cognito-identity/list-tags-for-resource.html](https://docs.aws.amazon.com/cli/latest/reference/cognito-identity/list-tags-for-resource.html) 使用して、ID プールにタグを割り当てます。  

```
$ aws cognito-identity list-tags-for-resource --resource-arn identity-pool-arn
```

### タグの削除
<a name="tagging-cli-examples-removing"></a>

以下のコマンドを使用して、ユーザープールと ID プールからタグを削除します。

**Example `untag-resource` ユーザープール向けのコマンド**  
コマンドの `cognito-idp` セット内の [https://docs.aws.amazon.com/cli/latest/reference/cognito-idp/untag-resource.html](https://docs.aws.amazon.com/cli/latest/reference/cognito-idp/untag-resource.html) 使用して、ユーザープールにタグを割り当てます。  

```
$ aws cognito-idp untag-resource \
> --resource-arn user-pool-arn \
> --tag-keys Stage CostCenter Owner
```
`--tag-keys`パラメータには、1 つ以上のタグキーを指定します。タグ値は含みません。キーをスペースで区切ります。

**Example `untag-resource` ID プール向けのコマンド**  
コマンドの `cognito-identity` セット内の [https://docs.aws.amazon.com/cli/latest/reference/cognito-identity/untag-resource.html](https://docs.aws.amazon.com/cli/latest/reference/cognito-identity/untag-resource.html) 使用して、ID プールにタグを割り当てます。  

```
$ aws cognito-identity untag-resource \
> --resource-arn identity-pool-arn \
> --tag-keys Stage CostCenter Owner
```
`--tag-keys`パラメータには、1 つ以上のタグキーを指定します。タグ値は含みません。

**重要**  
ユーザーまたは ID プールの削除後、削除されたプールに関連するタグは、削除から最大 30 日までコンソールまたは API コールに表示できます。

### リソース作成時のタグの適用
<a name="tagging-cli-examples-applying"></a>

次のコマンドを使用して、ユーザープールまたは ID プールを作成するときにタグを割り当てます。

**Example `create-user-pool`コマンドとタグ**  
[https://docs.aws.amazon.com/cli/latest/reference/cognito-idp/create-user-pool.html](https://docs.aws.amazon.com/cli/latest/reference/cognito-idp/create-user-pool.html) コマンドを使用してユーザープールを作成するときは、`--user-pool-tags` パラメータと共にタグを指定できます。  

```
$ aws cognito-idp create-user-pool \
> --pool-name user-pool-name \
> --user-pool-tags Stage=Test,CostCenter=80432,Owner=SysEng
```
タグのキーバリューペアは、`key=value`形式が必須です。複数のタグを追加する場合は、カンマで区切りを付けたリストで指定します。

**Example `create-identity-pool` コマンドとタグ**  
[https://docs.aws.amazon.com/cli/latest/reference/cognito-identity/create-identity-pool.html](https://docs.aws.amazon.com/cli/latest/reference/cognito-identity/create-identity-pool.html) コマンドを使用して ID プールを作成するときは、`--identity-pool-tags` パラメータと共にタグを指定できます。  

```
$ aws cognito-identity create-identity-pool \
> --identity-pool-name identity-pool-name \
> --allow-unauthenticated-identities \
> --identity-pool-tags Stage=Test,CostCenter=80432,Owner=SysEng
```
タグのキーバリューペアは、`key=value`形式が必須です。複数のタグを追加する場合は、カンマで区切りを付けたリストで指定します。

## Amazon Cognito API を使用したタグの管理
<a name="tagging-api"></a>

以下のアクションを Amazon Cognito API で使用することで、ユーザープールと ID プールのタグを管理できます。

### ユーザープールタグの API アクション
<a name="tagging-api-user-pools"></a>

次の API アクションを使用して、ユーザープールのタグを割り当て、表示、削除します。
+ [TagResource](https://docs.aws.amazon.com/cognito-user-identity-pools/latest/APIReference/API_TagResource.html)
+ [ListTagsForResource](https://docs.aws.amazon.com/cognito-user-identity-pools/latest/APIReference/API_ListTagsForResource.html)
+ [UntagResource](https://docs.aws.amazon.com/cognito-user-identity-pools/latest/APIReference/API_UntagResource.html)
+ [CreateUserPool](https://docs.aws.amazon.com/cognito-user-identity-pools/latest/APIReference/API_CreateUserPool.html)

### ID プールタグの API アクション
<a name="tagging-api-identity-pools"></a>

次の API アクションを使用して、ID プールのタグを割り当て、表示、削除します。
+ [TagResource](https://docs.aws.amazon.com/cognitoidentity/latest/APIReference/API_TagResource.html)
+ [ListTagsForResource](https://docs.aws.amazon.com/cognitoidentity/latest/APIReference/API_ListTagsForResource.html)
+ [UntagResource](https://docs.aws.amazon.com/cognitoidentity/latest/APIReference/API_UntagResource.html)
+ [CreateIdentityPool](https://docs.aws.amazon.com/cognitoidentity/latest/APIReference/API_CreateIdentityPool.html)