y.selivonchyk
y.selivonchyk

Reputation: 9900

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?

Upvotes: 4

Views: 8650

Answers (1)

krishna_mee2004
krishna_mee2004

Reputation: 7366

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.

Upvotes: 19

Related Questions