How do I attach or replace an instance profile on an Amazon Elastic Compute Cloud (Amazon EC2) instance?

  1. Open the Amazon EC2 console, and choose Instances from the navigation pane.
  2. Choose the instance that you want to attach an IAM role to.
  3. Check the IAM role under the Description view of the Launch Instance pane to confirm if an IAM role is attached to the instance. If a role is attached, confirm that changing the role attached to this instance won't affect your applications or access to AWS services.
  4. Choose Actions, choose Instance Settings, and then choose Attach/Replace IAM role from the drop-down list.
  5. On the Attach/Replace IAM role page, under IAM role, choose the instance profile that you want to attach from the drop-down list.
    Note: If a role is created using the Amazon EC2 console, the instance profile name and IAM role names are the same.
  6. Choose Apply.

You can use the AWS Command Line Interface (AWS CLI) to verify that the IAM role is attached to the instance by running the following command:

$ aws ec2 describe-iam-instance-profile-associations

If you created the IAM role using the AWS CLI, add the role to the instance profile before attaching the instance profile to the EC2 instance by running the following command:

$ aws iam add-role-to-instance-profile --instance-profile-name <value> --role-name <value>

After you have associated the role to the instance profile, use the AWS CLI to associate the instance profile to the EC2 instance by running the following command:

$ aws ec2 associate-iam-instance-profile --iam-instance-profile Name=<value> --instance-id i-012345678910abcde

Note: If a role is created using the AWS CLI, the instance profile name and IAM role name might be different. However, if you choose the instance profile that contains the IAM role from the drop-down menu, you'll see the IAM role name in the description after the instance profile is attached.


Did this page help you? Yes | No

Back to the AWS Support Knowledge Center

Need help? Visit the AWS Support Center

Published: 2018-06-01