如何从 returns 固定响应的 CloudFormation 创建 AWS LB 监听器?

How to create a AWS LB Listener from CloudFormation that returns a fixed response?

从 Load Balancer Lister 配置页面,在 AWS 控制台中,它允许您创建具有默认操作的侦听器,如下所示:

固定响应选项允许您指定 http return 代码和正文:

以下是已知有效的 CloudFormation 示例。不确定如何编辑它以支持非转发操作。

MyServicesLoadBalancerListener:
    Type: AWS::ElasticLoadBalancingV2::Listener
    Properties:
        LoadBalancerArn: !Ref MyServicesLoadBalancer
        Port: 80
        Protocol: HTTP
        DefaultActions:
            - Type: forward
              TargetGroupArn: !Ref MyServicesTargetGroup

如何使用 CloudFormation 执行此操作? documentation here 似乎表明 CloudFormation 仅支持转发规则。

谢谢

还不可能。已在 forums 上提出要求,但没有预计到达时间。

根据 AWS CloudFormation 的 Release History,该功能于 2018 年 11 月 19 日添加。这应该会复制您使用控制台图片显示的固定响应。

MyServicesLoadBalancerListener:
  Type: AWS::ElasticLoadBalancingV2::Listener
  Properties:
    LoadBalancerArn: !Ref MyServicesLoadBalancer
    Port: 80
    Protocol: HTTP
    DefaultActions:
      - Type: fixed-response
        FixedResponseConfig:
          ContentType: "text/plain"
          MessageBody: "You've reached the listener! Congrats!"
          StatusCode: "503"