Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get public ip of an EC2 instance from aws CLI by instance id?

I have an instance that I start through aws cli:

aws ec2 start-instances --instance-ids i-00112223333444445

Instance does not have a static public IP. How can I get instance public ip through CLI knowing the ID i-00112223333444445?

like image 394
y.selivonchyk Avatar asked Oct 28 '25 17:10

y.selivonchyk


1 Answers

Try the following command:

aws ec2 describe-instances --instance-ids $instance_id \
    --query 'Reservations[*].Instances[*].PublicIpAddress' \
    --output text

If the EC2 instance has a public IP address, this command will return it.

Links:

  • Details about the query parameter can be found here.
  • Details about the describe-instances command can be found here.
like image 152
krishna_mee2004 Avatar answered Oct 30 '25 06:10

krishna_mee2004