Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save alertedsnake/b7dc834510cf9883c84b3cfb286397b5 to your computer and use it in GitHub Desktop.
Save alertedsnake/b7dc834510cf9883c84b3cfb286397b5 to your computer and use it in GitHub Desktop.
Kill all servers in an AWS Autoscaling Group
#!/bin/bash
#
# Note that this requires the really cool command-line tool 'jq'
#
if [ -z "$1" ]; then
echo "as_kill_instances [group]"
exit -1
fi
instances=$(aws autoscaling describe-auto-scaling-groups --auto-scaling-group-names $1 | jq -r .AutoScalingGroups[0].Instances[].InstanceId )
for instance in $instances ; do
aws autoscaling terminate-instance-in-auto-scaling-group \
--instance-id $instance \
--no-should-decrement-desired-capacity
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment