cloudformation 从 LoadBalancerArn 获取 DNSName

cloudformation to get DNSName from LoadBalancerArn

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

我将完整的 arn 作为参数传递给需要它的资源,就像侦听器一样:

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

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

这样做我可以 return 作为参数传入的 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

也许我可以做一些骇人听闻的事情,比如解析 arn 以获取 dns 名称?

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

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

你可以使用类似这样的东西来代替 Arn

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