Wondering how to assign an existing IAM Role to an EC2 Instance? We can help you.
Here, at Bobcares, we assist our customers with several AWS queries as part of our AWS Support Services.
Today, let us see how to assign IAM Role to an EC2 Instance.
Assign an Existing IAM Role to an EC2 Instance
In order to assign, our Support Techs recommend ensuring the following:
- We need to wait for AWS Systems Manager Agent to detect the new IAM role or restart SSM Agent if we use AWS Systems Manager.
- If the AWS CLI commands result in errors, check if we have the most recent version of the AWS CLI.
To attach an IAM role to an instance that has no role, the instance can be running or not.
Moving ahead, let us see how to attach an IAM role to an instance in the new & old console.
New console:
- Initially, we open the Amazon EC2 console.
- In the navigation pane, we select Instances.
- Then we select the instance > Actions > Security > Modify IAM role.
- After that, we select the IAM role to attach to the instance
- Eventually, we hit the Save button.
Old console:
- First, we open the Amazon EC2 console.
- Then we go to Instance in the navigation pane.
- We select the instance > Actions > Instance Settings > Attach/Replace IAM role.
- Finally, we select the IAM role to attach to the instance and choose Apply.
Attach an IAM role to an instance (AWS CLI):
If necessary, we describe the instances to get the ID of the instance to which we attach the role.
aws ec2 describe-instances
We need to attach the IAM role to the instance by specifying the instance profile.
To do so, we use the associate-iam-instance-profile command.
aws ec2 associate-iam-instance-profile \
--instance-id i-1234567890abcdef0 \ --iam-instance-profile Name="TestRole-1"
{
"IamInstanceProfileAssociation": {
"InstanceId": "i-1234567890abcdef0",
"State": "associating",
"AssociationId": "iip-assoc-0dbd8529a48294120",
"IamInstanceProfile": {
"Id": "AIPAJLNLDX3AMYZNWYYAY",
"Arn": "arn:aws:iam::123456789012:instance-profile/TestRole-1"
}
}
}
[Need help with the procedures? We’d be happy to assist you]
Conclusion
In short, we saw how our Support Techs go ahead to assign IAM Role to an EC2 Instance.
0 Comments