- Newest
- Most votes
- Most comments
Could you clarify if you're referring to two containers within the same task definition or two separate ECS tasks?
When you click on "Register target," it adds a target to the ELB manually, bypassing the ECS service. If that target becomes unhealthy later, it won’t be automatically replaced due to the manual registration, so it's not advisable to do this.
You can only associate a load balancer with an ECS service during its creation. To update the service afterward, you’ll need to use the CLI command update-service
(see the documentation here: https://awscli.amazonaws.com/v2/documentation/api/latest/reference/ecs/update-service.html).
I recommend using the CLI to update the service or creating a new service with the updated task definition (which includes both containers) and then associating the load balancer from scratch. This way, the load balancer will automatically add the necessary listener rules and targets.
Note: Using the IP address option, you might have noticed that the IP address changed each time. This is expected behavior because whenever a task is recycled, it launches with a new IP. If ECS manages the registration, it will automatically update the load balancer with the new IP address. However, since you registered the target manually, ECS had no way to make any updates to the configuration.
It seems you're encountering some challenges with attaching your second ECS container to the load balancer. Let's address these issues step by step:
-
For ECS services using a load balancer, you need to specify the load balancer configuration when creating or updating the service, not by manually registering targets in the target group.
-
The absence of the load balancer section in the service for container 2 could be due to how the service was initially created. You may need to update the service to include load balancer configuration.
-
When using ECS with a load balancer, you should use the 'ip' as the target type for your target group, not 'instance', especially if your tasks are using the 'awsvpc' network mode.
-
For path-based routing, you can use an Application Load Balancer (ALB) and configure multiple target groups with different path patterns.
Here's what you can do:
-
Ensure your load balancer is an Application Load Balancer for path-based routing.
-
Create a new target group for the "/container2" path with target type 'ip'.
-
Update your ECS service for container 2 to include the load balancer configuration. You'll need to specify:
- The container name (as it appears in the task definition)
- The container port
- The target group ARN for the "/container2" path
-
In the load balancer listener rules, ensure you have a rule that forwards traffic for the "/container2" path to the correct target group.
-
If you're using the AWS CLI or SDK, you can update the service with the load balancer configuration. If using the console, you might need to create a new service with the correct configuration.
Remember, you can't attach more than five target groups to a single ECS service. Also, ensure that your load balancer subnet configuration includes all Availability Zones where your container instances reside.
If you continue to face issues, double-check your IAM permissions, VPC configurations, and ensure that your ECS tasks are in the same VPC as your load balancer.
Sources
Troubleshooting service load balancers in Amazon ECS - Amazon Elastic Container Service
LoadBalancer - Amazon Elastic Container Service
Use a Network Load Balancer for Amazon ECS - Amazon Elastic Container Service
Fully Managed Container Orchestration – Amazon Elastic Container Service (Amazon ECS) Features – Amazon Web Services
You are trying to register EC2 instances when clicking register on the target group. You can’t register ECS services this way.
When you create an ECS service this is the point you register the service with a target group and load balancer.
Relevant content
- Accepted Answerasked 2 months ago
- AWS OFFICIALUpdated 7 months ago
- AWS OFFICIALUpdated a year ago
- AWS OFFICIALUpdated 2 months ago
- AWS OFFICIALUpdated 4 months ago
Both containers have separate task definitions.