Home > Software engineering >  how to get DNS ELB automatically ELB AWS Cloud formation
how to get DNS ELB automatically ELB AWS Cloud formation

Time:03-15

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

CodePudding user response:

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.

CodePudding user response:

Thank for you answer

you are right i forgot to say some important things, I create the load balancer in the same stack, all my infra is created in the same stack I will take a look at the function !GetAtt :)

  • Related