大网数据广告活动
服务器运维问答

Discover private DNS of load balancers in Cloudformation

· 52CE 我爱测

This is a pretty common issue but I am having trouble finding a proper answer to how to go about this. I have two apps, which will run on EC2s. These apps will be in their separate autoscaling groups, which are behind their own E…

问题原文

原帖链接 · madu · CC BY-SA 4.0

This is a pretty common issue but I am having trouble finding a proper answer to how to go about this.

I have two apps, which will run on EC2s. These apps will be in their separate autoscaling groups, which are behind their own ELBs. These 2 apps need to talk to each other, so they need to know the internal DNS of the ELBs.

I can think of few ways to go about this:

  1. Create the ELBs before-hand and use them by their name in the CF template. (I have not tried this, there was a post about not being able to reference an externally created ELB name in the CF template. But I'm guessing it should be doable).
  2. Create the ELBs first in the CF, and then get their private IPs through Fn::Gett (or something similar), and then write this value to an environmental variable in the app.
  3. Implement a service discovery, where each app/ELB, write its private IP to a DB or something similar so other apps and discover the IPs of the other services/apps.

Option #2 would be the best case, and I'm assuming this is the process that is most infra-as-a-code. However, I cannot find proper documentation on how to do it.

If anyone can refer me the right way of going about this, I very much appreciate. Thank you.

已采纳解答

原帖链接 · MLu · CC BY-SA 4.0

Each ELB has an AWS-assigned DNS name that you should use.

If you create the ELB through CloudFormation you can get the name with Fn:GetAtt ELB.DNSName as described in AWS::ElasticLoadBalancing::LoadBalancer Return Values:

[...]
  MyELB:
    Type: AWS::ElasticLoadBalancing::LoadBalancer
    Properties:
      ...

Outputs:
  ELBName:
    Value: !GetAtt MyELB.DNSName            <<< Like this

BTW Never ever refer directly to the resolved IP addresses anywhere because they change often, for example when the ELB scales up, down, goes through maintenance, etc.

Hope that helps :)

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2019-11-13)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。