How to assign same dynamic port to UDP and TCP ports on the same container

0

Hi ! I have a container that I want to run in ECS, EC2 supported. My container runs a UDP Server at, let's say, port 2020. I have configured dynamic port mapping for task definition, so when I run the container, it assigns for example the port 32770 to port 2020 UDP As I need healthcheck from balancer, and needs to be TCP, I run a second tiny process that listens on 2020 TCP, and I configured the target group healthcheck to run on traffic port. But port for the second TCP port mapping is not 32770, but a different one, let's say 32771, which balanacer does not know to run the healtcheck. So task ends up being terminated after 3 healthcheck attempts. in docker and docker compose this is totally possible, by doing like this for example: ports: - "4379:2020/udp" - "4379:2020" Why can ECS assign ports like this for my case: ports: - "32770:2020/udp" - "32779:2020"

Is this not possible for bridged, ec2 backed, dynamic port ECS Tasks ? awful limitation....

asked 7 months ago315 views
2 Answers
0

What you can do is setup a sidecar container along side your UDP container that supplies the TCP endpoint for health checks.

The side car would check the service is running on the main ECS task and this would be the Health Check container.

I think this issue you are facing is in the pipeline but do not quote me on it. https://github.com/aws/copilot-cli/pull/4980

profile picture
EXPERT
answered 7 months ago
  • The side car does need a port mapping for the ELB to call the healthcheck ebndpoint and determine the target is healthy. Actually I tested that first (run 2 containers for the same task definition), but port mapping configures 2 different ports (again, 32770 and 32771). And on target group, the task only shows 32770 as traffic port. And traffic port is the only port that ELB knows for calling healthcheck (I mean, i cannot put the UDP port fixed because I would not be able to run multiple tasks in the same instance)

  • Yeah your right.. this is not possible at this time

0

Hello. In Amazon Elastic Container Service (ECS), dynamic port mapping is indeed a bit different from Docker Compose and may not allow you to map both UDP and TCP ports to the same dynamic port number for the same container. This limitation arises from how ECS handles dynamic port mapping.

When you define port mappings in your ECS task definition, you can specify the container port, but the host port is assigned dynamically by ECS. ECS ensures that there are no conflicts by assigning unique host port numbers to each container in the task. However, this approach may result in different host port numbers for UDP and TCP protocols for the same container.

Best regards, ANdrii

profile picture
EXPERT
answered 7 months ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions