AWS CDK:负载平衡器侦听器转发给ECS

发布于 2025-02-11 16:21:31 字数 469 浏览 2 评论 0原文

我正在用CDK(打字稿)代替控制台定义的基础架构。
我需要知道如何将通信转发到端口80到ECS任务。

在控制台中,我在目标组中设置了ECS任务的IP地址。
以同样的方式,我如何将负载平衡器与CDK中的EC相关联?
也许这样做的唯一方法是用L1代码编写它? (cfntargetGroup类?)

    const lb = new elbv2.ApplicationLoadBalancer(this, 'LB', {
      vpc,
      internetFacing: true
    })

    lb.addListener('Listener', {
      port: 80,
      defaultTargetGroups: []  // pass something here?
    })

I am replacing the infrastructure defined in the console with CDK(TypeScript).
I need to know how to forward the communication to port 80 to the ECS task.

In the console, I set the IP address of the ECS task in the Target groups.
In the same way, how can I associate the Load Balancer with ECS in CDK?
Perhaps the only way to do this is to write it in L1 code? (CfnTargetGroup class?)

    const lb = new elbv2.ApplicationLoadBalancer(this, 'LB', {
      vpc,
      internetFacing: true
    })

    lb.addListener('Listener', {
      port: 80,
      defaultTargetGroups: []  // pass something here?
    })

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

段念尘 2025-02-18 16:21:31

选项1:将听众添加到ALB。将ECS服务添加为侦听器目标。完整示例在这里

const listener = lb.addListener('PublicListener', { port: 80, open: true });

listener.addTargets('ECS', {
  port: 80,
  targets: [
    service.loadBalancerTarget({
      containerName: 'web',
      containerPort: 80,
    }),
  ],
});

选项2:使用L3 applicationloadbalancedfargateservice 或其 aws_ecs_patterns 在ALB后面创建ECS服务。

Option 1: Add a listener to the ALB. Add the ECS Service as a listener target. Full example here.

const listener = lb.addListener('PublicListener', { port: 80, open: true });

listener.addTargets('ECS', {
  port: 80,
  targets: [
    service.loadBalancerTarget({
      containerName: 'web',
      containerPort: 80,
    }),
  ],
});

Option 2: Use the L3 ApplicationLoadBalancedFargateService or its EC2 cousin from aws_ecs_patterns to create an ECS Service behind an ALB.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文