nate
nate

Reputation: 522

Attach IAM role to multiple EC2 instances

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?

Upvotes: 0

Views: 892

Answers (2)

jaredready
jaredready

Reputation: 2698

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.

Upvotes: 2

Chris Williams
Chris Williams

Reputation: 35258

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

Upvotes: 2

Related Questions