我正在尝试为ALB编写一个CloudFormation模板,但我仍然想要将ALB的HTTP侦听器流量重定向到HTTPS侦听器。文档仅提及转发/重定向到目标组。
我知道使用Web界面(AWS控制台)是可以实现的,我想避免这种情况。在服务器上处理它也不适合我。
这个ALB的功能是不是在CloudFormation中实现,而是存在于Console中?
2018年11月19日,亚马逊推出了Elastic Load Balancer Listener的RedirectConfig。
下面是通常的HTTP到HTTPS重定向的示例配置。将“PublicLoadBalancerBackend”替换为负载均衡器CF对象。
PublicLoadBalancerHttpRedirectListener:
Type: AWS::ElasticLoadBalancingV2::Listener
DependsOn:
- PublicLoadBalancerBackend
Properties:
DefaultActions:
- RedirectConfig:
Host: "#{host}"
Path: "/#{path}"
Port: 443
Protocol: "HTTPS"
Query: "#{query}"
StatusCode: HTTP_301
Type: redirect
LoadBalancerArn: !Ref 'PublicLoadBalancerBackend'
Port: 80
Protocol: HTTP
RedirectConfig上的Cloudformation文档:https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-elasticloadbalancingv2-listener-redirectconfig.html
关于监听器动作的Cloudformation文档:https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-elasticloadbalancingv2-listener-defaultactions.html
看起来现在唯一的选择是编写自定义资源来管理它。请参阅:https://github.com/jheller/alb-rule以获得实现的可靠示例 - 或者将其用作您自己实现的基础。 (我与上面的代码没有任何关系 - 只是因为我自己需要做同样的事情)
事实证明,到目前为止,redirect
并没有在CF中实现,遗憾的是,可以预见AWS - source。