Skip to content
v2.275.0

EcsContainerDefinitionProps Struct ​

Props to configure an EcsContainerDefinition.

Example ​

ts
// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
import * as cdk from 'aws-cdk-lib';
import { aws_batch as batch } from 'aws-cdk-lib';
import { aws_ecs as ecs } from 'aws-cdk-lib';
import { aws_iam as iam } from 'aws-cdk-lib';

declare const containerImage: ecs.ContainerImage;
declare const ecsVolume: batch.EcsVolume;
declare const linuxParameters: batch.LinuxParameters;
declare const logDriver: ecs.LogDriver;
declare const role: iam.Role;
declare const secret: batch.Secret;
declare const size: cdk.Size;
const ecsContainerDefinitionProps: batch.EcsContainerDefinitionProps = {
  cpu: 123,
  image: containerImage,
  memory: size,

  // the properties below are optional
  command: ['command'],
  enableExecuteCommand: false,
  environment: {
    environmentKey: 'environment',
  },
  executionRole: role,
  jobRole: role,
  linuxParameters: linuxParameters,
  logging: logDriver,
  readonlyRootFilesystem: false,
  secrets: {
    secretsKey: secret,
  },
  user: 'user',
  volumes: [ecsVolume],
};

Properties ​

commandoptionalstring[]commandoptionaltyping.List[str]commandoptionalList<String>Commandoptionalstring[]Commandoptional*[]*string#
The command that's passed to the container.

Default: no command

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.

enableExecuteCommandoptionalbooleanenable_execute_commandoptionalboolenableExecuteCommandoptionalBooleanEnableExecuteCommandoptionalboolEnableExecuteCommandoptional*bool#
Determines whether execute command functionality is turned on for this task.

Default: undefined - AWS Batch default is false

notes

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.

environmentoptional{ [key: string]: string }environmentoptionaltyping.Mapping[str, str]environmentoptionalMap<String, String>EnvironmentoptionalIDictionary<string, string>Environmentoptional*map[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.

executionRoleoptionalIRoleexecution_roleoptionalIRoleexecutionRoleoptionalIRoleExecutionRoleoptionalIRoleExecutionRoleoptionalIRole#
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

The image that this container will run.
jobRoleoptionalIRolejob_roleoptionalIRolejobRoleoptionalIRoleJobRoleoptionalIRoleJobRoleoptionalIRole#
The role that the container can assume.

Default: no job role

linuxParametersoptionalLinuxParameterslinux_parametersoptionalLinuxParameterslinuxParametersoptionalLinuxParametersLinuxParametersoptionalLinuxParametersLinuxParametersoptionalLinuxParameters= none#
Linux-specific modifications that are applied to the container, such as details for device mappings.
loggingoptionalLogDriverloggingoptionalLogDriverloggingoptionalLogDriverLoggingoptionalLogDriverLoggingoptionalLogDriver#
The loging configuration for this Job.

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.

readonlyRootFilesystemoptionalbooleanreadonly_root_filesystemoptionalboolreadonlyRootFilesystemoptionalBooleanReadonlyRootFilesystemoptionalboolReadonlyRootFilesystemoptional*bool= false#
Gives the container readonly access to its root filesystem.
secretsoptional{ [key: string]: Secret }secretsoptionaltyping.Mapping[str, Secret]secretsoptionalMap<String, Secret>SecretsoptionalIDictionary<string, Secret>Secretsoptional*map[string]Secret#
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.

useroptionalstringuseroptionalstruseroptionalStringUseroptionalstringUseroptional*string#
The user name to use inside the container.

Default: no user

volumesoptionalEcsVolume[]volumesoptionaltyping.List[EcsVolume]volumesoptionalList<EcsVolume>VolumesoptionalEcsVolume[]Volumesoptional*[]EcsVolume#
The volumes to mount to this container.

Default: no volumes

Automatically added to the job definition.