Search code examples
amazon-web-servicesdockeramazon-ecsamazon-elb

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


I have currently deployed a web server via aws ecs cli compose service up cli command, and I further registered a domain in route 53 service, register a certificate through Amazon Certificate Manager. Making use of the ALB (application load balancer), I am able to perform dynamic port mapping and https for my web application, but here is the problem.

Using docker compose as the blueprint for my web application, which consists of 3 containers, frontend, loopback and database (mongo), my frontend container's dynamic port mapping and https are up and running fine

enter image description here

However the problem comes to the loopback container, there are chances frontend needs to fetch something via loopback API server (which makes use of 3002 port), but the loopback container does not is not have configured in https which causes the error below when calling the API.

enter image description here

Through ecs cli compose service up command, I can configure the target group to allow elb to forward the request to frontend container (using --target-group-arn, --container-name and --container-port attributes to specify the frontend container with the specific target group), but this command seems unable to map the 2nd target group to my loopback container. Reading https://docs.aws.amazon.com/AmazonECS/latest/developerguide/register-multiple-targetgroups.html which seems to allow the possibility of multiple target groups for a service, but I cannot figure out how to use create service command to link up my docker containers without using user ecs cli compose service up command.

Is there a way to

  1. Use ecs cli compose service up command to register multiple target groups on my containers?
  2. Apply https also on my loopback URL (which domain name is myDomain.com:3002)?

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

Follow-up tasks

  1. Created 2 target groups

enter image description here

  1. Configured rules and listeners

enter image description here enter image description here

  1. Knowing ecs cli service up cannot register multiple groups, I tried to do via console, still only 1 container can be registered enter image description here

Thanks and appreciate for all helps


Solution

  • ecs cli compose service up contains a parameter --target-groups allowing you to add multiple target groups at once.

    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