amazon-web-services - 检查停止的 AWS EC2 实例是否将获得带有 boto3 的公共(public) IP

标签 amazon-web-services amazon-ec2

如果 EC2 实例已设置为检索公共(public) IP(而非弹性 IP)并且当前已停止,我可以查看什么以确保它在启动时将获得公共(public) IP?假设它所在的子网未设置为所有实例提供公共(public) IP。当实例正在运行时,当我使用 client.describe_instances() 检索实例时,我可以看到公共(public) IP 信息,但当它停止时我看不到任何信息。谢谢。

最佳答案

在查阅大量文档后,我得出结论,通过 API 公开的信息无法可靠地完成此操作。 answer by John 包含有关确定 是否 EC2 实例将在首次启动时分配公共(public) IP 的因素的重要详细信息。

根据该信息,可以确定新启动的 EC2 实例是否会获得公共(public) IP,这基本上由 AssociatePublicIpAddress 参数控制。这可以在启动实例时明确设置(请参阅 doc1 - Example 5doc2 ),并且将具有取决于启动实例的子网的默认值。

如果实例在 MapPublicIPOnLaunch 设置为 true 的子网中启动,则默认为 true,如果 MapPublicIPOnLaunch 设置为 false,则默认为 false。 但是,您可以覆盖此默认值。

如果应该相信 docs(强调我的),则信息是否应该关联保留在 ENI 上

When you create a network interface, it inherits the public IPv4 addressing attribute from the subnet. If you later modify the public IPv4 addressing attribute of the subnet, the network interface keeps the setting that was in effect when it was created. If you launch an instance and specify an existing network interface as the primary network interface, the public IPv4 address attribute is determined by this network interface.

不幸的是,似乎没有任何 API 公开此内部标志的值 - DescribeInstancesDescribeNetworkInterfaces API 调用均未将其包含在响应中。

因此,您可以根据实例所在的子网进行有根据的猜测,但无论有多大根据,它仍然是一个猜测,因为这仅在 AssociatePublicIpAddress 的默认值时有效> 没有改变。确定可靠的唯一方法是打开实例,在其上使用 DescribeInstances 并检查它是否已收到公共(public) IP。

关于amazon-web-services - 检查停止的 AWS EC2 实例是否将获得带有 boto3 的公共(public) IP,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65943916/

相关文章:

amazon-web-services - 适用于只能访问特定 S3 存储桶的 IAM 组的 AWS CloudFormation 模板

amazon-web-services - 通过 CloudFormation 从 xtrabackup 恢复 AWS RDS

mysql - mysqldump 错误 2003

amazon-web-services - Elastic Beanstalk NetworkOut 自动扩展

amazon-web-services - 如何使用 HadoopJarStep Config.Step 属性?

amazon-web-services - 通过 Cloudformation 将配方分配给 Opsworks 中的生命周期事件

amazon-web-services - 列出 Amazon Glacier 保管库中具有名称的文件

amazon-web-services - 使用 "jhipster aws"部署 jhipster 应用程序时连接到 EC2 实例

magento - Amazon Web Services 中 EC2 和 RDS 实例之间的网络延迟影响有多大,特别是对于 Magento 而言?

amazon-ec2 - 无法访问 ec2 实例上的 httpd