2014-10-07 191 views
4

使用aws CLI,如何根據實例ID檢索EC2實例的私有IP地址檢索給定實例ID的EC2實例的IP地址

當我這樣做:

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

我得到其他的信息,但不是私有IP地址,如:

{ 
    "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" 
        } 
       ] 
      } 
     } 
    ] 
} 

回答

3

讓所有的私有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