简体   繁体   English

如何自动获取DNS ELB ELB AWS Cloud formation

[英]how to get DNS ELB automatically ELB AWS Cloud formation

For my stack i need to automatically retrieve the dns of my load balancer on AWS, because i delete/create to update my stack and my server, the names change all the time or my need to be able to automatically retrieve the dns from my ELB in AWS对于我的堆栈,我需要在 AWS 上自动检索我的负载均衡器的 dns,因为我删除/创建更新我的堆栈和我的服务器,名称一直在变化,或者我需要能够从我的 ELB 中自动检索 dns在亚马逊

thank感谢

It is unclear whether or not you are creating that load balancer in the same stack or not, and which load balancer you're talking about.目前尚不清楚您是否在同一个堆栈中创建该负载均衡器,以及您在谈论哪个负载均衡器。 If it is an ELB within the same stack, this is very easy by using the !GetAtt function with the correct output. Information about the outputs of the ELB in cloudformation can be found here .如果它是同一堆栈中的 ELB,这非常容易,方法是使用!GetAtt function 和正确的 output。有关 ELB 在 cloudformation 中的输出的信息可以在此处找到。

If you are talking about an already existing load balancer, then there are a few options.如果您正在谈论一个已经存在的负载均衡器,那么有几个选项。 If it is created in another stack, you can always cross-reference it by using the ImportValue function that comes with cloudformation.如果它是在另一个堆栈中创建的,您始终可以通过使用cloudformation自带的 ImportValue function 来交叉引用它。 A second option is to pass it in as a parameter to the stack.第二种选择是将其作为参数传递给堆栈。 If the value subsequently changes, you can easily update your template with the new value as a parameter.如果该值随后发生变化,您可以使用新值作为参数轻松更新您的模板。

The last option is to use a custom resource that executes a lambda function which retrieves the DNS value you want and returns it as an output value to the CloudFormation resource.最后一个选项是使用执行 lambda function 的自定义资源,它检索所需的 DNS 值并将其作为 output 值返回给 CloudFormation 资源。 You can then use the !GetAtt function to reference the return value.然后,您可以使用!GetAtt function 来引用返回值。 However, you must be wary that this function will not always execute when you update the stack, so you can add a dummy parameter as input to the custom resource which you can change to force a rerun of the lambda to retrieve the latest value.但是,您必须注意,当您更新堆栈时,此 function 不会始终执行,因此您可以添加一个虚拟参数作为自定义资源的输入,您可以更改该参数以强制重新运行 lambda 以检索最新值。 This option is quite some work to implement and will be only marginally easier to use than simply using a stack parameter to pass in the value.这个选项的实现需要做一些工作,并且只比简单地使用堆栈参数传递值更容易使用。

In the Output section of your Cloudformation template you can get the DNS url在 Cloudformation 模板的 Output 部分,您可以获得 DNS url

.
.
.
Resources:
      .
      .
      .
  MyLoadBalancer:
    Type: AWS::ElasticLoadBalancing::LoadBalancer
    Properties:
      .
      .
.
.
.
Outputs:
  LoadBalancerOutput:
    Value: !GetAtt MyLoadBalancer.DNSName  

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

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