Retrieving the IP address of an EC2 instance given an instance ID

荒凉一梦 提交于 2019-12-05 15:41:05

Try describe-instances instead. Private IP Address isn't returned with describe-instance-status because that command describes system and instance status, primarily concerning itself with hardware/issues or scheduled events.

Per the "Output" section of the describe-instances documentation, part of the output of describe-instances is a string PrivateIpAddress.

Example usage:

aws ec2 describe-instances --instance-ids <instance_ID>

To get ALL private IP addresses:

aws ec2 describe-instances --instance-ids ${INSTANCE_ID} |\
jq -r '.Reservations[].Instances[].NetworkInterfaces[].PrivateIpAddress'

or

aws ec2 describe-instances --instance-ids ${INSTANCE_ID} |\
jq -r ".Reservations[]" | grep PrivateIpAddress |\
egrep -o "([0-9]{1,3}\.){3}[0-9]{1,3}" | sort -u

You can do this using the query option.

aws ec2 describe-instances --instance-ids ${INSTANCE_ID} --query Reservations[].Instances[].NetworkInterfaces[].PrivateIpAddress

This will just return the private IPAddress and no other output information

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!