Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a aws fargate service with multiple load balancers

We are trying to create a service with the specified task definition using the create-service command of aws ecs cli. Our task definition is people-cloud:27.

 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,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]}"

The command mentions that it can take multiple load balancers as input but when we provide them in comma separated format only the last one is taken into account.

In this case only one that is attached to app2 container is published in the output. Need help on this how to provide multiple load balancer information in the cli command.

like image 836
GJoshi Avatar asked Sep 11 '25 22:09

GJoshi


1 Answers

You can add JSON to any AWS CLI command.

aws ecs create-service --cluster mycluster \
    --cli-input-json '{"loadBalancers": [
    {
        "targetGroupArn": "my_target1_arn",
        "containerName": "mycontainer",
        "containerPort": 8080
    },
    {
        "targetGroupArn": "my_target2_arn",
        "containerName": "mycontainer",
        "containerPort": 80
    }
    ]}' \
    --service-name myservice \
    ...
like image 199
ANDgineer Avatar answered Sep 13 '25 12:09

ANDgineer