Skip to content

Instantly share code, notes, and snippets.

Last active September 2, 2016 06:51
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Detach and Attach a random instance to an ELB.
Instance_ids_str=`aws elb describe-load-balancers --load-balancer-name $LOAD_BALANCER_NAME --query "LoadBalancerDescriptions[*].{ID:LoadBalancerName,InstanceId:Instances[*].InstanceId}[*]. {ELB:ID,InstanceId:InstanceId[*]}" --output=json |jq -r ".[].InstanceId|@csv" |sed 's/\"//g'`
IFS=',' read -a Instance_ids_array <<< "$Instance_ids_str"
for INSTANCE_ID in ${Instance_ids_array[$RANDOM % ${#Instance_ids_array[@]}]}
aws elb deregister-instances-from-load-balancer --load-balancer-name $LOAD_BALANCER_NAME --instances $INSTANCE_ID
aws elb register-instances-with-load-balancer --load-balancer-name $LOAD_BALANCER_NAME --instances $INSTANCE_ID
Copy link

acsrujan commented Mar 28, 2016

To execute:

#raw url of above gist
chmod +x
#run the script whenever necessary.

Copy link

@acsrujan only one instance needs to be kicked out not all

Copy link

got it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment