Overriding AWS batch submit_job cpu/memory parameters

Viewed 128

I built a job definition using a docker image (on ECR) and according to the documentation and this guide the vCPU and memory parameters should be override using the containerOverrides dictionary:

"containerOverrides": {    "resourceRequirements": [
      {
         "type": "MEMORY",
         "value": "8192"
      },
      {
         "type": "VCPU",
         "value": "4"
      }    ], }

So this is how I built my code (python):

import boto3
client = boto3.client('batch')
resource_requirements = [
        {
            'value': str(cpu_count),
            'type': 'VCPU'
        },
        {
            'value': str(memory),
            'type': 'MEMORY'
        }
    ]
container_overrides = {
    'command': ["python", "main.py", "example"],
    'resourceRequirements': resource_requirements,
}

result = client.submit_job(
    jobName=job_name,
    jobQueue=job_queue,
    jobDefinition=job_definition,
    containerOverrides=container_overrides,
)

But still the AWS console displays the original values for cpu & memory and this error as well:

Configuration conflict This value was submitted using containerOverrides.vcpus which has been deprecated and was not used as an override. Instead, the VCPU value found in the job definition’s resourceRequirements key was used instead. More information about the deprecated key can be found in the AWS Batch API documentation.

So I tried to do the exact opposite to what the documentation says and changed my code to look like this:

import boto3
client = boto3.client('batch')
resource_requirements = [
        {
            'value': str(cpu_count),
            'type': 'VCPU'
        },
        {
            'value': str(memory),
            'type': 'MEMORY'
        }
    ]
container_overrides = {
    'command': ["python", "main.py", "example"],
    'vcpus': cpu_count,
    'memory': memory
}

result = client.submit_job(
    jobName=job_name,
    jobQueue=job_queue,
    jobDefinition=job_definition,
    containerOverrides=container_overrides,
)

And now the error is not displayed and the values on the console are overridden. Can someone explain why the documentation and actual results are so different? Maybe I'm missing something?

1 Answers

Your first example and code snippet are correct. I validated this by copying your code. I was able to override the CPUs and Memory in my own batch setup.

The error you get about "This value was submitted using containerOverrides.vcpus" suggests that there is something wrong in the request. I'd expect that error if you did what you showed in your 3rd code snippet, directly placing vcpus into container_overrides.

After verifying that the base configuration works correctly, try using the first approach again, being sure you are containing the resourceRequirements in containerOverrides.

Related