List public IP addresses of EC2 instances

The below command would list the IP addresses of all your running EC2 instances

aws ec2 describe-instances | grep PublicIpAddress | grep -o -P "\d+\.\d+\.\d+\.\d+" | grep -v '^10\.'

Hope that answers your query...

But this works without all the errors about access:

wget -qO- http://instance-data/latest/meta-data/public-ipv4/|grep .

  • Filter on running instances (you can drop that part if you don't need it)
  • Query for each PublicIPaddress and the Name Tag, handling when Name isn't set
aws ec2 describe-instances \
  --filter "Name=instance-state-name,Values=running" \
  --query "Reservations[*].Instances[*].[PublicIpAddress, Tags[?Key=='Name'].Value|[0]]" \
  --output text

Directly from the aws cli:

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