Skip to content

Instantly share code, notes, and snippets.

@jfouse
Created December 19, 2014 19:33
Show Gist options
  • Save jfouse/07a97311b81218f40d95 to your computer and use it in GitHub Desktop.
Save jfouse/07a97311b81218f40d95 to your computer and use it in GitHub Desktop.
find-ec2-instance.sh
#!/bin/bash
# Intention: when receiving seemingly-random emails from Amazon Web Services that some EC2 instance will be rebooted,
# it would be handy to be able to easily identify the instance to know if you need to take further action either before
# or after the stated maintenance action. Unfortunately, the email only gives the instance ID and region. If you're
# maintaining multiple AWS accounts it quickly becomes cumbersome to locate the instance in question. This small script
# can help with that. Nothing fancy, just a quick convenience script to go do your searching for you.
#
# This script assumes two things:
# 1. you have the AWS cli installed: http://aws.amazon.com/cli/
# 2. You have one or more named account profiles configured in ~/.aws/config
#
if [ -z $1 ]
then
echo "Usage: find-ec2-instance.sh <instance-id>"
exit
fi
for x in `ack profile ~/.aws/config | sed 's/^.* \(.*\)\]/\1/'`;
do
echo "- $x";
aws ec2 describe-instances --instance-ids $1 --profile $x --query 'Reservations[*].Instances.Tags' --output text 2>/dev/null;
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment