Created
December 15, 2016 10:21
-
-
Save shiplu/a203bcddef5926c56240aa660c4493e5 to your computer and use it in GitHub Desktop.
Lists all the ec2 instance's ip by name. The name can be a glob pattern, means if its '*a' then it'll match any instance that has name ending with letter a. It outputs only the PrivateIpAddress. But if you can also use PublicIpAddress.
This file contains 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 characters
#!/bin/bash | |
IP_SOURCE=PrivateIpAddress | |
aws ec2 describe-instances --output text \ | |
--query 'Reservations[*].Instances[*].{ip:['$IP_SOURCE'],name:Tags[?Key==`Name`].Value}' \ | |
--filter "Name=tag:Name,Values=$1" | | |
awk '$1 ~ /IP/{ip=$2} $1 ~ /NAME/{printf "%-15s %s\n", ip, $2}' | | |
sort -k2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment