Search code examples
amazon-web-servicesamazon-ecs

Several Amazon ECS tasks on the same instance host


Say I have an autoscaling group with initial number of 2 instances. Assume that instances of this autoscaling group would be of the same type (hence the same amount of memory and CPU). The maximum number of instances isn't relevant in this case. Also I have an ELB which load-balancing load among instances of this group. Besides this, instances of this autoscaling group are members of some fresh ECS cluster I've created earlier. There is only one task definition in this case with only one container which would use 512Mb of RAM. Also this container requires port mapping from host's 80 to container's 5000.

Say I've spun up this autoscaling group and 2 initial instances are now ready to be used. Then I'm trying to spawn a service of 4 tasks based on the aforementioned task definition. Imagine that this tasks would perfectly fit this 2 instances if they were placed by two (if the hosts had 1Gb of RAM each).

Would this setup even be legitimate? If so then what would happen with port mappings because there would be 2 identical containers on one host?


Solution

  • You would forward the 5000 to different instance ports (since you can't bind 80 multiple times).

    You could then use an ELB to map across the ports. this post answers the specifics.

    You'd want to standardize the ports of service 1 across the cluster so that you could bind an ELB to it. Ie. ELB port 80 can't be mapped to 5000 and 5001. So port 5000 would be forwarded on both instances.

    enter image description here