How to solve the problem that ECS task not being connected to ALB properly.

·

2 min read

During the deployment stage, I initially ran a container on ECS. This container was placed in a target group that was connected to an application load balancer. Subsequently, I created a CodePipeline with the source being an image in ECR and the task definition residing in CodeCommit.

However, I encountered a recurring issue every time I deployed an application through the pipeline. The server would return a 503 error, indicating that the target group was not properly connected. To resolve this, I had to check the CodeDeploy settings and ensure that the listener port was correctly configured to match our usage, which is port 443. In my case, the listener port was set to 80, which caused the issue.

When a new task definition is deployed, CodeDeploy generates a new set of ECS tasks with the updated image version, and waits for them to become healthy before proceeding with the deployment process. After the new tasks are deemed healthy, CodeDeploy updates the ECS service to utilize the new task definition, which in turn updates the instances running in the service.

Even when an application is deployed through the CodePipeline, it is automatically connected to the load balancer. This is because the load balancer is configured to use a target group that is already associated with the ECS service. When CodeDeploy updates the service to utilize the new task definition, it automatically registers the new instances with the target group.

Overall, CodeDeploy and CodePipeline are powerful tools, and it is important to configure them correctly to ensure optimal functionality.