I'm using AWS ECS to start containers to run automated tests and their number cannot be known beforehand, because they are triggered by different events.
For some config reasons I have to start these tasks in EC2
mode only (not FARGATE
),
The issue is: I need to add new containers to a running task, but I couldn't achieve that, the only way I found is to start a new task for each new container, but this solution is very expensive in some cases.
I'm using boto3
to start the new tasks&containers, I share with you this part of code to do that:
client = boto3.client('ecs', region_name="eu-west-1")
networkConfiguration = {
'awsvpcConfiguration': {
'subnets': ['subnet-01', 'subnet-06'],
}
}
resp = client.run_task(
cluster='run-on-demand',
launchType='EC2',
taskDefinition="task-01-ec2",
networkConfiguration=networkConfiguration,
overrides={
'containerOverrides': [
{
'name': "task-01-c1-ec2",
'environment': env_vars,
'cpu': 512,
'memory': 2048
}
],
},
startedBy="admin",
count=1
)
so my question is: is there any way to add new container to a running task ?
short answer: it is not possible, because the containers are defined at task creation time only.