AWS GameLift with ECS and container port configuration


I am trying to implement my game servers solution based on this AWS example: GitHub - aws-samples/amazon-gamelift-fleetiq-with-amazon-ecs and I have some questions to the approach.

In the example, the game server port is static and configured on the container start but for real purposes, we cannot do it since we can run multiple game servers per node.

I am trying to figure out, how I can pass the proper unallocated port to the container during the startup. E.g. I can implement some kind of orchestrator that can manage all allocated ports and pass to the new containers free ports. But with GameLift this approach seems doesn’t work since we don’t know on which EC2 node my game server will be allocated → we cannot guess, which ports are free.

Another option is to try to guess free ports on the node during the container startup but seems like it’s also impossible since the game server is working inside the container.

How can solve this issue?

Thanks in advance!

I think I got it, how it works - if hostPort is settled to 0, ECS handles port choosing automatically. I guess it is the answer for the question.