嗨,我在AWS CDK工作。我正在尝试创建具有应用程序负载平衡的ECS。我创建了ECS集群、任务定义、负载均衡和listner。在
下面是我的负载平衡器。在
lb = elbv2.ApplicationLoadBalancer(
self, "MWSLoadBalancer",
vpc = vpc,
internet_facing= True,
security_group= mws_vpc_sg_alb
)
下面是我的听众
^{pr2}$下面是健康检查
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 synth时自动创建的一个组。下一步我想把listner规则应用到我的ALB中。listner规则的云形成模板如下。在
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
我试着创建listner规则如下。在
elbv2.ApplicationListenerRule(self, id = "listner rule", path_pattern="/api/*", priority = 1, listener = listener)
这是在扔东西
Listener rule needs at least one action
有人能帮我找出这个错误吗?在
创建ApplicationListenerRule时,必须指定一个操作,该操作是target_group、fixed_response或redirect_response之一。在
只需注意,本例中有一个CDK模式,aws-ecs模式,它为常见的体系结构模式提供了更高层次的构造。在
https://docs.aws.amazon.com/cdk/api/latest/docs/aws-ecs-patterns-readme.html
相关问题 更多 >
编程相关推荐