Created
May 18, 2018 20:50
-
-
Save rphillips/37da0874b3a44e1db8b2aca6151c1e62 to your computer and use it in GitHub Desktop.
Revisions
-
rphillips renamed this gist
May 18, 2018 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
rphillips created this gist
May 18, 2018 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,40 @@ #!/usr/bin/env bash ## Script to mark nodes for termination on AWS ## usage: term-cluster.sh [filter on name] [region (default: us-east-1)] ## ## Dependencies: jq and awless ## set -eou pipefail die() { echo $@ exit 1 } FILTER=${1:-} if [[ $FILTER == "" ]]; then die "invalid filter" fi REGION=${2:-us-east-1} declare -A instances=() # Query instances awsdata=$(awless list instances --filter name="$FILTER" --aws-region=$REGION --format json --no-sync) filtered=$(echo $awsdata | jq -r '.[] | "\(.ID) \(.Name) "') while read id name; do echo "Instance $id - $name" instances[$id]=$name done <<< "$filtered" # Prompt for deletion read -p "Terminate these instances? " -n 1 -r echo if [[ $REPLY =~ ^[Yy]$ ]]; then for key in "${!instances[@]}"; do name=${instances[$key]} awless create tag resource=$key key=Name value="$name-terminate" --aws-region=$REGION -f --no-sync done fi