# EksContainerDefinition

A container that can be run with EKS orchestration on EC2 resources.

Extends: Construct › EksContainerDefinition
Implements: IEksContainerDefinition, IConstruct, IDependable

- Source: [`aws-batch/lib/eks-container-definition.ts`](https://github.com/aws/aws-cdk/blob/v2.275.0/packages/aws-cdk-lib/aws-batch/lib/eks-container-definition.ts#L537)
- Type last changed: v2.196.0 · 16 May 2025

## Example

```ts
const jobDefn = new batch.EksJobDefinition(this, 'eksf2', {
  container: new batch.EksContainerDefinition(this, 'container', {
    image: ecs.ContainerImage.fromRegistry('amazon/amazon-ecs-sample'),
    volumes: [batch.EksVolume.emptyDir({
      name: 'myEmptyDirVolume',
      mountPath: '/mount/path',
      medium: batch.EmptyDirMediumType.MEMORY,
      readonly: true,
      sizeLimit: cdk.Size.mebibytes(2048),
    })],
  }),
});
```

## Initializer

```ts
new EksContainerDefinition(scope: Construct, id: string, props: EksContainerDefinitionProps)
```

## Construct Props

- `args`: string[] — An array of arguments to the entrypoint.

  **Default:** no args

  If this isn't specified, the CMD of the container image is used.
  This corresponds to the args member in the Entrypoint portion of the Pod in Kubernetes.
  Environment variable references are expanded using the container's environment.
  If the referenced environment variable doesn't exist, the reference in the command isn't changed.
  For example, if the reference is to "$(NAME1)" and the NAME1 environment variable doesn't exist,
  the command string will remain "$(NAME1)." $$ is replaced with $, and the resulting string isn't expanded.
  or example, $$(VAR_NAME) is passed as $(VAR_NAME) whether or not the VAR_NAME environment variable exists.

- `command`: string[] — The entrypoint for the container.

  **Default:** no command

  This isn't run within a shell.
  If this isn't specified, the `ENTRYPOINT` of the container image is used.
  Environment variable references are expanded using the container's environment.
  If the referenced environment variable doesn't exist, the reference in the command isn't changed.
  For example, if the reference is to `"$(NAME1)"` and the `NAME1` environment variable doesn't exist,
  the command string will remain `"$(NAME1)."` `$$` is replaced with `$` and the resulting string isn't expanded.
  For example, `$$(VAR_NAME)` will be passed as `$(VAR_NAME)` whether or not the `VAR_NAME` environment variable exists.

  The entrypoint can't be updated.

- `cpuLimit`: number — The hard limit of CPUs to present to this container. Must be an even multiple of 0.25.

  **Default:** No CPU limit

  If your container attempts to exceed this limit, it will be terminated.

  At least one of `cpuReservation` and `cpuLimit` is required.
  If both are specified, then `cpuLimit` must be at least as large as `cpuReservation`.

- `cpuReservation`: number — The soft limit of CPUs to reserve for the container Must be an even multiple of 0.25.

  **Default:** No CPUs reserved

  The container will given at least this many CPUs, but may consume more.

  At least one of `cpuReservation` and `cpuLimit` is required.
  If both are specified, then `cpuLimit` must be at least as large as `cpuReservation`.

- `env`: { [key: string]: string } — The environment variables to pass to this container.

  **Default:** no environment variables

  *Note*: Environment variables cannot start with "AWS_BATCH".
  This naming convention is reserved for variables that AWS Batch sets.

- `gpuLimit`: number — The hard limit of GPUs to present to this container.

  **Default:** No GPU limit

  If your container attempts to exceed this limit, it will be terminated.

  If both `gpuReservation` and `gpuLimit` are specified, then `gpuLimit` must be equal to `gpuReservation`.

- `gpuReservation`: number — The soft limit of CPUs to reserve for the container Must be an even multiple of 0.25.

  **Default:** No GPUs reserved

  The container will given at least this many CPUs, but may consume more.

  If both `gpuReservation` and `gpuLimit` are specified, then `gpuLimit` must be equal to `gpuReservation`.

- `image`: [ContainerImage](/cdk/api/v2/docs/aws-cdk-lib.aws_ecs.ContainerImage.html) (required) — The image that this container will run.

- `imagePullPolicy`: [ImagePullPolicy](/cdk/api/v2/docs/aws-cdk-lib.aws_batch.ImagePullPolicy.html) — The image pull policy for this container.

  **Default:** `ALWAYS` if the `:latest` tag is specified, `IF_NOT_PRESENT` otherwise

- `memoryLimit`: [Size](/cdk/api/v2/docs/aws-cdk-lib.Size.html) — The amount (in MiB) of memory to present to the container.

  **Default:** No memory limit

  If your container attempts to exceed the allocated memory, it will be terminated.

  Must be larger that 4 MiB

  At least one of `memoryLimit` and `memoryReservation` is required

  *Note*: To maximize your resource utilization, provide your jobs with as much memory as possible
  for the specific instance type that you are using.

- `memoryReservation`: [Size](/cdk/api/v2/docs/aws-cdk-lib.Size.html) — The soft limit (in MiB) of memory to reserve for the container.

  **Default:** No memory reserved

  Your container will be given at least this much memory, but may consume more.

  Must be larger that 4 MiB

  When system memory is under heavy contention, Docker attempts to keep the
  container memory to this soft limit. However, your container can consume more
  memory when it needs to, up to either the hard limit specified with the memory
  parameter (if applicable), or all of the available memory on the container
  instance, whichever comes first.

  At least one of `memoryLimit` and `memoryReservation` is required.
  If both are specified, then `memoryLimit` must be equal to `memoryReservation`

  *Note*: To maximize your resource utilization, provide your jobs with as much memory as possible
  for the specific instance type that you are using.

- `name`: string — The name of this container.

  **Default:** : `'Default'`

- `privileged`: boolean = false — If specified, gives this container elevated permissions on the host container instance.

  The level of permissions are similar to the root user permissions.

  This parameter maps to `privileged` policy in the Privileged pod security policies in the Kubernetes documentation.

  *Note*: this is only compatible with Kubernetes < v1.25

- `readonlyRootFilesystem`: boolean = false — If specified, gives this container readonly access to its root file system.

  This parameter maps to `ReadOnlyRootFilesystem` policy in the Volumes and file systems pod security policies in the Kubernetes documentation.

  *Note*: this is only compatible with Kubernetes < v1.25

- `runAsGroup`: number = none — If specified, the container is run as the specified group ID (`gid`).

  If this parameter isn't specified, the default is the group that's specified in the image metadata.
  This parameter maps to `RunAsGroup` and `MustRunAs` policy in the Users and groups pod security policies in the Kubernetes documentation.

  *Note*: this is only compatible with Kubernetes < v1.25

- `runAsRoot`: boolean — If specified, the container is run as a user with a `uid` other than 0.

  **Default:** the container is *not* required to run as a non-root user

  Otherwise, no such rule is enforced.
  This parameter maps to `RunAsUser` and `MustRunAsNonRoot` policy in the Users and groups pod security policies in the Kubernetes documentation.

  *Note*: this is only compatible with Kubernetes < v1.25

- `runAsUser`: number — If specified, this container is run as the specified user ID (`uid`).

  **Default:** the user that is specified in the image metadata.

  This parameter maps to `RunAsUser` and `MustRunAs` policy in the Users and groups pod security policies in the Kubernetes documentation.

  *Note*: this is only compatible with Kubernetes < v1.25

- `volumes`: [EksVolume](/cdk/api/v2/docs/aws-cdk-lib.aws_batch.EksVolume.html)[] — The Volumes to mount to this container.

  **Default:** no volumes

  Automatically added to the Pod.

## Properties

- `args`: string[] — An array of arguments to the entrypoint.

  If this isn't specified, the CMD of the container image is used.
  This corresponds to the args member in the Entrypoint portion of the Pod in Kubernetes.
  Environment variable references are expanded using the container's environment.
  If the referenced environment variable doesn't exist, the reference in the command isn't changed.
  For example, if the reference is to "$(NAME1)" and the NAME1 environment variable doesn't exist,
  the command string will remain "$(NAME1)." $$ is replaced with $, and the resulting string isn't expanded.
  or example, $$(VAR_NAME) is passed as $(VAR_NAME) whether or not the VAR_NAME environment variable exists.

- `command`: string[] — The entrypoint for the container.

  This isn't run within a shell.
  If this isn't specified, the `ENTRYPOINT` of the container image is used.
  Environment variable references are expanded using the container's environment.
  If the referenced environment variable doesn't exist, the reference in the command isn't changed.
  For example, if the reference is to `"$(NAME1)"` and the `NAME1` environment variable doesn't exist,
  the command string will remain `"$(NAME1)."` `$$` is replaced with `$` and the resulting string isn't expanded.
  For example, `$$(VAR_NAME)` will be passed as `$(VAR_NAME)` whether or not the `VAR_NAME` environment variable exists.

  The entrypoint can't be updated.

- `cpuLimit`: number — The hard limit of CPUs to present to this container. Must be an even multiple of 0.25.

  If your container attempts to exceed this limit, it will be terminated.

  At least one of `cpuReservation` and `cpuLimit` is required.
  If both are specified, then `cpuLimit` must be at least as large as `cpuReservation`.

- `cpuReservation`: number — The soft limit of CPUs to reserve for the container Must be an even multiple of 0.25.

  The container will given at least this many CPUs, but may consume more.

  At least one of `cpuReservation` and `cpuLimit` is required.
  If both are specified, then `cpuLimit` must be at least as large as `cpuReservation`.

- `env`: { [key: string]: string } — The environment variables to pass to this container.

  *Note*: Environment variables cannot start with "AWS_BATCH".
  This naming convention is reserved for variables that AWS Batch sets.

- `gpuLimit`: number — The hard limit of GPUs to present to this container.

  If your container attempts to exceed this limit, it will be terminated.

  If both `gpuReservation` and `gpuLimit` are specified, then `gpuLimit` must be equal to `gpuReservation`.

- `gpuReservation`: number — The soft limit of CPUs to reserve for the container Must be an even multiple of 0.25.

  The container will given at least this many CPUs, but may consume more.

  If both `gpuReservation` and `gpuLimit` are specified, then `gpuLimit` must be equal to `gpuReservation`.

- `image`: [ContainerImage](/cdk/api/v2/docs/aws-cdk-lib.aws_ecs.ContainerImage.html) — The image that this container will run.

- `imagePullPolicy`: [ImagePullPolicy](/cdk/api/v2/docs/aws-cdk-lib.aws_batch.ImagePullPolicy.html) — The image pull policy for this container.

- `memoryLimit`: [Size](/cdk/api/v2/docs/aws-cdk-lib.Size.html) — The amount (in MiB) of memory to present to the container.

  If your container attempts to exceed the allocated memory, it will be terminated.

  Must be larger that 4 MiB

  At least one of `memoryLimit` and `memoryReservation` is required

  *Note*: To maximize your resource utilization, provide your jobs with as much memory as possible
  for the specific instance type that you are using.

- `memoryReservation`: [Size](/cdk/api/v2/docs/aws-cdk-lib.Size.html) — The soft limit (in MiB) of memory to reserve for the container.

  Your container will be given at least this much memory, but may consume more.

  Must be larger that 4 MiB

  When system memory is under heavy contention, Docker attempts to keep the
  container memory to this soft limit. However, your container can consume more
  memory when it needs to, up to either the hard limit specified with the memory
  parameter (if applicable), or all of the available memory on the container
  instance, whichever comes first.

  At least one of `memoryLimit` and `memoryReservation` is required.
  If both are specified, then `memoryLimit` must be equal to `memoryReservation`

  *Note*: To maximize your resource utilization, provide your jobs with as much memory as possible
  for the specific instance type that you are using.

- `name`: string — The name of this container.

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

- `privileged`: boolean — If specified, gives this container elevated permissions on the host container instance.

  The level of permissions are similar to the root user permissions.

  This parameter maps to `privileged` policy in the Privileged pod security policies in the Kubernetes documentation.

  *Note*: this is only compatible with Kubernetes < v1.25

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

- `readonlyRootFilesystem`: boolean — If specified, gives this container readonly access to its root file system.

  This parameter maps to `ReadOnlyRootFilesystem` policy in the Volumes and file systems pod security policies in the Kubernetes documentation.

  *Note*: this is only compatible with Kubernetes < v1.25

- `runAsGroup`: number — If specified, the container is run as the specified group ID (`gid`).

  If this parameter isn't specified, the default is the group that's specified in the image metadata.
  This parameter maps to `RunAsGroup` and `MustRunAs` policy in the Users and groups pod security policies in the Kubernetes documentation.

  *Note*: this is only compatible with Kubernetes < v1.25

- `runAsRoot`: boolean — If specified, the container is run as a user with a `uid` other than 0.

  Otherwise, no such rule is enforced.
  This parameter maps to `RunAsUser` and `MustRunAsNonRoot` policy in the Users and groups pod security policies in the Kubernetes documentation.

  *Note*: this is only compatible with Kubernetes < v1.25

- `runAsUser`: number — If specified, this container is run as the specified user ID (`uid`).

  This parameter maps to `RunAsUser` and `MustRunAs` policy in the Users and groups pod security policies in the Kubernetes documentation.

  *Note*: this is only compatible with Kubernetes < v1.25

- `volumes`: [EksVolume](/cdk/api/v2/docs/aws-cdk-lib.aws_batch.EksVolume.html)[] — The Volumes to mount to this container.

  Automatically added to the Pod.

## Methods

- `addVolume(volume: EksVolume): void` — Mount a Volume to this container.

  Automatically added to the Pod.

- `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`.

- `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.

  **Parameters**

  - `mixins` — The mixins to apply.

  **Returns:** This construct for chaining
