Skip to content

register_job_definition

register_job_definition(
    *,
    config_overrides: Optional[BatchClientConfig] = None,
    job_definition_name: Optional[String] = None,
    type: Optional[JobDefinitionType] = None,
    parameters: Optional[ParametersMap] = None,
    scheduling_priority: Optional[Integer] = None,
    container_properties: Optional[ContainerProperties] = None,
    node_properties: Optional[NodeProperties] = None,
    retry_strategy: Optional[RetryStrategy] = None,
    propagate_tags: Optional[Boolean] = None,
    timeout: Optional[JobTimeout] = None,
    tags: Optional[TagrisTagsMap] = None,
    platform_capabilities: Optional[PlatformCapabilityList] = None,
    eks_properties: Optional[EksProperties] = None,
    ecs_properties: Optional[EcsProperties] = None,
    consumable_resource_properties: Optional[ConsumableResourceProperties] = None,
) -> RegisterJobDefinitionResponse

Registers an Batch job definition.

Parameters:

  • job_definition_name (Optional[String], default: None ) –

    The name of the job definition to register. It can be up to 128 letters long. It can contain uppercase and lowercase letters, numbers, hyphens (-), and underscores (_).

  • type (Optional[JobDefinitionType], default: None ) –

    The type of job definition. For more information about multi-node parallel jobs, see Creating a multi-node parallel job definition in the Batch User Guide.

    • If the value is container, then one of the following is required: containerProperties, ecsProperties, or eksProperties.

    • If the value is multinode, then nodeProperties is required.

    If the job is run on Fargate resources, then multinode isn't supported.

  • parameters (Optional[ParametersMap], default: None ) –

    Default parameter substitution placeholders to set in the job definition. Parameters are specified as a key-value pair mapping. Parameters in a SubmitJob request override any corresponding parameter defaults from the job definition.

  • scheduling_priority (Optional[Integer], default: None ) –

    The scheduling priority for jobs that are submitted with this job definition. This only affects jobs in job queues with a fair-share policy. Jobs with a higher scheduling priority are scheduled before jobs with a lower scheduling priority.

    The minimum supported value is 0 and the maximum supported value is 9999.

  • container_properties (Optional[ContainerProperties], default: None ) –

    An object with properties specific to Amazon ECS-based single-node container-based jobs. If the job definition's type parameter is container, then you must specify either containerProperties or nodeProperties. This must not be specified for Amazon EKS-based job definitions.

    If the job runs on Fargate resources, then you must not specify nodeProperties; use only containerProperties.

  • node_properties (Optional[NodeProperties], default: None ) –

    An object with properties specific to multi-node parallel jobs. If you specify node properties for a job, it becomes a multi-node parallel job. For more information, see Multi-node Parallel Jobs in the Batch User Guide.

    If the job runs on Fargate resources, then you must not specify nodeProperties; use containerProperties instead.

    If the job runs on Amazon EKS resources, then you must not specify nodeProperties.

  • retry_strategy (Optional[RetryStrategy], default: None ) –

    The retry strategy to use for failed jobs that are submitted with this job definition. Any retry strategy that's specified during a SubmitJob operation overrides the retry strategy defined here. If a job is terminated due to a timeout, it isn't retried.

  • propagate_tags (Optional[Boolean], default: None ) –

    Specifies whether to propagate the tags from the job or job definition to the corresponding Amazon ECS task. If no value is specified, the tags are not propagated. Tags can only be propagated to the tasks during task creation. For tags with the same name, job tags are given priority over job definitions tags. If the total number of combined tags from the job and job definition is over 50, the job is moved to the FAILED state.

    If the job runs on Amazon EKS resources, then you must not specify propagateTags.

  • timeout (Optional[JobTimeout], default: None ) –

    The timeout configuration for jobs that are submitted with this job definition, after which Batch terminates your jobs if they have not finished. If a job is terminated due to a timeout, it isn't retried. The minimum value for the timeout is 60 seconds. Any timeout configuration that's specified during a SubmitJob operation overrides the timeout configuration defined here. For more information, see Job Timeouts in the Batch User Guide.

  • tags (Optional[TagrisTagsMap], default: None ) –

    The tags that you apply to the job definition to help you categorize and organize your resources. Each tag consists of a key and an optional value. For more information, see Tagging Amazon Web Services Resources in Batch User Guide.

  • platform_capabilities (Optional[PlatformCapabilityList], default: None ) –

    The platform capabilities required by the job definition. If no value is specified, it defaults to EC2. To run the job on Fargate resources, specify FARGATE. To run the job on Amazon ECS Managed Instances, specify MANAGED_INSTANCES.

    Jobs with the MANAGED_INSTANCES platform capability must use ecsProperties (not containerProperties) and do not support multi-node parallel jobs.

    If the job runs on Amazon EKS resources, then you must not specify platformCapabilities.

  • eks_properties (Optional[EksProperties], default: None ) –

    An object with properties that are specific to Amazon EKS-based jobs. This must not be specified for Amazon ECS based job definitions.

  • ecs_properties (Optional[EcsProperties], default: None ) –

    An object with properties that are specific to Amazon ECS-based jobs. This must not be specified for Amazon EKS-based job definitions.

  • consumable_resource_properties (Optional[ConsumableResourceProperties], default: None ) –

    Contains a list of consumable resources required by the job.

Raises:

  • ClientException –

    These errors are usually caused by a client action. One example cause is using an action or resource on behalf of a user that doesn't have permissions to use the action or resource. Another cause is specifying an identifier that's not valid.

  • ServerException –

    These errors are usually caused by a server issue.

  • UnknownServiceError –

    The service returned an error code this client does not model.

Examples:

RegisterJobDefinition with tags This demonstrates calling the RegisterJobDefinition action, including tags.

>>> client.register_job_definition(job_definition_name='sleep30', type='container', container_properties={'image': 'busybox', 'command': ['sleep', '30'], 'resourceRequirements': [{'type': 'MEMORY', 'value': '128'}, {'type': 'VCPU', 'value': '1'}]}, tags={'Department': 'Engineering', 'User': 'JaneDoe'})
To register a GPU job definition on ECS Managed Instances
This example registers a job definition that requests GPU resources on ECS Managed Instances.
>>> client.register_job_definition(job_definition_name='my-gpu-managed-instances-job-def', type='container', platform_capabilities=['MANAGED_INSTANCES'], ecs_properties={'taskProperties': [{'containers': [{'image': '123456789012.dkr.ecr.us-east-1.amazonaws.com/my-gpu-image:latest', 'name': 'main', 'command': ['nvidia-smi'], 'resourceRequirements': [{'type': 'VCPU', 'value': '4'}, {'type': 'MEMORY', 'value': '16384'}, {'type': 'GPU', 'value': '1'}]}], 'executionRoleArn': 'arn:aws:iam::123456789012:role/ecsTaskExecutionRole'}]})
To register a job definition
This example registers a job definition for a simple container job.
>>> client.register_job_definition(container_properties={'image': 'busybox', 'command': ['sleep', '10'], 'resourceRequirements': [{'type': 'MEMORY', 'value': '128'}, {'type': 'VCPU', 'value': '1'}]}, type='container', job_definition_name='sleep10')
To register a job definition on ECS Managed Instances
This example registers a job definition that runs on ECS Managed Instances using ecsProperties with the MANAGED_INSTANCES platform capability.
>>> client.register_job_definition(job_definition_name='my-managed-instances-job-def', type='container', platform_capabilities=['MANAGED_INSTANCES'], ecs_properties={'taskProperties': [{'containers': [{'image': 'public.ecr.aws/amazonlinux/amazonlinux:2023', 'name': 'main', 'command': ['echo', 'hello managed instances'], 'resourceRequirements': [{'type': 'VCPU', 'value': '1'}, {'type': 'MEMORY', 'value': '1024'}]}], 'executionRoleArn': 'arn:aws:iam::123456789012:role/ecsTaskExecutionRole'}]})
To register a multi-container job definition on ECS Managed Instances
This example registers a job definition with a main container and a sidecar logging container on ECS Managed Instances.
>>> client.register_job_definition(job_definition_name='my-sidecar-managed-instances-job-def', type='container', platform_capabilities=['MANAGED_INSTANCES'], ecs_properties={'taskProperties': [{'containers': [{'image': 'public.ecr.aws/amazonlinux/amazonlinux:2023', 'name': 'main', 'command': ['echo', 'processing data'], 'essential': True, 'resourceRequirements': [{'type': 'VCPU', 'value': '2'}, {'type': 'MEMORY', 'value': '4096'}]}, {'image': 'public.ecr.aws/amazonlinux/amazonlinux:2023', 'name': 'sidecar', 'command': ['echo', 'logging sidecar'], 'essential': False, 'resourceRequirements': [{'type': 'VCPU', 'value': '1'}, {'type': 'MEMORY', 'value': '512'}]}], 'executionRoleArn': 'arn:aws:iam::123456789012:role/ecsTaskExecutionRole'}]})
Source code in docs_src/capo_batch/_services/batch.py
def register_job_definition(
    self,
    *,
    config_overrides: Optional[BatchClientConfig] = None,
    job_definition_name: Optional["capo_batch.types.string.String"] = None,
    type: Optional["capo_batch.types.job_definition_type.JobDefinitionType"] = None,
    parameters: Optional["capo_batch.types.parameters_map.ParametersMap"] = None,
    scheduling_priority: Optional["capo_batch.types.integer.Integer"] = None,
    container_properties: Optional[
        "capo_batch.types.container_properties.ContainerProperties"
    ] = None,
    node_properties: Optional[
        "capo_batch.types.node_properties.NodeProperties"
    ] = None,
    retry_strategy: Optional[
        "capo_batch.types.retry_strategy.RetryStrategy"
    ] = None,
    propagate_tags: Optional["capo_batch.types.boolean.Boolean"] = None,
    timeout: Optional["capo_batch.types.job_timeout.JobTimeout"] = None,
    tags: Optional["capo_batch.types.tagris_tags_map.TagrisTagsMap"] = None,
    platform_capabilities: Optional[
        "capo_batch.types.platform_capability_list.PlatformCapabilityList"
    ] = None,
    eks_properties: Optional[
        "capo_batch.types.eks_properties.EksProperties"
    ] = None,
    ecs_properties: Optional[
        "capo_batch.types.ecs_properties.EcsProperties"
    ] = None,
    consumable_resource_properties: Optional[
        "capo_batch.types.consumable_resource_properties.ConsumableResourceProperties"
    ] = None,
) -> "capo_batch.types.register_job_definition_response.RegisterJobDefinitionResponse":
    """<p>Registers an Batch job definition.</p>

    Args:
        job_definition_name: <p>The name of the job definition to register. It can be up to 128 letters long. It can contain uppercase and lowercase letters, numbers, hyphens (-), and underscores (_).</p>
        type: <p>The type of job definition. For more information about multi-node parallel jobs, see <a href="https://docs.aws.amazon.com/batch/latest/userguide/multi-node-job-def.html">Creating a multi-node parallel job definition</a> in the <i>Batch User Guide</i>.</p> <ul> <li> <p>If the value is <code>container</code>, then one of the following is required: <code>containerProperties</code>, <code>ecsProperties</code>, or <code>eksProperties</code>.</p> </li> <li> <p>If the value is <code>multinode</code>, then <code>nodeProperties</code> is required.</p> </li> </ul> <note> <p>If the job is run on Fargate resources, then <code>multinode</code> isn't supported.</p> </note>
        parameters: <p>Default parameter substitution placeholders to set in the job definition. Parameters are specified as a key-value pair mapping. Parameters in a <code>SubmitJob</code> request override any corresponding parameter defaults from the job definition.</p>
        scheduling_priority: <p>The scheduling priority for jobs that are submitted with this job definition. This only affects jobs in job queues with a fair-share policy. Jobs with a higher scheduling priority are scheduled before jobs with a lower scheduling priority.</p> <p>The minimum supported value is 0 and the maximum supported value is 9999.</p>
        container_properties: <p>An object with properties specific to Amazon ECS-based single-node container-based jobs. If the job definition's <code>type</code> parameter is <code>container</code>, then you must specify either <code>containerProperties</code> or <code>nodeProperties</code>. This must not be specified for Amazon EKS-based job definitions.</p> <note> <p>If the job runs on Fargate resources, then you must not specify <code>nodeProperties</code>; use only <code>containerProperties</code>.</p> </note>
        node_properties: <p>An object with properties specific to multi-node parallel jobs. If you specify node properties for a job, it becomes a multi-node parallel job. For more information, see <a href="https://docs.aws.amazon.com/batch/latest/userguide/multi-node-parallel-jobs.html">Multi-node Parallel Jobs</a> in the <i>Batch User Guide</i>.</p> <note> <p>If the job runs on Fargate resources, then you must not specify <code>nodeProperties</code>; use <code>containerProperties</code> instead.</p> </note> <note> <p>If the job runs on Amazon EKS resources, then you must not specify <code>nodeProperties</code>.</p> </note>
        retry_strategy: <p>The retry strategy to use for failed jobs that are submitted with this job definition. Any retry strategy that's specified during a <a>SubmitJob</a> operation overrides the retry strategy defined here. If a job is terminated due to a timeout, it isn't retried.</p>
        propagate_tags: <p>Specifies whether to propagate the tags from the job or job definition to the corresponding Amazon ECS task. If no value is specified, the tags are not propagated. Tags can only be propagated to the tasks during task creation. For tags with the same name, job tags are given priority over job definitions tags. If the total number of combined tags from the job and job definition is over 50, the job is moved to the <code>FAILED</code> state.</p> <note> <p>If the job runs on Amazon EKS resources, then you must not specify <code>propagateTags</code>.</p> </note>
        timeout: <p>The timeout configuration for jobs that are submitted with this job definition, after which Batch terminates your jobs if they have not finished. If a job is terminated due to a timeout, it isn't retried. The minimum value for the timeout is 60 seconds. Any timeout configuration that's specified during a <a>SubmitJob</a> operation overrides the timeout configuration defined here. For more information, see <a href="https://docs.aws.amazon.com/batch/latest/userguide/job_timeouts.html">Job Timeouts</a> in the <i>Batch User Guide</i>.</p>
        tags: <p>The tags that you apply to the job definition to help you categorize and organize your resources. Each tag consists of a key and an optional value. For more information, see <a href="https://docs.aws.amazon.com/batch/latest/userguide/using-tags.html">Tagging Amazon Web Services Resources</a> in <i>Batch User Guide</i>.</p>
        platform_capabilities: <p>The platform capabilities required by the job definition. If no value is specified, it defaults to <code>EC2</code>. To run the job on Fargate resources, specify <code>FARGATE</code>. To run the job on Amazon ECS Managed Instances, specify <code>MANAGED_INSTANCES</code>.</p> <p>Jobs with the <code>MANAGED_INSTANCES</code> platform capability must use <code>ecsProperties</code> (not <code>containerProperties</code>) and do not support multi-node parallel jobs.</p> <note> <p>If the job runs on Amazon EKS resources, then you must not specify <code>platformCapabilities</code>.</p> </note>
        eks_properties: <p>An object with properties that are specific to Amazon EKS-based jobs. This must not be specified for Amazon ECS based job definitions.</p>
        ecs_properties: <p>An object with properties that are specific to Amazon ECS-based jobs. This must not be specified for Amazon EKS-based job definitions.</p>
        consumable_resource_properties: <p>Contains a list of consumable resources required by the job.</p>

    Raises:
        capo_batch.errors.client_exception.ClientException: <p>These errors are usually caused by a client action. One example cause is using an action or resource on behalf of a user that doesn't have permissions to use the action or resource. Another cause is specifying an identifier that's not valid.</p>
        capo_batch.errors.server_exception.ServerException: <p>These errors are usually caused by a server issue.</p>
        capo_batch.errors.UnknownServiceError: The service returned an error code this client does not model.

    Examples:
        RegisterJobDefinition with tags
        This demonstrates calling the RegisterJobDefinition action, including tags.

        >>> client.register_job_definition(job_definition_name='sleep30', type='container', container_properties={'image': 'busybox', 'command': ['sleep', '30'], 'resourceRequirements': [{'type': 'MEMORY', 'value': '128'}, {'type': 'VCPU', 'value': '1'}]}, tags={'Department': 'Engineering', 'User': 'JaneDoe'})
        To register a GPU job definition on ECS Managed Instances
        This example registers a job definition that requests GPU resources on ECS Managed Instances.

        >>> client.register_job_definition(job_definition_name='my-gpu-managed-instances-job-def', type='container', platform_capabilities=['MANAGED_INSTANCES'], ecs_properties={'taskProperties': [{'containers': [{'image': '123456789012.dkr.ecr.us-east-1.amazonaws.com/my-gpu-image:latest', 'name': 'main', 'command': ['nvidia-smi'], 'resourceRequirements': [{'type': 'VCPU', 'value': '4'}, {'type': 'MEMORY', 'value': '16384'}, {'type': 'GPU', 'value': '1'}]}], 'executionRoleArn': 'arn:aws:iam::123456789012:role/ecsTaskExecutionRole'}]})
        To register a job definition
        This example registers a job definition for a simple container job.

        >>> client.register_job_definition(container_properties={'image': 'busybox', 'command': ['sleep', '10'], 'resourceRequirements': [{'type': 'MEMORY', 'value': '128'}, {'type': 'VCPU', 'value': '1'}]}, type='container', job_definition_name='sleep10')
        To register a job definition on ECS Managed Instances
        This example registers a job definition that runs on ECS Managed Instances using ecsProperties with the MANAGED_INSTANCES platform capability.

        >>> client.register_job_definition(job_definition_name='my-managed-instances-job-def', type='container', platform_capabilities=['MANAGED_INSTANCES'], ecs_properties={'taskProperties': [{'containers': [{'image': 'public.ecr.aws/amazonlinux/amazonlinux:2023', 'name': 'main', 'command': ['echo', 'hello managed instances'], 'resourceRequirements': [{'type': 'VCPU', 'value': '1'}, {'type': 'MEMORY', 'value': '1024'}]}], 'executionRoleArn': 'arn:aws:iam::123456789012:role/ecsTaskExecutionRole'}]})
        To register a multi-container job definition on ECS Managed Instances
        This example registers a job definition with a main container and a sidecar logging container on ECS Managed Instances.

        >>> client.register_job_definition(job_definition_name='my-sidecar-managed-instances-job-def', type='container', platform_capabilities=['MANAGED_INSTANCES'], ecs_properties={'taskProperties': [{'containers': [{'image': 'public.ecr.aws/amazonlinux/amazonlinux:2023', 'name': 'main', 'command': ['echo', 'processing data'], 'essential': True, 'resourceRequirements': [{'type': 'VCPU', 'value': '2'}, {'type': 'MEMORY', 'value': '4096'}]}, {'image': 'public.ecr.aws/amazonlinux/amazonlinux:2023', 'name': 'sidecar', 'command': ['echo', 'logging sidecar'], 'essential': False, 'resourceRequirements': [{'type': 'VCPU', 'value': '1'}, {'type': 'MEMORY', 'value': '512'}]}], 'executionRoleArn': 'arn:aws:iam::123456789012:role/ecsTaskExecutionRole'}]})
    """

    def _handler(
        req: "OperationRequest[capo_batch.types.register_job_definition_request.RegisterJobDefinitionRequest]",
    ) -> OperationResponse[
        "capo_batch.types.register_job_definition_response.RegisterJobDefinitionResponse"
    ]:
        import capo_batch._operations.aws_batch_v20160810.register_job_definition

        output, http_response = (
            capo_batch._operations.aws_batch_v20160810.register_job_definition.register_job_definition(
                req.options, req.input
            )
        )
        return OperationResponse(output=output, response=http_response)

    interceptors_, options_ = self.operation_options(
        config_overrides, OperationLogging("RegisterJobDefinition")
    )
    input_: capo_batch.types.register_job_definition_request.RegisterJobDefinitionRequest = {}
    if job_definition_name is not None:
        input_["job_definition_name"] = job_definition_name
    if type is not None:
        input_["type"] = type
    if parameters is not None:
        input_["parameters"] = parameters
    if scheduling_priority is not None:
        input_["scheduling_priority"] = scheduling_priority
    if container_properties is not None:
        input_["container_properties"] = container_properties
    if node_properties is not None:
        input_["node_properties"] = node_properties
    if retry_strategy is not None:
        input_["retry_strategy"] = retry_strategy
    if propagate_tags is not None:
        input_["propagate_tags"] = propagate_tags
    if timeout is not None:
        input_["timeout"] = timeout
    if tags is not None:
        input_["tags"] = tags
    if platform_capabilities is not None:
        input_["platform_capabilities"] = platform_capabilities
    if eks_properties is not None:
        input_["eks_properties"] = eks_properties
    if ecs_properties is not None:
        input_["ecs_properties"] = ecs_properties
    if consumable_resource_properties is not None:
        input_["consumable_resource_properties"] = consumable_resource_properties

    response = execute_pipeline(
        OperationRequest(input=input_, options=options_),
        handler=_handler,
        interceptors=list(interceptors_),
    )
    response.response.close()
    return response.output