1
votes

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

2

2 Answers

3
votes
  1. As far your question is a concern, it possible to perform that using AWS console, but ecs cli currently does not support multiple target group at the moment.

you can check this ecs-cli compose service up with a load balancer also consider this amazon-ecs-cli-register-service.

  1. The second error occurred when the frontend application tries to use load mix HTTP and https resources. you can look into the error, there can be static or API calls that are based on HTTP, convert all these calls to HTTPS then it should work fine. you can check error seems like static file loading from http site.

Once you applied HTTPS it should point to https://example.com or https://api.example.com, the port is not required with HTTPs call if its bind with standard HTTPS port.

Update:

ALB target group route traffic base on the target group, so the target group contain the desired container. adding screenshot to make it more clear. enter image description here

2
votes

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