Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run a shell script on all amazon ec2 instances that are part of a autoscaling group?

Can anyone please tell me how to run a shell script on all the ec2 instances that are part of an 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 to 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.

like image 916
Ankur Jain Avatar asked Oct 31 '22 05:10

Ankur Jain


1 Answers

You'll want to add that shell script to the userdata in a NEW Launch Config and then update the autoscaling group.

https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/user-data.html#user-data-shell-scripts

Updating the Launch Config

if you want to change the launch configuration for your Auto Scaling group, you must create a launch configuration and then update your Auto Scaling group with the new launch configuration. When you change the launch configuration for your Auto Scaling group, any new instances are launched using the new configuration parameters, but existing instances are not affected.

https://docs.aws.amazon.com/autoscaling/latest/userguide/LaunchConfiguration.html

like image 182
strongjz Avatar answered Nov 09 '22 12:11

strongjz