Skip to content
v2.274.0

Ec2TaskDefinitionProps Struct ​

The properties for a task definition run on an EC2 cluster.

Example ​

ts
const ec2TaskDefinition = new ecs.Ec2TaskDefinition(this, 'TaskDef', {
  networkMode: ecs.NetworkMode.BRIDGE,
});

const container = ec2TaskDefinition.addContainer("WebContainer", {
  // Use an image from DockerHub
  image: ecs.ContainerImage.fromRegistry("amazon/amazon-ecs-sample"),
  memoryLimitMiB: 1024,
  // ... other options here ...
});

Properties ​

enableFaultInjectionoptionalbooleanenable_fault_injectionoptionalboolenableFaultInjectionoptionalBooleanEnableFaultInjectionoptionalboolEnableFaultInjectionoptional*bool#
Enables fault injection and allows for fault injection requests to be accepted from the task's containers.

Default: undefined - ECS default setting is false

Fault injection only works with tasks using the {@link NetworkMode.AWS_VPC} or {@link NetworkMode.HOST} network modes.

executionRoleoptionalIRoleexecution_roleoptionalIRoleexecutionRoleoptionalIRoleExecutionRoleoptionalIRoleExecutionRoleoptionalIRole#
The name of the IAM task execution role that grants the ECS agent permission to call AWS APIs on your behalf.

Default: An execution role will be automatically created if you use ECR images in your task definition.

The role will be used to retrieve container images from ECR and create CloudWatch log groups.

familyoptionalstringfamilyoptionalstrfamilyoptionalStringFamilyoptionalstringFamilyoptional*string#
The name of a family that this task definition is registered to.

Default: Automatically generated name.

A family groups multiple versions of a task definition.

inferenceAcceleratorsoptionalInferenceAccelerator[]inference_acceleratorsoptionaltyping.List[InferenceAccelerator]inferenceAcceleratorsoptionalList<InferenceAccelerator>InferenceAcceleratorsoptionalInferenceAccelerator[]InferenceAcceleratorsoptional*[]InferenceAccelerator#
The inference accelerators to use for the containers in the task.

Default: No inference accelerators.

Not supported in Fargate.

ipcModeoptionalIpcModeipc_modeoptionalIpcModeipcModeoptionalIpcModeIpcModeoptionalIpcModeIpcModeoptionalIpcMode#
The IPC resource namespace to use for the containers in the task.

Default: IpcMode used by the task is not specified

Not supported in Fargate and Windows containers.

networkModeoptionalNetworkModenetwork_modeoptionalNetworkModenetworkModeoptionalNetworkModeNetworkModeoptionalNetworkModeNetworkModeoptionalNetworkMode#
The Docker networking mode to use for the containers in the task.

Default: NetworkMode.BRIDGE for EC2 tasks, AWS_VPC for Fargate tasks.

The valid values are NONE, BRIDGE, AWS_VPC, and HOST.

pidModeoptionalPidModepid_modeoptionalPidModepidModeoptionalPidModePidModeoptionalPidModePidModeoptionalPidMode#
The process namespace to use for the containers in the task.

Default: PidMode used by the task is not specified

Not supported in Windows containers.

placementConstraintsoptionalPlacementConstraint[]placement_constraintsoptionaltyping.List[PlacementConstraint]placementConstraintsoptionalList<PlacementConstraint>PlacementConstraintsoptionalPlacementConstraint[]PlacementConstraintsoptional*[]PlacementConstraint#
An array of placement constraint objects to use for the task.

Default: No placement constraints.

You can specify a maximum of 10 constraints per task (this limit includes constraints in the task definition and those specified at run time).

proxyConfigurationoptionalProxyConfigurationproxy_configurationoptionalProxyConfigurationproxyConfigurationoptionalProxyConfigurationProxyConfigurationoptionalProxyConfigurationProxyConfigurationoptionalProxyConfiguration#
The configuration details for the App Mesh proxy.

Default: No proxy configuration.

taskRoleoptionalIRoletask_roleoptionalIRoletaskRoleoptionalIRoleTaskRoleoptionalIRoleTaskRoleoptionalIRole#
The name of the IAM role that grants containers in the task permission to call AWS APIs on your behalf.

Default: A task role is automatically created for you.

volumesoptionalVolume[]volumesoptionaltyping.List[Volume]volumesoptionalList<Volume>VolumesoptionalVolume[]Volumesoptional*[]Volume#
The list of volume definitions for the task.

Default: No volumes are passed to the Docker daemon on a container instance.

For more information, see Task Definition Parameter Volumes.