

# インスタンスプロファイルを使用する
<a name="id_roles_use_switch-role-ec2_instance-profiles"></a>

インスタンスプロファイルを使用して、IAM ロールを EC2 インスタンスに渡します。詳細については、[Amazon EC2 ユーザーガイド](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/iam-roles-for-amazon-ec2.html) の「*Amazon EC2 の IAM ロール*」を参照してください。

## インスタンスプロファイルの管理 (コンソール)
<a name="instance-profiles-manage-console"></a>

AWS マネジメントコンソール を使用して Amazon EC2 のロールを作成する場合、コンソールはインスタンスプロファイルを自動的に作成し、そのインスタンスプロファイルにロールと同じ名前を付けます。IAM ロールを使用してインスタンスを起動するのに Amazon EC2 コンソールを使用する場合、インスタンスに関連付けるロールを選択できます。コンソールに表示されるリストは実際にはインスタンスプロファイル名のリストです。コンソールでは、Amazon EC2 に関連付けられていないロールのインスタンスプロファイルは作成されません。

ロールとインスタンスプロファイルの名前が同じである場合は、AWS マネジメントコンソール を使用して Amazon EC2 の IAM ロールとインスタンスプロファイルを削除できます。インスタンスプロファイルの削除の詳細については、「[ロールまたはインスタンスプロファイルを削除する](id_roles_manage_delete.md)」を参照してください。

**注記**  
インスタンスのアクセス許可を更新するには、インスタンスプロファイルを置き換えます。この変更が有効になるまでに最大 1 時間の遅延が発生するため、インスタンスプロファイルからロールを削除することはお勧めしません。

## インスタンスプロファイルの管理 (AWS CLI または AWS API)
<a name="instance-profiles-manage-cli-api"></a>

AWS CLI または AWS API からロールを管理する場合、ロールとインスタンスプロファイルを別個のアクションとして作成します。ロールとインスタンスプロファイルには異なる名前を使用できるため、インスタンスプロファイルの名前とこれらのプロファイルに含まれるロールの名前を知っている必要があります。これにより、EC2 インスタンスを起動するときに適切なインスタンスプロファイルを選択できます。

IAM リソース (インスタンスプロファイルを含む) にタグをアタッチして、それらへのアクセスを特定、整理、制御することができます。インスタンスプロファイルにタグを付けることができるのは、AWS CLI または AWS API を使用する場合のみです。

**注記**  
インスタンスプロファイルに含めることができる IAM ロールは 1 つのみです。ただし、1 つのロールを複数のインスタンスプロファイルに含めることはできます。このインスタンスプロファイルあたり 1 ロールの制限は、緩和できません。既存のロールを削除してから、別のロールをインスタンスプロファイルに追加することはできます。その後、AWS 全体で変更が反映されるのを待つ必要があります。これは[結果整合性](https://en.wikipedia.org/wiki/Eventual_consistency)のためです。変更を強制的に実行するには、[インスタンスプロファイル](https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_DisassociateIamInstanceProfile.html)の関連付けを解除してから、[インスタンスプロファイルを関連付ける](https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_AssociateIamInstanceProfile.html)か、インスタンスを停止してから再起動します。

### インスタンスプロファイルの管理 (AWS CLI)
<a name="instance-profiles-manage-cli"></a>

AWS アカウントでインスタンスプロファイルを使用するには、以下の AWS CLI コマンドを使用できます。
+ インスタンスプロファイルを作成する: [https://docs.aws.amazon.com/cli/latest/reference/iam/create-instance-profile.html](https://docs.aws.amazon.com/cli/latest/reference/iam/create-instance-profile.html)
+ インスタンスプロファイルにタグを付ける: [https://docs.aws.amazon.com/cli/latest/reference/iam/tag-instance-profile.html](https://docs.aws.amazon.com/cli/latest/reference/iam/tag-instance-profile.html)
+ インスタンスプロファイルのタグを一覧表示する: [https://docs.aws.amazon.com/cli/latest/reference/iam/list-instance-profile-tags.html](https://docs.aws.amazon.com/cli/latest/reference/iam/list-instance-profile-tags.html)
+ インスタンスプロファイルのタグを解除する: [https://docs.aws.amazon.com/cli/latest/reference/iam/untag-instance-profile.html](https://docs.aws.amazon.com/cli/latest/reference/iam/untag-instance-profile.html)
+ ロールをインスタンスプロファイルに追加する: [https://docs.aws.amazon.com/cli/latest/reference/iam/add-role-to-instance-profile.html](https://docs.aws.amazon.com/cli/latest/reference/iam/add-role-to-instance-profile.html) 
+ インスタンスプロファイルのリストを取得する: [https://docs.aws.amazon.com/cli/latest/reference/iam/list-instance-profiles.html](https://docs.aws.amazon.com/cli/latest/reference/iam/list-instance-profiles.html)、[https://docs.aws.amazon.com/cli/latest/reference/iam/list-instance-profiles-for-role.html](https://docs.aws.amazon.com/cli/latest/reference/iam/list-instance-profiles-for-role.html)
+ インスタンスプロファイルの情報を取得する: [https://docs.aws.amazon.com/cli/latest/reference/iam/get-instance-profile.html](https://docs.aws.amazon.com/cli/latest/reference/iam/get-instance-profile.html) 
+ ロールをインスタンスプロファイルから削除する: [https://docs.aws.amazon.com/cli/latest/reference/iam/remove-role-from-instance-profile.html](https://docs.aws.amazon.com/cli/latest/reference/iam/remove-role-from-instance-profile.html)
+ インスタンスプロファイルを削除する: [https://docs.aws.amazon.com/cli/latest/reference/iam/delete-instance-profile.html](https://docs.aws.amazon.com/cli/latest/reference/iam/delete-instance-profile.html) 

次のコマンドを使用して、既に実行中の EC2 インスタンスにロールをアタッチすることもできます。詳細については、「[Amazon EC2 の IAM ロール](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/iam-roles-for-amazon-ec2.html#attach-iam-role)」を参照してください。
+ ロールが含まれたインスタンスプロファイルを停止中または実行中の EC2 インスタンスにアタッチする: [https://docs.aws.amazon.com/cli/latest/reference/ec2/associate-iam-instance-profile.html](https://docs.aws.amazon.com/cli/latest/reference/ec2/associate-iam-instance-profile.html) 
+ EC2 インスタンスにアタッチされたインスタンスプロファイルに関する情報を取得する: [https://docs.aws.amazon.com/cli/latest/reference/ec2/describe-iam-instance-profile-associations.html](https://docs.aws.amazon.com/cli/latest/reference/ec2/describe-iam-instance-profile-associations.html) 
+ ロールが含まれたインスタンスプロファイルを停止中または実行中の EC2 インスタンスからデタッチする: [https://docs.aws.amazon.com/cli/latest/reference/ec2/disassociate-iam-instance-profile.html](https://docs.aws.amazon.com/cli/latest/reference/ec2/disassociate-iam-instance-profile.html) 

### インスタンスプロファイルの管理 (AWS API)
<a name="instance-profiles-manage-api"></a>

以下の AWS API オペレーションを呼び出して AWS アカウント のインスタンスプロファイルを使用できます。
+ インスタンスプロファイルを作成する: [https://docs.aws.amazon.com/IAM/latest/APIReference/API_CreateInstanceProfile.html](https://docs.aws.amazon.com/IAM/latest/APIReference/API_CreateInstanceProfile.html) 
+ インスタンスプロファイルにタグを付ける: [https://docs.aws.amazon.com/IAM/latest/APIReference/API_TagInstanceProfile.html](https://docs.aws.amazon.com/IAM/latest/APIReference/API_TagInstanceProfile.html) 
+ インスタンスプロファイルのタグを一覧表示する: [https://docs.aws.amazon.com/IAM/latest/APIReference/API_TagInstanceProfile.html](https://docs.aws.amazon.com/IAM/latest/APIReference/API_TagInstanceProfile.html) 
+ インスタンスプロファイルのタグを解除する: [https://docs.aws.amazon.com/IAM/latest/APIReference/API_TagInstanceProfile.html](https://docs.aws.amazon.com/IAM/latest/APIReference/API_TagInstanceProfile.html) 
+ ロールをインスタンスプロファイルに追加する: [https://docs.aws.amazon.com/IAM/latest/APIReference/API_AddRoleToInstanceProfile.html](https://docs.aws.amazon.com/IAM/latest/APIReference/API_AddRoleToInstanceProfile.html) 
+ インスタンスプロファイルのリストを取得する: [https://docs.aws.amazon.com/IAM/latest/APIReference/API_ListInstanceProfiles.html](https://docs.aws.amazon.com/IAM/latest/APIReference/API_ListInstanceProfiles.html)、[https://docs.aws.amazon.com/IAM/latest/APIReference/API_ListInstanceProfilesForRole.html](https://docs.aws.amazon.com/IAM/latest/APIReference/API_ListInstanceProfilesForRole.html)
+ インスタンスプロファイルの情報を取得する: [https://docs.aws.amazon.com/IAM/latest/APIReference/API_GetInstanceProfile.html](https://docs.aws.amazon.com/IAM/latest/APIReference/API_GetInstanceProfile.html) 
+ ロールをインスタンスプロファイルから削除する: [https://docs.aws.amazon.com/IAM/latest/APIReference/API_RemoveRoleFromInstanceProfile.html](https://docs.aws.amazon.com/IAM/latest/APIReference/API_RemoveRoleFromInstanceProfile.html) 
+ インスタンスプロファイルを削除する: [https://docs.aws.amazon.com/IAM/latest/APIReference/API_DeleteInstanceProfile.html](https://docs.aws.amazon.com/IAM/latest/APIReference/API_DeleteInstanceProfile.html) 

以下のオペレーションを呼び出して、既に実行中の EC2 インスタンスにロールをアタッチすることもできます。詳細については、「[Amazon EC2 の IAM ロール](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/iam-roles-for-amazon-ec2.html#attach-iam-role)」を参照してください。
+ ロールが含まれたインスタンスプロファイルを停止中または実行中の EC2 インスタンスにアタッチする: [https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_AssociateIamInstanceProfile.html](https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_AssociateIamInstanceProfile.html) 
+ EC2 インスタンスにアタッチされたインスタンスプロファイルに関する情報を取得する: [https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_DescribeIamInstanceProfileAssociations.html](https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_DescribeIamInstanceProfileAssociations.html) 
+ ロールが含まれたインスタンスプロファイルを停止中または実行中の EC2 インスタンスからデタッチする: [https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_DisassociateIamInstanceProfile.html](https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_DisassociateIamInstanceProfile.html) 