如何通过 aws ecs cli 服务命令注册多个目标组

How to register multiple target groups via aws ecs cli service command

我目前已经通过aws ecs cli compose service up cli命令部署了一个web服务器,并且我进一步在route 53服务中注册了一个域,通过Amazon Certificate Manager注册了一个证书。利用 ALB(应用程序负载平衡器),我能够为我的 Web 应用程序执行动态端口映射和 https,但问题就在这里。

使用 docker compose 作为我的 web 应用程序的蓝图,它由 3 个容器、前端、环回和数据库 (mongo) 组成,我的前端容器的动态端口映射和 https 已启动并且运行 很好

但是问题出在环回容器上,前端有可能需要通过环回API服务器(使用3002端口)获取一些东西,但是环回容器没有配置调用 API.

时导致以下错误的 https

通过ecs cli compose service up命令,我可以配置目标组允许elb将请求转发到前端容器(使用--target-group-arn--container-name--container-port属性来指定具有特定目标组的前端容器),但此命令似乎无法将第二个目标组映射到我的环回容器。阅读 https://docs.aws.amazon.com/AmazonECS/latest/developerguide/register-multiple-targetgroups.html 似乎允许多个目标组用于服务的可能性,但我无法弄清楚如何使用 create service 命令来 link 我的 docker 容器而不使用用户 ecs cli compose service up 命令。

有没有办法

  1. 使用 ecs cli compose service up 命令在我的容器上注册多个目标组?
  2. 也在我的环回上应用 https URL(哪个域名是 myDomain.com:3002)?

============================================= =========

Follow-up 任务

  1. 创建了 2 个目标群体

  1. 已配置的规则和侦听器

  1. 知道ecs cli service up不能注册多个组,我尝试通过console注册,还是只能注册1个容器

感谢并感谢所有帮助

  1. 就您的问题而言,可以使用 AWS 控制台执行该操作,但目前 ecs cli 目前 does not support multiple target group

你可以检查这个 also consider this amazon-ecs-cli-register-service

  1. 第二个错误发生在前端应用程序尝试使用负载混合 HTTPhttps 资源时。您可以查看错误,可以有基于 HTTP 的静态或 API 调用,将所有这些调用转换为 HTTPS 然后它应该可以正常工作。您可以检查错误似乎是从 http 站点加载静态文件。

应用 HTTPS 后,它应该指向 https://example.comhttps://api.example.com,如果它与标准 HTTPS 端口绑定,则 HTTPs 调用不需要该端口。

更新:

ALB 目标组基于目标组路由流量,因此目标组包含所需的容器。添加屏幕截图以使其更加清晰。

ecs cli compose service up 包含一个参数 --target-groups 允许您一次添加多个目标组。

ecs-cli compose --file "../../src/docker-compose.yml" `
                --ecs-params "../../src/ecs-params.yml" `
                --project-name xxxxx service up  `
                --target-groups "targetGroupArn=arn:aws:elasticloadbalancing:eu-west-3:xxxxx:targetgroup/xxxx_tg1,containerPort=80,containerName=webapi" `
                --target-groups "targetGroupArn=arn:aws:elasticloadbalancing:eu-west-3:xxxxx:targetgroup/xxxx_tg2,containerPort=81,containerName=webapi2" `
                --cluster-config myconfig`
                --ecs-profile myprofile

ecs-cli compose service up documentation