Last active
August 27, 2018 07:35
-
-
Save lavie/a829336ee53f6aecdbea8a365399e39c to your computer and use it in GitHub Desktop.
Bash script to replace all ASG instances (by flagging them as Unhealthy, ASG does the rest)
This file contains hidden or 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 | |
# Usage `./replace-asg-instances.sh my-asg-name` | |
# Will set all instances to Unhealthy, so they are replaced by the ASG. | |
# Notice this is meant to work with EC2 health-check ASG, not ELB health-checks. | |
if [[ $1 == "" ]]; then | |
echo Usage "./replace-asg-instances.sh my-asg-name" | |
exit 1 | |
fi | |
aws autoscaling describe-auto-scaling-groups | \ | |
jq -r ".AutoScalingGroups[] | select (.AutoScalingGroupName | contains(\"$1\"))| .Instances[].InstanceId" | \ | |
xargs -n1 -I {} \ | |
aws autoscaling set-instance-health --cli-input-json '{"InstanceId": "{}", "HealthStatus": "Unhealthy"}' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment