awslabs / fargatecli

CLI for AWS Fargate
Apache License 2.0
893 stars 114 forks source link

Load Balancer Problem with Pre-Existing Target Group #29

Open MedLexAI opened 6 years ago

MedLexAI commented 6 years ago

Ok based on your previous response I was able to successfully create a load balancer on port 8080 and then create a service with an alias that mapped http://example.com:8080 -> lb -> two Fargate tasks. Awesome!

So then I destroyed the load balancer and the service, and then went back to create the load balancer again but this time specifying port 443, and got this error message:

$ fargate lb create testapp --certificate example.com --port 443 --verbose
[d] Creating ECS cluster
[d] Created ECS cluster fargate
[d] Creating ELB load balancer
[d] Creating ELB target group
[!] Could not create ELB target group
DuplicateTargetGroupName: A target group with the same name 'testapp-default' exists, but with different settings
        status code: 400, request id: 1234-2345-345678

My current architecture is just a Docker image on the backend listening on port 8080 (no SSL currently). I am trying to create a load balancer that will accept connections on 443 with our Amazon Route 53 SSL certs, and then forward those requests to the Fargate Docker tasks that have exposed port 8080.

Is this a possible scenario or have anything to do with this error message above? Do the external application load balancer ports have to map to the Fargate task ports with a 1:1 mapping, e.g. lb:443 -> task:443?

jpignata commented 6 years ago

Looks like you've found a bug. There's a bit of awkwardness with the order of creation and deletion of load balancers and services, and it looks like I blew it in this scenario. 🤬

To delete the vestigial target group, you can run:

aws elbv2 delete-target-group --target-group-arn `aws elbv2 describe-target-groups --names testapp-default --query TargetGroups[].TargetGroupArn --output text`

This command will find the ARN of the errant target group and delete it.

The scenario you pose above is really my target use case. A 1:1 mapping is not required. It's just a matter of creating a load balancer listening on HTTPS and a service listening on port 8080. Let me know if I can help you further get this running! I'm leaving this issue open to investigate this target group business, and I suspect it's related to https://github.com/jpignata/fargate/issues/9.

MedLexAI commented 6 years ago

Hey that did the trick, thanks! Everything is running perfectly now, your project is extremely helpful!

jpignata commented 6 years ago

Root cause: Destroy needs to delete all load balancer listeners before destroying the target group.

arvinep commented 5 years ago

Is this bug somehow scheduled to get fixed in any release? In which release we can expect the fix?