Your setup looks almost correct. However, you need to set your Target Group to point to port 4000 instead of 443. Otherwise it will be unable to establish a connection with your Fargate task.
In addition, you will want to confirm your Fargate security group allows incoming traffic from the Load Balancer, and you'll want to make sure your health check is configured and it shows healthy targets.
The errors you're receiving mean:
- 503 Service Temporarily Unavailable -- Your Fargate task(s) are not running, and there are no targets registered to the load balancer.
- 504 Gateway Time-out -- There is at least one target registered to the load balancer, but it's not responding on the configured port.
The reason it's flipping between 503 and 504 is because your Target Group cannot reach your Fargate task, so the health check is failing, and the task is getting restarted over and over.
If you clear up the connectivity between the Target Group and the Fargate task, this will probably solve the problem.
How to set the Load balancer service to route a certain host to a fargate task?Accepted Answerasked 5 months ago
How to make a AppConfig-managed configuration file on S3 available to an ECS service on Fargate?Accepted Answerasked a month ago
Cannot select a target group with alb target type when creating an application load balancerAccepted Answerasked 5 months ago
Health check at NLB level for a Fargate Serviceasked 6 months ago
NLB, Target Groups, Fargate Services and Tasks, and containers with multiple portsAccepted Answerasked a month ago
Service stuck in "pending" on EKS with FargateAccepted Answerasked 2 years ago
Wordpress in Docker container on Fargateasked 8 months ago
How to make HTTPS ALB that targets other TCP port of a fargate service?asked 4 months ago
How to make ALB seamlessly re-forward to a healthy target?asked 7 months ago
Container cannot bind to port 80 running as non-root user on ECS FargateAccepted Answerasked 8 months ago