List public IP addresses of EC2 instances

Bas Peeters picture Bas Peeters · Jul 24, 2014 · Viewed 40.7k times · Source

I want to list the public IP addresses of my EC2 instances using Bash, separated by a delimiter (space or a new-line).

I tried to pipe the output to jq with aws ec2 describe-instances | jq, but can't seem to isolate just the IP addresses.

Can this be done by aws alone, specifying arguments to jq, or something else entirely?

Answer

Julio Faerman picture Julio Faerman · Jul 24, 2014

Directly from the aws cli:

aws ec2 describe-instances \
  --query "Reservations[*].Instances[*].PublicIpAddress" \
  --output=text