List public IP addresses of EC2 instances

后端 未结 5 810
無奈伤痛
無奈伤痛 2020-12-13 08:46

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 aw

5条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-13 09:16

    • 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
    

提交回复
热议问题