Ec2TaskDefinitionProps

class aws_cdk.aws_ecs.Ec2TaskDefinitionProps(*, execution_role=None, family=None, proxy_configuration=None, task_role=None, volumes=None, inference_accelerators=None, ipc_mode=None, network_mode=None, pid_mode=None, placement_constraints=None)

Bases: CommonTaskDefinitionProps

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

Parameters:
  • execution_role (Optional[IRole]) – The name of the IAM task execution role that grants the ECS agent permission to call AWS APIs on your behalf. The role will be used to retrieve container images from ECR and create CloudWatch log groups. Default: - An execution role will be automatically created if you use ECR images in your task definition.

  • family (Optional[str]) – The name of a family that this task definition is registered to. A family groups multiple versions of a task definition. Default: - Automatically generated name.

  • proxy_configuration (Optional[ProxyConfiguration]) – The configuration details for the App Mesh proxy. Default: - No proxy configuration.

  • task_role (Optional[IRole]) – 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.

  • volumes (Optional[Sequence[Union[Volume, Dict[str, Any]]]]) – The list of volume definitions for the task. For more information, see Task Definition Parameter Volumes. Default: - No volumes are passed to the Docker daemon on a container instance.

  • inference_accelerators (Optional[Sequence[Union[InferenceAccelerator, Dict[str, Any]]]]) – The inference accelerators to use for the containers in the task. Not supported in Fargate. Default: - No inference accelerators.

  • ipc_mode (Optional[IpcMode]) – The IPC resource namespace to use for the containers in the task. Not supported in Fargate and Windows containers. Default: - IpcMode used by the task is not specified

  • network_mode (Optional[NetworkMode]) – The Docker networking mode to use for the containers in the task. The valid values are NONE, BRIDGE, AWS_VPC, and HOST. Default: - NetworkMode.BRIDGE for EC2 tasks, AWS_VPC for Fargate tasks.

  • pid_mode (Optional[PidMode]) – The process namespace to use for the containers in the task. Not supported in Windows containers. Default: - PidMode used by the task is not specified

  • placement_constraints (Optional[Sequence[PlacementConstraint]]) – An array of placement constraint objects to use for the task. You can specify a maximum of 10 constraints per task (this limit includes constraints in the task definition and those specified at run time). Default: - No placement constraints.

ExampleMetadata:

infused

Example:

ec2_task_definition = ecs.Ec2TaskDefinition(self, "TaskDef",
    network_mode=ecs.NetworkMode.BRIDGE
)

container = ec2_task_definition.add_container("WebContainer",
    # Use an image from DockerHub
    image=ecs.ContainerImage.from_registry("amazon/amazon-ecs-sample"),
    memory_limit_mi_b=1024
)

Attributes

execution_role

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

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

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

family

The name of a family that this task definition is registered to.

A family groups multiple versions of a task definition.

Default:
  • Automatically generated name.

inference_accelerators

The inference accelerators to use for the containers in the task.

Not supported in Fargate.

Default:
  • No inference accelerators.

ipc_mode

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

Not supported in Fargate and Windows containers.

Default:
  • IpcMode used by the task is not specified

network_mode

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

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

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

pid_mode

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

Not supported in Windows containers.

Default:
  • PidMode used by the task is not specified

placement_constraints

An array of placement constraint objects to use for the task.

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

Default:
  • No placement constraints.

proxy_configuration

The configuration details for the App Mesh proxy.

Default:
  • No proxy configuration.

task_role

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.

volumes

The list of volume definitions for the task.

For more information, see Task Definition Parameter Volumes.

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