You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

AWS ECS CLI创建Fargate服务时多负载均衡器配置问题求助

解决AWS ECS CLI创建服务时多负载均衡器仅最后一个生效的问题

我之前也踩过这个坑!你当前的写法是把两个负载均衡器的配置都塞进同一个--load-balancers参数里用逗号分隔,这会让CLI把重复的参数键(比如targetGroupArn)覆盖,只保留最后一组配置,自然就只有最后一个负载均衡器生效了。

正确的做法是给每个负载均衡器单独设置一个--load-balancers参数,每个参数里包含对应容器的完整配置项,这样CLI就能识别出这是两个独立的负载均衡器关联条目。

修改后的完整命令:

aws ecs create-service \
  --cluster cloud1 \
  --service-name docker-service \
  --task-definition people-cloud:27 \
  --load-balancers targetGroupArn=arn:aws:elasticloadbalancing:ap-south-1:2******5555:targetgroup/ecsCloud/ee7f4c280b1672aa,containerName=app,containerPort=8080 \
  --load-balancers targetGroupArn=arn:aws:elasticloadbalancing:ap-south-1:2******5555:targetgroup/ecsServer/54fcbf7052957660,containerName=app2,containerPort=2990 \
  --launch-type FARGATE \
  --client-token AMOEBA@123 \
  --desired-count 1 \
  --network-configuration "awsvpcConfiguration={subnets=[subnet-0e11****f9e4218,subnet-0er****ufgrger],securityGroups=[sg-******5b***b3]}"

验证配置是否生效:

服务创建完成后,你可以用这条命令检查负载均衡器的关联情况:

aws ecs describe-service --cluster cloud1 --service docker-service

在返回的JSON结果里找到loadBalancers字段,就能看到两个分别对应app和app2容器的配置条目了。

内容的提问来源于stack exchange,提问作者GJoshi

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.14 09:04:30