Last active
September 2, 2016 06:51
-
-
Save acsrujan/062db33fb25721b67760 to your computer and use it in GitHub Desktop.
Detach and Attach a random instance to an ELB.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
LOAD_BALANCER_NAME=$1 | |
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[@]}]} | |
do | |
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 | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To execute: