Getting the IP Address of an EC2 Instance with Instance ID

Using aws CLI, how can I get the private IP address of an EC2 instance given its instance id?

When I do this:

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

I get other information, but not private IP addresses, such as:

{
    "InstanceStatuses": [
        {
            "InstanceId": "XXXXX", 
            "InstanceState": {
                "Code": 16, 
                "Name": "running"
            }, 
            "AvailabilityZone": "us-east-1a", 
            "SystemStatus": {
                "Status": "ok", 
                "Details": [
                    {
                        "Status": "passed", 
                        "Name": "reachability"
                    }
                ]
            }, 
            "InstanceStatus": {
                "Status": "ok", 
                "Details": [
                    {
                        "Status": "passed", 
                        "Name": "reachability"
                    }
                ]
            }
        }
    ]
}
+4
source share
2 answers

Give it a try describe-instances. The private IP address is not returned with describe-instance-status , because this command describes the state of the system and instance, primarily related to hardware / problems or scheduled events.

"Output" - - PrivateIpAddress.

:

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

IP-:

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

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
+3

All Articles