0

Can anyone please tell me how to run a shell script on all the ec2 instances that are part of a auto scaling group.

The scenario is that i have a script that i want to run on many ec2 instances that are turned on automatically as part of auto scaling group. The native approach is ssh to each instance and run the script. I am looking for a way by which it can run automatically on all the instances when i run it on one of the ec2 instance or any better way of doing this?

Thanks in advance.

Ankur Jain
  • 17
  • 5

1 Answers1

1

I would say there are two approaches:

  • Use the AWS API to determine the IP of all group members and then do SSH. -- This itself is possible on different levels, ranging from a shell script using aws-cli (describe-auto-scaling-instances and describe-instances) to a more sophisticated setup e.g. with Python boto and Fabric.

  • Have all instances register themselves in some orchestration or cluster management tool, e.g. serf or MCollective, and then use that channel to send commands to all group members.

Possibly third approach: do not explicitly run shell scripts at all, but have all instances get their setup from a Puppet or Chef server.

mschuett
  • 3,066
  • 20
  • 21
  • I need a shell script to determine all the IP of the instances of auto scaling group – Ankur Jain Apr 24 '15 at 11:54
  • Ankur, were you able to get the IP addresses of Instances of the AutoScaling group? – Ramesh Kumar Jul 10 '15 at 07:23
  • Ankur, you can get the find the anwer here: http://serverfault.com/questions/704806/how-to-get-autoscaling-group-instances-ip-adresses/705024#705024 I wrote small script for the same. – Ramesh Kumar Jul 15 '15 at 09:53