【问题标题】:cloudformation to get DNSName from LoadBalancerArncloudformation 从 LoadBalancerArn 获取 DNSName
【发布时间】:2018-12-23 11:15:49
【问题描述】:

我的负载均衡器已经存在并且不是使用 cloudformation 创建的。

我将完整的 arn 作为参数传递给需要它的资源,例如监听器:

  Listener:
    Type: AWS::ElasticLoadBalancingV2::Listener
    Properties:
      DefaultActions:
      - Type: forward
        TargetGroupArn: !Ref MyTargetGroup
      LoadBalancerArn: !Ref LoadBalancerARN
      Port: 80
      Protocol: HTTP

在这个使用 LoadBalacnerArn 的模板中,我还希望它输出该负载均衡器的 DNSName - 这可能吗?

这样做我可以返回作为参数传入的 ARN:

Outputs:
  LoadBalancerName:
    Description: The DNS Name of the ALB where this container was deploy
    Value: !Ref LoadBalancerARN

我尝试这样获取 DNS 名称,但出现错误:

Outputs:
  LoadBalancerName:
    Description: The DNS Name of the ALB where this container was deploy
    Value: !GetAtt !Ref LoadBalancerARN.DNSName

有没有办法像这样 !Ref 的 !GetAtt ?

其他尝试:

Value:
  !GetAtt
    - DNSName
    - !Ref LoadBalancerARN

这也不行

Value:
  !GetAtt
  - !Ref LoadBalancerARN
  - LoadBalancerARN.DNSName

也许我可以做一些 hacky,比如解析 arn 以获取 dns 名称?

【问题讨论】:

  • 您不能将负载均衡器引用为 cloudformation 资源,除非它是由 Cloudformation 创建的。

标签: amazon-web-services amazon-cloudformation


【解决方案1】:

您可以使用类似这样的东西,而不是使用 Arn

Fn::Join: [ "", [ "http://", !GetAtt <<LoadBalancerResourceName>>.DNSName ] ]

【讨论】:

  • 这个问题的重点是模板中没有定义资源
【解决方案2】:

您不能将负载均衡器作为 cloudformation 资源引用,除非它是由 Cloudformation 创建的。

您需要通过 cloudformation 重新创建负载均衡器,以引用 DNS 名称等资源属性。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-06-23
    • 1970-01-01
    • 2021-12-27
    • 2017-05-28
    • 1970-01-01
    • 2016-04-12
    • 2019-08-15
    • 1970-01-01
    相关资源
    最近更新 更多