Created
January 5, 2016 21:40
-
-
Save parsnips/841055ae6984ed92c755 to your computer and use it in GitHub Desktop.
For those times when the ASG says you got N instances, but your cluster says you N - k instances.
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 | |
set -e | |
CLUSTER=$1 | |
aws ecs list-container-instances --cluster $CLUSTER | jq .containerInstanceArns[] | tr -d \" | xargs -I{} aws ecs describe-container-instances --cluster $CLUSTER --container-instance {} | jq .containerInstances[].ec2InstanceId | tr -d \" > cluster.txt | |
aws autoscaling describe-auto-scaling-groups --auto-scaling-group-names $CLUSTER | jq -r ".AutoScalingGroups | .[] | .Instances | .[] | .InstanceId" | tr -d \" > asg.txt | |
sort cluster.txt cluster.txt asg.txt | uniq -u | xargs -I{} aws ec2 terminate-instances --instance-ids {} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment