Skip to content

Instantly share code, notes, and snippets.

@parsnips
Created January 5, 2016 21:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save parsnips/841055ae6984ed92c755 to your computer and use it in GitHub Desktop.
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.
#!/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