【发布时间】:2020-03-30 00:28:19
【问题描述】:
您好,我正在使用 AWS CDK。我正在尝试使用应用程序负载平衡创建 ECS。我创建 ECS 集群、任务定义、负载均衡器和侦听器。
下面是我的负载均衡器。
lb = elbv2.ApplicationLoadBalancer(
self, "MWSLoadBalancer",
vpc = vpc,
internet_facing= True,
security_group= mws_vpc_sg_alb
)
下面是我的听众
listener = lb.add_listener(
"MWSLoadBalanceListener",
port = 80,
open = True,
)
下面是健康检查
health_check = elbv2.HealthCheck(
interval=core.Duration.seconds(60),
path="/",
timeout=core.Duration.seconds(5)
)
下面是添加 ALB 到 ECS。
target = listener.add_targets(
"MWSLoadBalancerTargetGroup",
port=80,
targets=[service],
health_check=health_check,
)
根据https://docs.aws.amazon.com/cdk/api/latest/docs/aws-elasticloadbalancingv2-readme.html#targets-and-target-groups,如果我们将平衡目标(例如 AutoScalingGroups、ECS 服务或单个实例)直接添加到您的侦听器,则会自动为您创建相应的 TargetGroup。 所以我没有创建任何目标组,而是在我做 cdk 合成器时自动创建的。接下来我想对我的 ALB 设置监听器规则。监听器规则成云模板如下。
MWSLoadBalancerHttpListenerRule:
Type: "AWS::ElasticLoadBalancingV2::ListenerRule"
DependsOn: MWSLoadBalancer
Properties:
Actions:
- Type: forward
TargetGroupArn: !Ref MWSTargetGroup
ListenerArn: !Ref MWSLoadBalanceListener
Conditions:
- Field: path-pattern
Values:
- "/api/*"
Priority: 3
我尝试创建如下的监听器规则。
elbv2.ApplicationListenerRule(self, id = "listner rule", path_pattern="/api/*", priority = 1, listener = listener)
这是在扔
监听器规则至少需要一个动作
有人可以帮我找出这个错误吗?
【问题讨论】:
标签: python amazon-web-services amazon-cloudformation aws-cdk aws-load-balancer