amazon-web-servicesamazon-ec2amazon-ecs

Port mapping for AWS ECS


I am deploying my app to a domain I've purchased. My application has a frontend and a backend. My frontend runs on localhost:3000 and calls its backend api on localhost:5000. Are the port mappings on my local machine the same as when creating a task definition on AWS?

enter image description here


Solution

  • I wish there was a simple yes/no answer to this. But there isn't.

    ECS uses 4 networking modes. awsvpc, bridge, host and none. None is not relevant here as there is no networking there.

    For awsvpc, the container gets its own ENI. Which means that your container will act as a host and the port that you expose will be the port that you serve on.

    For bridge, you use the docker network and use ephemeral ports dynamically to map your container ports to. This mode is the best if you want to use multiple copies of the same container/task.

    For host, the container bypasses docker network and uses the EC2 ENIs which limits you by not allowing to run multiple copies of the same container/task on the same EC2 instance if you plan to use port mappings.

    This is explained in detail at: https://docs.aws.amazon.com/AmazonECS/latest/developerguide/task-networking.html