简体   繁体   中英

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

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 .

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. 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. You can then use the !GetAtt function to reference the return value. 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. 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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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