# EcsEc2ContainerDefinitionProps

Props to configure an EcsEc2ContainerDefinition.

Extends: EcsEc2ContainerDefinitionProps
Extends: EcsContainerDefinitionProps
Used as props by: EcsEc2ContainerDefinition

- Source: [`aws-batch/lib/ecs-container-definition.ts`](https://github.com/aws/aws-cdk/blob/v2.275.0/packages/aws-cdk-lib/aws-batch/lib/ecs-container-definition.ts#L948)
- Type last changed: v2.96.0 · 13 Sep 2023

## Example

```ts
declare const myFileSystem: efs.IFileSystem;
declare const myJobRole: iam.Role;
myFileSystem.grantRead(myJobRole);

const jobDefn = new batch.EcsJobDefinition(this, 'JobDefn', {
  container: new batch.EcsEc2ContainerDefinition(this, 'containerDefn', {
    image: ecs.ContainerImage.fromRegistry('public.ecr.aws/amazonlinux/amazonlinux:latest'),
    memory: cdk.Size.mebibytes(2048),
    cpu: 256,
    volumes: [batch.EcsVolume.efs({
      name: 'myVolume',
      fileSystem: myFileSystem,
      containerPath: '/Volumes/myVolume',
      useJobRole: true,
    })],
    jobRole: myJobRole,
  }),
});
```

## Properties

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

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

- `gpu`: number — The number of physical GPUs to reserve for the container.

  **Default:** no gpus

  Make sure that the number of GPUs reserved for all containers in a job doesn't exceed
  the number of available GPUs on the compute resource that the job is launched on.

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

- `privileged`: boolean = false — When this parameter is true, the container is given elevated permissions on the host container instance (similar to the root user).

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

- `ulimits`: [Ulimit](/cdk/api/v2/docs/aws-cdk-lib.aws_batch.Ulimit.html)[] — Limits to set for the user this docker container will run as.

  **Default:** no ulimits

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