简体   繁体   English

如何通过实例ID从AWS CLI获取EC2实例的公共IP?

[英]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 cli启动的实例:

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

Instance does not have a static public IP. 实例没有静态公共IP。 How can I get instance public ip through CLI knowing the ID i-00112223333444445? 如何通过CLI知道ID为i-00112223333444445的实例来获取公共IP?

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. 如果EC2实例具有公共IP地址,则此命令将返回它。

Links: 链接:

  • Details about the query parameter can be found here . 有关查询参数的详细信息,请参见此处
  • Details about the describe-instances command can be found here . 可以在此处找到有关describe-instances命令的详细信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM