Reputation: 301
My AWS Command is:
> aws ec2 run-instances --image-id ami-346b2354 --count 1 --instance-type c4.large --key-name my-cali-key --security-group-ids sg-a168c7c4
When I trigger this, the JSON data that it returns has only the Private IP address and NOT the Public IP address.
................ DATA OMITTED...................
"Groups": [
{
"GroupName": "launch-wizard-1",
"GroupId": "sg-a168c7c4"
}
],
"SubnetId": "subnet-cb2524ae",
"OwnerId": "012710546082",
"PrivateIpAddress": "172.31.17.252"
}
..................... DATA OMITTED ....................
(Image) Browser look of the same instance with Public IP
However when I see in the browser I immediately notice a Public IP address being associated automatically. How Can I fetch the public IP of launched instances? Kindly do not get confused with elastic-IP and its association with instances. I know to associate an elastic-IP but the need here is different.
Upvotes: 3
Views: 911
Reputation: 511
aws ec2 describe-instances \
--query "Reservations[*].Instances[*].PublicIpAddress" \
--output=text
Another Way is
curl --silent http://ipecho.net/plain
This will return Public IP of instance
Upvotes: 6