# EcsFargateContainerDefinition

A container orchestrated by ECS that uses Fargate resources.

Extends: Construct › EcsFargateContainerDefinition
Implements: IEcsContainerDefinition, IEcsFargateContainerDefinition, IConstruct, IDependable

- Source: [`aws-batch/lib/ecs-container-definition.ts`](https://github.com/aws/aws-cdk/blob/v2.274.0/packages/aws-cdk-lib/aws-batch/lib/ecs-container-definition.ts#L1129)
- Type last changed: v2.215.0 · 15 Sep 2025

## Example

```ts
const jobDefn = new batch.EcsJobDefinition(this, 'JobDefn', {
  container: new batch.EcsFargateContainerDefinition(this, 'myFargateContainer', {
    image: ecs.ContainerImage.fromRegistry('public.ecr.aws/amazonlinux/amazonlinux:latest'),
    memory: cdk.Size.mebibytes(2048),
    cpu: 256,
    ephemeralStorageSize: cdk.Size.gibibytes(100),
    fargateCpuArchitecture: ecs.CpuArchitecture.ARM64,
    fargateOperatingSystemFamily: ecs.OperatingSystemFamily.LINUX,
  }),
});
```

## Initializer

```ts
new EcsFargateContainerDefinition(scope: Construct, id: string, props: EcsFargateContainerDefinitionProps)
```

## Construct Props

- `assignPublicIp`: boolean = false — Indicates whether the job has a public IP address.

  For a job that's running on Fargate resources in a private subnet to send outbound traffic to the internet
  (for example, to pull container images), the private subnet requires a NAT gateway be attached to route requests to the internet.

- `command`: string[] — The command that's passed to the container.

  **Default:** no command

- `cpu`: number (required) — The number of vCPUs reserved for the container.

  Each vCPU is equivalent to 1,024 CPU shares.
  For containers running on EC2 resources, you must specify at least one vCPU.

- `enableExecuteCommand`: boolean — Determines whether execute command functionality is turned on for this task.

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

  If true, execute command functionality is turned on all the containers in the task.

  This allows you to use ECS Exec to access containers interactively.
  When enabled, a job role with required SSM permissions will be created automatically if no job role is provided.
  If a job role is alreadyprovided, the required permissions will be added to it.

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

  **Default:** no environment variables

  Cannot start with `AWS_BATCH`.
  We don't recommend using plaintext environment variables for sensitive information, such as credential data.

- `ephemeralStorageSize`: [Size](/cdk/api/v2/docs/aws-cdk-lib.Size.html) — The size for ephemeral storage.

  **Default:** 20 GiB

- `executionRole`: [IRole](/cdk/api/v2/docs/aws-cdk-lib.aws_iam.IRole.html) — The role used by Amazon ECS container and AWS Fargate agents to make AWS API calls on your behalf.

  **Default:** a Role will be created

- `fargateCpuArchitecture`: [CpuArchitecture](/cdk/api/v2/docs/aws-cdk-lib.aws_ecs.CpuArchitecture.html) = X86_64 — The vCPU architecture of Fargate Runtime.

- `fargateOperatingSystemFamily`: [OperatingSystemFamily](/cdk/api/v2/docs/aws-cdk-lib.aws_ecs.OperatingSystemFamily.html) = LINUX — The operating system for the compute environment.

- `fargatePlatformVersion`: [FargatePlatformVersion](/cdk/api/v2/docs/aws-cdk-lib.aws_ecs.FargatePlatformVersion.html) = LATEST — Which version of Fargate to use when running this container.

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

- `jobRole`: [IRole](/cdk/api/v2/docs/aws-cdk-lib.aws_iam.IRole.html) — The role that the container can assume.

  **Default:** no job role

- `linuxParameters`: [LinuxParameters](/cdk/api/v2/docs/aws-cdk-lib.aws_batch.LinuxParameters.html) = none — Linux-specific modifications that are applied to the container, such as details for device mappings.

- `logging`: [LogDriver](/cdk/api/v2/docs/aws-cdk-lib.aws_ecs.LogDriver.html) — The loging configuration for this Job.

  **Default:** the log configuration of the Docker daemon

- `memory`: [Size](/cdk/api/v2/docs/aws-cdk-lib.Size.html) (required) — The memory hard limit present to the container.

  If your container attempts to exceed the memory specified, the container is terminated.
  You must specify at least 4 MiB of memory for a job.

- `readonlyRootFilesystem`: boolean = false — Gives the container readonly access to its root filesystem.

- `secrets`: { [key: string]: [Secret](/cdk/api/v2/docs/aws-cdk-lib.aws_batch.Secret.html) } — A map from environment variable names to the secrets for the container.

  **Default:** no secrets

  Allows your job definitions
  to reference the secret by the environment variable name defined in this property.

- `user`: string — The user name to use inside the container.

  **Default:** no user

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

  **Default:** no volumes

  Automatically added to the job definition.

## Properties

- `assignPublicIp`: boolean — Indicates whether the job has a public IP address.

  For a job that's running on Fargate resources in a private subnet to send outbound traffic to the internet
  (for example, to pull container images), the private subnet requires a NAT gateway be attached to route requests to the internet.

- `command`: string[] — The command that's passed to the container.

- `cpu`: number — The number of vCPUs reserved for the container.

  Each vCPU is equivalent to 1,024 CPU shares.
  For containers running on EC2 resources, you must specify at least one vCPU.

- `enableExecuteCommand`: boolean — Whether to enable ecs exec for this container.

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

  Cannot start with `AWS_BATCH`.
  We don't recommend using plaintext environment variables for sensitive information, such as credential data.

- `ephemeralStorageSize`: [Size](/cdk/api/v2/docs/aws-cdk-lib.Size.html) — The size for ephemeral storage.

- `executionRole`: [IRole](/cdk/api/v2/docs/aws-cdk-lib.aws_iam.IRole.html) — The role used by Amazon ECS container and AWS Fargate agents to make AWS API calls on your behalf.

- `fargateCpuArchitecture`: [CpuArchitecture](/cdk/api/v2/docs/aws-cdk-lib.aws_ecs.CpuArchitecture.html) — The vCPU architecture of Fargate Runtime.

- `fargateOperatingSystemFamily`: [OperatingSystemFamily](/cdk/api/v2/docs/aws-cdk-lib.aws_ecs.OperatingSystemFamily.html) — The operating system for the compute environment.

- `fargatePlatformVersion`: [FargatePlatformVersion](/cdk/api/v2/docs/aws-cdk-lib.aws_ecs.FargatePlatformVersion.html) — Which version of Fargate to use when running this container.

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

- `jobRole`: [IRole](/cdk/api/v2/docs/aws-cdk-lib.aws_iam.IRole.html) — The role that the container can assume.

- `linuxParameters`: [LinuxParameters](/cdk/api/v2/docs/aws-cdk-lib.aws_batch.LinuxParameters.html) — Linux-specific modifications that are applied to the container, such as details for device mappings.

- `logDriverConfig`: [LogDriverConfig](/cdk/api/v2/docs/aws-cdk-lib.aws_ecs.LogDriverConfig.html) — The configuration of the log driver.

- `memory`: [Size](/cdk/api/v2/docs/aws-cdk-lib.Size.html) — The memory hard limit present to the container.

  If your container attempts to exceed the memory specified, the container is terminated.
  You must specify at least 4 MiB of memory for a job.

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

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

- `readonlyRootFilesystem`: boolean — Gives the container readonly access to its root filesystem.

- `secrets`: { [key: string]: [Secret](/cdk/api/v2/docs/aws-cdk-lib.aws_batch.Secret.html) } — A map from environment variable names to the secrets for the container.

  Allows your job definitions
  to reference the secret by the environment variable name defined in this property.

- `user`: string — The user name to use inside the container.

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

  Automatically added to the job definition.

## Methods

- `addVolume(volume: EcsVolume): void` — Add a Volume to this container.

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