I'm trying to override the CPU and memory limits on a container when using the RunTask command. I'm using the Python SDK, boto3.
The container has default CPU limit of 0 (unlimited) and a soft memory limit of 1024. That's all fine and good.
When I attempt to pass a containerOverrides
list to the RunTask command, I don't get an error, the tasks runs mostly as expected. I'm also overriding the command the container runs, and that works - I can see as the task is running the command has been overridden, and the logs reflect this.
The CPU and memory limits, however, are not being overridden. I'm checking this by peeking at the AWS console and seeing the cpu and memory are listed as 0 and 1024, but the command is shown to be overridden. I can also do a little math by checking on the container instance to confirm the memory is not the desired 2048, but must be 1024.
Here's some simplified code:
import boto3
client = boto3.client('ecs')
overrides = {
"containerOverrides": [
{
"name": "runcommand",
"command": command_wrapper,
"cpu": 512,
"memory": 2048,
"memoryReservation": 2048
}
]
}
response = client.run_task(
cluster='mycluster',
taskDefinition='runcommand-qa',
overrides=overrides,
group='stackoverflow:run-command'
)
And the tasks
section of the response:
'tasks': [{
'taskArn': 'arn:aws:ecs:us-east-1:12345667890:task/72f1a8ae-4f51-4717-acc6-fce3199a9e92',
'group': 'stackoverflow:run-command',
'attachments': [],
'overrides': {
'containerOverrides': [{
'memoryReservation': 2048,
'memory': 2048,
'command': ['sh', '-c', '. /app/bin/activate && ./manage.py help'],
'name': 'runcommand',
'cpu': 512
}]
},
'launchType': 'EC2',
'lastStatus': 'PENDING',
'containerInstanceArn': 'arn:aws:ecs:us-east-1:12345667890:container-instance/f0dd320e-b1de-413d-8e1c-c64b0799e473',
'createdAt': datetime.datetime(2018, 5, 25, 9, 4, 3, 46000, tzinfo = tzlocal()),
'version': 1,
'clusterArn': 'arn:aws:ecs:us-east-1:12345667890:cluster/runcommand-qa',
'memory': '2048',
'desiredStatus': 'RUNNING',
'taskDefinitionArn': 'arn:aws:ecs:us-east-1:12345667890:task-definition/runcommand-qa:127',
'cpu': '512',
'containers': [{
'containerArn': 'arn:aws:ecs:us-east-1:12345667890:container/80949a81-747f-4729-a9d4-922007448729',
'taskArn': 'arn:aws:ecs:us-east-1:12345667890:task/72f1a8ae-4f51-4717-acc6-fce3199a9e92',
'lastStatus': 'PENDING',
'name': 'runcommand',
'networkInterfaces': []
}]
}]
What am I missing here?
cpu and memory needs to be defined in the Task Overrides, not just containerOverrides. like this
notice that inside containerOverrides they are defined as
int
, as task overrides they need to be defined asstr
. this worked for me on FARGATE ecs tasks, with boto3 version 1.15.16