Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save bageljp/5869946 to your computer and use it in GitHub Desktop.

Select an option

Save bageljp/5869946 to your computer and use it in GitHub Desktop.
ELBでOutOfServiceになったインスタンスをAutoScalingグループから強制排除
#!/bin/bash
if [ $# -lt 1 ]; then
echo "Usage: `basename $0` {elb-name} [region]"
exit 1
fi
ELB_NAME="$1"
REGION="${2:-ap-northeast-1}"
# :TODO
# initial instances excluded.
aws elb describe-instance-health --load-balancer-name ${ELB_NAME} | \
jq '.InstanceStates[] | select(.State == "OutOfService").InstanceId' | \
sed -e 's/\"//g' | while read line; do
aws autoscaling terminate-instance-in-auto-scaling-group --instance-id ${line} --no-should-decrement-desired-capacity
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment