[英]AWS CloudFormation Application Load Balancer - how to redirect HTTP listener to HTTPS listener?
I am trying to write a CloudFormation template for ALB, but got stuck on the point where I would like to redirect ALB's HTTP listener's traffic to HTTPS listener.我正在尝试为 ALB 编写 CloudFormation 模板,但卡在了我想将 ALB 的 HTTP 侦听器的流量重定向到 HTTPS 侦听器的点上。 Docs mention only forwarding/redirection to the target group.
文档只提到转发/重定向到目标组。
I am aware that it is achievable using the web interface (AWS Console), which I want to avoid.我知道使用我想避免的 Web 界面(AWS 控制台)可以实现它。 Also handling it on the server is a no go for me.
在服务器上处理它也不适合我。
Is this ALB's feature simply not implemented in CloudFormation, but exists in Console?这个 ALB 的功能是否根本没有在 CloudFormation 中实现,但存在于控制台中?
On November 19, 2018 Amazon introduced the RedirectConfig for the Elastic Load Balancer Listener. 2018 年 11 月 19 日,Amazon 为 Elastic Load Balancer Listener 引入了 RedirectConfig。 This listener type is also used for the Application Load Balancer (ALB).
此侦听器类型也用于应用程序负载均衡器 (ALB)。
Below you find an example configuration for the usual HTTP to HTTPS redirect .下面是通常的HTTP 到 HTTPS 重定向的示例配置。 Replace 'PublicLoadBalancerBackend' with your load balancers CloudFormation object.
将“PublicLoadBalancerBackend”替换为您的负载均衡器 CloudFormation 对象。
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
CloudFormation Documentation on the RedirectConfig: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-elasticloadbalancingv2-listener-redirectconfig.html RedirectConfig 上的 CloudFormation 文档: https : //docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-elasticloadbalancingv2-listener-redirectconfig.html
CloudFormation Documentation on the Listener Action: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-elasticloadbalancingv2-listener-defaultactions.html有关侦听器操作的 CloudFormation 文档: https : //docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-elasticloadbalancingv2-listener-defaultactions.html
Looks like for now the only option is to write a custom resource to manage it.看起来现在唯一的选择是编写一个自定义资源来管理它。 See: https://github.com/jheller/alb-rule for a solid example to either implement - or use as a base for your own implementation.
请参阅: https : //github.com/jheller/alb-rule一个可靠的例子来实现 - 或用作您自己实现的基础。 (I have no affiliation with the above code - just found for my own need to do the exact same thing)
(我与上面的代码没有任何关系 - 只是为了我自己需要做同样的事情而发现的)
事实证明,到目前为止, redirect
尚未在 CF 中实现,可悲的是,AWS- source预计会发生什么。
They implemented it recently.他们最近实施了它。 Take a look at: https://docs.aws.amazon.com/elasticloadbalancing/latest/APIReference/API_RedirectActionConfig.html
看看: https : //docs.aws.amazon.com/elasticloadbalancing/latest/APIReference/API_RedirectActionConfig.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.