Skip to content
v2.273.0

EcsEc2ContainerDefinitionProps Struct ​

Props to configure an EcsEc2ContainerDefinition.

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 ​

commandstring[]commandtyping.List[str]commandList<String>Commandstring[]Command*[]*string= no command#
The command that's passed to the container.
cpunumbercpuint | floatcpuNumberCpudoubleCpu*float64required#
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.

enableExecuteCommandbooleanenable_execute_commandboolenableExecuteCommandBooleanEnableExecuteCommandboolEnableExecuteCommand*bool= undefined - AWS Batch default is…#
Determines whether execute command functionality is turned on for this task.
notes · default

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.

Default: undefined - AWS Batch default is false

environment{ [key: string]: string }environmenttyping.Mapping[str, str]environmentMap<String, String>EnvironmentIDictionary<string, string>Environment*map[string]*string= no environment variables#
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.

executionRoleIRoleexecution_roleIRoleexecutionRoleIRoleExecutionRoleIRoleExecutionRoleIRole= a Role will be created#
The role used by Amazon ECS container and AWS Fargate agents to make AWS API calls on your behalf.
gpunumbergpuint | floatgpuNumberGpudoubleGpu*float64= no gpus#
The number of physical GPUs to reserve for the container.

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.

The image that this container will run.
jobRoleIRolejob_roleIRolejobRoleIRoleJobRoleIRoleJobRoleIRole= no job role#
The role that the container can assume.
linuxParametersLinuxParameterslinux_parametersLinuxParameterslinuxParametersLinuxParametersLinuxParametersLinuxParametersLinuxParametersLinuxParameters= none#
Linux-specific modifications that are applied to the container, such as details for device mappings.
loggingLogDriverloggingLogDriverloggingLogDriverLoggingLogDriverLoggingLogDriver= the log configuration of the Doc…#
The loging configuration for this Job.
default

Default: the log configuration of the Docker daemon

memorySizememorySizememorySizeMemorySizeMemorySizerequired#
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.

privilegedbooleanprivilegedboolprivilegedBooleanPrivilegedboolPrivileged*bool= false#
When this parameter is true, the container is given elevated permissions on the host container instance (similar to the root user).
readonlyRootFilesystembooleanreadonly_root_filesystemboolreadonlyRootFilesystemBooleanReadonlyRootFilesystemboolReadonlyRootFilesystem*bool= false#
Gives the container readonly access to its root filesystem.
secrets{ [key: string]: Secret }secretstyping.Mapping[str, Secret]secretsMap<String, Secret>SecretsIDictionary<string, Secret>Secrets*map[string]Secret= no secrets#
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.

ulimitsUlimit[]ulimitstyping.List[Ulimit]ulimitsList<Ulimit>UlimitsUlimit[]Ulimits*[]Ulimit= no ulimits#
Limits to set for the user this docker container will run as.
userstringuserstruserStringUserstringUser*string= no user#
The user name to use inside the container.
volumesEcsVolume[]volumestyping.List[EcsVolume]volumesList<EcsVolume>VolumesEcsVolume[]Volumes*[]EcsVolume= no volumes#
The volumes to mount to this container.

Automatically added to the job definition.

Used as props by ​