简体   繁体   English

获取弹性伸缩组实例内部IP

[英]Getting the internal IP of an instance in an auto-scaling group

I'm using CloudFormation to bring up a single instance in an autoscaling group (MaxSize: 1)我正在使用 CloudFormation 在自动缩放组中启动单个实例 (MaxSize: 1)

I would like to know how to access the internal IP of that instance so I can assign it a friendly name with Route 53 in the same template.我想知道如何访问该实例的内部 IP,以便我可以在同一模板中为其分配一个带有 Route 53 的友好名称。

If it were just a AWS::EC2::Instance it would be easy but it is defined as an autoscaling group so I don't have access to the "PrivateIP" attribute如果它只是一个 AWS::EC2::Instance,那会很容易,但它被定义为一个自动缩放组,所以我无权访问“PrivateIP”属性

From CloudFormation, you can't. 从CloudFormation,你不能。

Cloud Formation builds your auto scaling group, but it's scaling group itself that is responsible for creating that instance. Cloud Formation构建了您的自动扩展组,但它是扩展组本身,负责创建该实例。 In some cases, Cloud Formation will have finished creating the stack prior to the scaling group triggering and completing the creation of the instance. 在某些情况下,Cloud Formation将在缩放组触发和完成实例创建之前完成创建堆栈。

In order to achieve what you want through CloudFormation, you should add an Elastic Load Balancer (ELB) to the front. 为了通过CloudFormation实现您想要的功能,您应该在前面添加Elastic Load Balancer(ELB)。 Then register the ELB address with Route 53, and tie that into the scaling group. 然后使用Route 53注册ELB地址,并将其绑定到缩放组。

I'm facing the same issue, dont think its possible if your instance goes down and a new one comes up as it should using cloudfomration, You would have to run cloudformation update again as the private Ip would've changed我面临着同样的问题,如果您的实例出现故障并且应该使用 cloudfomration 出现一个新实例,请不要认为这是可能的,您将不得不再次运行 cloudformation 更新,因为私有 Ip 会发生变化

从instnace,您可以获得内部IP地址:

curl http://169.254.169.254/latest/meta-data/local-ipv4/

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

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