# MultiNodeJobDefinition

A JobDefinition that uses Ecs orchestration to run multiple containers.

Extends: Construct › Resource › MultiNodeJobDefinition
Implements: IResource, IJobDefinition, IEnvironmentAware, IJobDefinitionRef, IConstruct, IDependable

- CloudFormation: [`AWS::Batch::JobDefinition`](https://docs.aws.amazon.com/AWSCloudFormation/latest/TemplateReference/aws-resource-batch-jobdefinition.html)
- L1 type: [`CfnJobDefinition`](/cdk/api/v2/docs/aws-cdk-lib.aws_batch.CfnJobDefinition.html)
- Source: [`aws-batch/lib/multinode-job-definition.ts`](https://github.com/aws/aws-cdk/blob/v2.275.0/packages/aws-cdk-lib/aws-batch/lib/multinode-job-definition.ts#L130)
- Type last changed: v2.247.0 · 2 Apr 2026

## Example

```ts
const multiNodeJob = new batch.MultiNodeJobDefinition(this, 'JobDefinition', {
  instanceType: ec2.InstanceType.of(ec2.InstanceClass.R4, ec2.InstanceSize.LARGE), // optional, omit to let Batch choose the type for you
  containers: [{
    container: new batch.EcsEc2ContainerDefinition(this, 'mainMPIContainer', {
      image: ecs.ContainerImage.fromRegistry('yourregsitry.com/yourMPIImage:latest'),
      cpu: 256,
      memory: cdk.Size.mebibytes(2048),
    }),
    startNode: 0,
    endNode: 5,
  }],
});
// convenience method
multiNodeJob.addContainer({
  startNode: 6,
  endNode: 10,
  container: new batch.EcsEc2ContainerDefinition(this, 'multiContainer', {
    image: ecs.ContainerImage.fromRegistry('amazon/amazon-ecs-sample'),
    cpu: 256,
    memory: cdk.Size.mebibytes(2048),
  }),
});
```

## Initializer

```ts
new MultiNodeJobDefinition(scope: Construct, id: string, props?: MultiNodeJobDefinitionProps)
```

## Construct Props

- `containers`: [MultiNodeContainer](/cdk/api/v2/docs/aws-cdk-lib.aws_batch.MultiNodeContainer.html)[] = none — The containers that this multinode job will run.

- `instanceType`: [InstanceType](/cdk/api/v2/docs/aws-cdk-lib.aws_ec2.InstanceType.html) — The instance type that this job definition will run.

  **Default:** optimal instance, selected by Batch

- `jobDefinitionName`: string — The name of this job definition.

  **Default:** generated by CloudFormation

- `mainNode`: number = 0 — The index of the main node in this job.

  The main node is responsible for orchestration.

- `parameters`: { [key: string]: any } = none — The default parameters passed to the container These parameters can be referenced in the `command` that you give to the container.

- `propagateTags`: boolean = false — Whether to propagate tags from the JobDefinition to the ECS task that Batch spawns.

- `retryAttempts`: number = 1 — The number of times to retry a job.

  The job is retried on failure the same number of attempts as the value.

- `retryStrategies`: [RetryStrategy](/cdk/api/v2/docs/aws-cdk-lib.aws_batch.RetryStrategy.html)[] — Defines the retry behavior for this job.

  **Default:** no `RetryStrategy`

- `schedulingPriority`: number = none — The priority of this Job.

  Only used in Fairshare Scheduling
  to decide which job to run first when there are multiple jobs
  with the same share identifier.

- `skipDeregisterOnUpdate`: boolean — Specifies whether the previous revision of the job definition is retained in an active status after UPDATE events for the resource.

  **Default:** undefined - AWS Batch default is false

  When the property is set to false, the previous revision of the job definition is de-registered after a new revision is created.
  When the property is set to true, the previous revision of the job definition is not de-registered.

- `timeout`: [Duration](/cdk/api/v2/docs/aws-cdk-lib.Duration.html) — The timeout time for jobs that are submitted with this job definition.

  **Default:** no timeout

  After the amount of time you specify passes,
  Batch terminates your jobs if they aren't finished.

## Properties

- `containers`: [MultiNodeContainer](/cdk/api/v2/docs/aws-cdk-lib.aws_batch.MultiNodeContainer.html)[] — The containers that this multinode job will run.

- `env`: [ResourceEnvironment](/cdk/api/v2/docs/aws-cdk-lib.interfaces.ResourceEnvironment.html) — The environment this resource belongs to.

  For resources that are created and managed in a Stack (those created by
  creating new class instances like `new Role()`, `new Bucket()`, etc.), this
  is always the same as the environment of the stack they belong to.

  For referenced resources (those obtained from referencing methods like
  `Role.fromRoleArn()`, `Bucket.fromBucketName()`, etc.), they might be
  different than the stack they were imported into.

- `instanceType`: [InstanceType](/cdk/api/v2/docs/aws-cdk-lib.aws_ec2.InstanceType.html) — If the prop `instanceType` is left `undefined`, then this will hold a fake instance type, for backwards compatibility reasons.

- `jobDefinitionArn`: string — The ARN of this job definition.

- `jobDefinitionName`: string — The name of this job definition.

- `jobDefinitionRef`: [JobDefinitionReference](/cdk/api/v2/docs/aws-cdk-lib.interfaces.aws_batch.JobDefinitionReference.html) — A reference to a JobDefinition resource.

- `mainNode`: number — The index of the main node in this job.

  The main node is responsible for orchestration.

- `node`: [Node](/cdk/api/v2/docs/constructs.Node.html) — The tree node.

- `parameters`: { [key: string]: any } — The default parameters passed to the container These parameters can be referenced in the `command` that you give to the container.

- `propagateTags`: boolean — Whether to propagate tags from the JobDefinition to the ECS task that Batch spawns.

- `PROPERTY_INJECTION_ID`: string (static) — Uniquely identifies this class.

- `retryAttempts`: number — The number of times to retry a job.

  The job is retried on failure the same number of attempts as the value.

- `retryStrategies`: [RetryStrategy](/cdk/api/v2/docs/aws-cdk-lib.aws_batch.RetryStrategy.html)[] — Defines the retry behavior for this job.

- `schedulingPriority`: number — The priority of this Job.

  Only used in Fairshare Scheduling
  to decide which job to run first when there are multiple jobs
  with the same share identifier.

- `skipDeregisterOnUpdate`: boolean — Specifies whether the previous revision of the job definition is retained in an active status after UPDATE events for the resource.

  **Default:** undefined - AWS Batch default is false

- `stack`: [Stack](/cdk/api/v2/docs/aws-cdk-lib.Stack.html) — The stack in which this resource is defined.

- `timeout`: [Duration](/cdk/api/v2/docs/aws-cdk-lib.Duration.html) — The timeout time for jobs that are submitted with this job definition.

  After the amount of time you specify passes,
  Batch terminates your jobs if they aren't finished.

## Methods

- `addContainer(container: MultiNodeContainer): void` — Add a container to this multinode job.

- `addRetryStrategy(strategy: RetryStrategy): void` — Add a RetryStrategy to this JobDefinition.

- `applyCrossStackReferenceStrength(strength: ReferenceStrength): void` — Override the cross-stack reference strength for this resource.

  When set, any cross-stack reference to this resource will use the specified
  mechanism instead of the global default determined by the
  `@aws-cdk/core:defaultCrossStackReferences` context key. This is useful for
  selectively weakening specific references to avoid the "deadly embrace" problem
  without changing the app-wide default.

  **Parameters**

  - `strength` — - The reference strength to use for this resource.

- `applyRemovalPolicy(policy: RemovalPolicy): void` — Apply the given removal policy to this resource.

  The Removal Policy controls what happens to this resource when it stops
  being managed by CloudFormation, either because you've removed it from the
  CDK application or because you've made a change that requires the resource
  to be replaced.

  The resource can be deleted (`RemovalPolicy.DESTROY`), or left in your AWS
  account for data recovery and cleanup later (`RemovalPolicy.RETAIN`).

- `fromJobDefinitionArn(scope: Construct, id: string, jobDefinitionArn: string): IJobDefinition` (static) — refer to an existing JobDefinition by its arn.

- `isConstruct(x: any): boolean` (static) — Checks if `x` is a construct.

  Use this method instead of `instanceof` to properly detect `Construct`
  instances, even when the construct library is symlinked.

  Explanation: in JavaScript, multiple copies of the `constructs` library on
  disk are seen as independent, completely different libraries. As a
  consequence, the class `Construct` in each copy of the `constructs` library
  is seen as a different class, and an instance of one class will not test as
  `instanceof` the other class. `npm install` will not create installations
  like this, but users may manually symlink construct libraries together or
  use a monorepo tool: in those cases, multiple copies of the `constructs`
  library can be accidentally installed, and `instanceof` will behave
  unpredictably. It is safest to avoid using `instanceof`, and using
  this type-testing method instead.

  **Parameters**

  - `x` — Any object.

  **Returns:** true if `x` is an object created from a class which extends `Construct`.

- `isOwnedResource(construct: IConstruct): boolean` (static) — Returns true if the construct was created by CDK, and false otherwise.

- `isResource(construct: IConstruct): boolean` (static) — Check whether the given construct is a Resource.

- `toString(): string` — Returns a string representation of this construct.

- `with(...mixins: IMixin[]): IConstruct` — Applies one or more mixins to this construct.

  Mixins are applied in order. The list of constructs is captured at the
  start of the call, so constructs added by a mixin will not be visited.
  Use multiple `with()` calls if subsequent mixins should apply to added
  constructs.
