Search code examples
windowspowershellamazon-web-servicesamazon-ec2aws-sdk

How do I remove a role from an EC2 instance?


I launched an instance with an iam role

I now want to remove the role from the instance via powershell

I must be confused about the terminology here because I'm reading this doc and I don't see how to remove a role from an instance.

I want to run this command on the EC2 instance that the role will be removed from.

There can only be one role assigned to an instance so is there a way to dynamically get the iam role that has been assigned to an instance and remove it from the instance via the powershell api?


Solution

  • You can do that using AWS CLI (v1.11.46 or newer).

    You can disassociate an IAM instance profile from a running or stopped instance using the disassociate-iam-instance-profile command.

    See the disassociate-iam-instance-profile CLI command documentation for more details.