Skip to content

Instantly share code, notes, and snippets.

@joswr1ght
Last active July 29, 2021 18:54
Show Gist options
  • Save joswr1ght/33df350242cb9128fbb77f51452ca430 to your computer and use it in GitHub Desktop.
Save joswr1ght/33df350242cb9128fbb77f51452ca430 to your computer and use it in GitHub Desktop.
Get Name and IP address from EC2 instances
$ aws --profile falsimentis --region us-west-1 ec2 describe-instances | jq -jr '.Reservations[] | .Instances[] | "\"", (.PublicIpAddress), "\":\"", (.Tags[] | select(.Key=="Name")|.Value),"\",\n"'
"54.183.200.32":"Web Server 3",
"13.56.160.248":"VPC NAT Backup",
"13.57.148.101":"VPC NAT",
"54.153.36.229":"Dev Webserver",
"52.52.159.114":"Web Server 2",
"null":"DB Server 1",
"54.241.78.206":"Web Server 1",
"54.219.245.27":"Web Server 4",
$ cat ec2-describe-instances.json | jq -jr '.Reservations[] | .Instances[] | "\"", (.NetworkInterfaces[] | .PrivateIpAddress), "\":\"", (.Tags[] | select(.Key=="Name")|.Value),"\",\n"'
"10.0.0.236":"Web Server 1",
"":"VPC NAT",
"10.0.1.235":"DB Server 1",
"10.0.0.40":"Web Server 4",
"":"VPC NAT Backup",
"10.0.0.36":"VPC NAT",
"172.31.17.216":"Dev Webserver",
"10.0.0.223":"Web Server 2",
"10.0.0.163":"Web Server 3",
"10.0.0.222":"VPC NAT Backup",
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment