Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Bash script to join a rabbitmq cluster of the same AWS autoscaling group
wget --quiet
sudo chmod u+x ec2-metadata
INSTANCE_ID=$(./ec2-metadata | grep instance-id | awk 'NR==1{print $2}')
AG_NAME=$(aws autoscaling describe-auto-scaling-instances --instance-ids ${INSTANCE_ID} --query AutoScalingInstances[].AutoScalingGroupName --output text)
echo ===================================
echo Searching for cluster in ${AG_NAME}
echo ===================================
echo Local Instance ID: ${INSTANCE_ID}
for ID in $(aws autoscaling describe-auto-scaling-groups --auto-scaling-group-names ${AG_NAME} --query AutoScalingGroups[].Instances[].InstanceId --output text);
echo Found cluster node ${ID}
if [ "${ID}" == ${INSTANCE_ID} ] ; then
DNS=$(aws ec2 describe-instances --instance-ids $ID --query Reservations[].Instances[].PrivateDnsName --output text)
DNS=(${DNS//./ })
echo Joining cluster ${ID} at rabbit@${DNS[0]}
rabbitmqctl stop_app
rabbitmqctl join_cluster rabbit@${DNS[0]}
rabbitmqctl start_app
exit 1

This comment has been minimized.

Copy link
Owner Author

@sators sators commented Oct 13, 2018

Note this is expecting your default region for the aws cli to already be set:

REGION=`/usr/bin/ec2metadata | grep "^availability-zone:" | awk '{print substr($2, 1, length($2)-1)}'`
aws configure set default.region $REGION
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.