0
votes

There seems to be plenty of documentation that outlines making a role with its corresponding policies and then attaching that to a new or pre-existing (single) EC2 instance. However, when you have many instances and the task it to attach a role to all of those instances, I can't find or figure a way that avoid doing the process one-by-one.

So, how does one attach an IAM role to multiple already-launched EC2 instances efficiently?

2

2 Answers

1
votes

You'd have to do this one by one. It would generally be attached at launch but you can do it afterwards.

Programatically looping would probably be the most efficient

2
votes

There is no way to bulk-assign roles to EC2 instances.

You can do this programmatically using the CLI or the SDK in your language of choice.

If using the CLI you'll want to use the ec2 associate-iam-instance-profile command. Note that this command still just accepts a single instance identifier at a time so you'll need to iterate through a list of instances and invoke repeatedly.