Using the aws CLI
, how can I retrieve the private IP address of an EC2 instance given its instanceID?
When I do:
aws ec2 describe-instance-status --instance-ids <instance_ID>
I get other information, but not the 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"
}
]
}
}
]
}
Simply check the var/lib/cloud/instance symlink, it should point to /var/lib/cloud/instances/{instance-id} where {instance_id} is your instance-id.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With