List public IP addresses of EC2 instances

后端 未结 5 813
無奈伤痛
無奈伤痛 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:28

    You can use instance metadata so you can run the following command from the ec2 instance:

    curl http://169.254.169.254/latest/meta-data/public-ipv4
    

    and it will give you the public IP of the instance. If you want the private IP, you will run

    curl http://169.254.169.254/latest/meta-data/local-ipv4
    

提交回复
热议问题