Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save mblakele/fb9f5327f1e115ae129a to your computer and use it in GitHub Desktop.
Save mblakele/fb9f5327f1e115ae129a to your computer and use it in GitHub Desktop.
check termination status on all my ec2 instances
#!/bin/bash
#
set -e
# It seems to be important to keep each json dict small enough for one line.
for o in $(aws ec2 describe-instances | jq '.Reservations[].Instances[]' \
| jq -c '{ InstanceId, Tags }'); do
id=$(echo $o | jq -e -r '.InstanceId')
name=$(echo $o | jq -e -r '.Tags[]|select(.Key == "Name").Value')
# No -e because false triggers it.
term=$(aws ec2 describe-instance-attribute --instance-id $id \
--attribute disableApiTermination \
| jq -r '.DisableApiTermination.Value')
echo $term $name $id;
done
# end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment