amazon-web-servicesamazon-ec2amazon-iam

EC2 Instance error telling me multiple IAM Roles are attached when I try to change it...?


This is a strange one... If I click on the instance id, and then navigate to security, it tells me the instance has role X. Then I back out to view all instances, mark the checkbox for the instance in question, go to Actions -> Security -> Modify IAM Role, and it shows me a different role, role Y. I then try to set it to No IAM Role (or any various role), and I get this error:

"Multiple roles associated to instance

The selected instance has more than one IAM role associated. This usually occurs when the instance is in the process of replacing an existing instance profile association. "

I have no idea what to do because I didn't think an EC2 instance was supposed to be able to have two roles... nothing can assume two roles at once, anyway. So this feels like a bug... can anyone help me solve this?

enter image description here

enter image description here

enter image description here


Solution

  • I had the same issue and it seems that when replacing the instance profile it somehow stays in a state that's not completely associated. Using the CLI we can see the status of the profile association:

    aws ec2 describe-iam-instance-profile-associations

    In my case the problematic profile was showing as "associating", while all the others show "associated". Get the AssociationID for the problematic association and disassociate it with the command

    aws ec2 disassociate-iam-instance-profile --association-id iip-assoc-xxxxxx

    After that you should see the previous profile you had originally and everything should be consistent. Hope it helps solving the problem.