Skip to content

Instantly share code, notes, and snippets.

@tschant
Created November 24, 2020 14:57
Show Gist options
  • Save tschant/f68b1162fca1797eb7beb6f02a9ad1e3 to your computer and use it in GitHub Desktop.
Save tschant/f68b1162fca1797eb7beb6f02a9ad1e3 to your computer and use it in GitHub Desktop.
Search running AWS EC2 instances for tag value, return IP and tag
function aws-search-ec2() {
if [ "$1" ]
then
echo "Searching running EC2 for: $1"
aws ec2 describe-instances \
--query "Reservations[*].Instances[*].[PrivateIpAddress, Tags[*].Value]" \
--output text \
--filters Name=instance-state-name,Values=running Name=tag-key,Values=Name Name=tag-value,Values="$1"
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment