Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running multiple ECS tasks based on same task definitions in one host, using different ports

I have one ecs task definition. Can multiple tasks of the above task definition can run on one EC2 instance on several ports ?

I have already have running several tasks running on several ec2 instances. I want to reduce the consumption of resources. As one EC2 instance has more than enough resources to run several tasks. Is it possible to run same task several times on different ports on one EC2 instance ?

like image 788
Lahiru Liyanapathirana Avatar asked Dec 19 '16 11:12

Lahiru Liyanapathirana


People also ask

Can an ECS service have multiple task definitions?

You can define different IAM roles for different tasks in Amazon ECS. Use the task definition to specify an IAM role for that application.

How many ECS tasks can run in parallel?

Services configured to use Amazon ECS service discovery have a limit of 1,000 tasks per service.

Can a task definition have multiple containers?

You can define multiple containers in a task definition. The parameters that you use depend on the launch type that you choose for the task. Not all parameters are valid.

How many containers can be defined in a task definition in ECS?

The task definition is a text file, in JSON format, that describes one or more containers, up to a maximum of ten, that form your application.


2 Answers

Yes, ECS has very good support for this since 2016. You can leave the host port empty in the container definition, this will result in a random port to be chosen for your container. As a result, more instances of the same task definition can run on one ECS instance.

You can configure your ECS service in combination with an Application Load Balancer so that when it starts a new task, it will register the port number in the associated target group. This way you never have to deal with the random port.

If you setup your service via the AWS console, configuration is pretty straightforward.

like image 62
Bram Avatar answered Nov 13 '22 15:11

Bram


This can be configured by setting Host Port to be 0 in Port Mappings setting of Container Definitions while defining Task.

Following setting is available in Container Definition of Task.

enter image description here

It allows ECS to assign random ports to Tasks running in same EC2.

For more details please check - Setup Dynamic Port Mapping for ECS

like image 36
Nikhil Prakash Avatar answered Nov 13 '22 15:11

Nikhil Prakash