EcsTask
- class aws_cdk.aws_events_targets.EcsTask(*, cluster, task_definition, assign_public_ip=None, container_overrides=None, cpu=None, enable_execute_command=None, ephemeral_storage=None, execution_role=None, inference_accelerator_overrides=None, launch_type=None, memory=None, platform_version=None, propagate_tags=None, role=None, security_groups=None, subnet_selection=None, tags=None, task_count=None, task_role=None, dead_letter_queue=None, max_event_age=None, retry_attempts=None)
Bases:
object
Start a task on an ECS cluster.
- ExampleMetadata:
infused
Example:
import aws_cdk.aws_ecs as ecs # cluster: ecs.ICluster # task_definition: ecs.TaskDefinition rule = events.Rule(self, "Rule", schedule=events.Schedule.rate(cdk.Duration.hours(1)) ) rule.add_target(targets.EcsTask( cluster=cluster, task_definition=task_definition, task_count=1, # Overrides the cpu and memory values in the task definition cpu="512", memory="512" ))
- Parameters:
cluster (
ICluster
) – Cluster where service will be deployed.task_definition (
ITaskDefinition
) – Task Definition of the task that should be started.assign_public_ip (
Optional
[bool
]) – Specifies whether the task’s elastic network interface receives a public IP address. You can specify true only when LaunchType is set to FARGATE. Default: - true if the subnet type is PUBLIC, otherwise falsecontainer_overrides (
Optional
[Sequence
[Union
[ContainerOverride
,Dict
[str
,Any
]]]]) – Container setting overrides. Key is the name of the container to override, value is the values you want to override.cpu (
Optional
[str
]) – The CPU override for the task. Default: - The task definition’s CPU valueenable_execute_command (
Optional
[bool
]) – Whether or not to enable the execute command functionality for the containers in this task. If true, this enables execute command functionality on all containers in the task. Default: - falseephemeral_storage (
Union
[EphemeralStorageOverride
,Dict
[str
,Any
],None
]) – The ephemeral storage setting override for the task. NOTE: This parameter is only supported for tasks hosted on Fargate that use the following platform versions: - Linux platform version 1.4.0 or later. - Windows platform version 1.0.0 or later. Default: - The task definition’s ephemeral storage valueexecution_role (
Optional
[IRole
]) – The execution role for the task. The Amazon Resource Name (ARN) of the task execution role override for the task. Default: - The task definition’s execution roleinference_accelerator_overrides (
Optional
[Sequence
[Union
[InferenceAcceleratorOverride
,Dict
[str
,Any
]]]]) – The Elastic Inference accelerator override for the task. Default: - The task definition’s inference accelerator overrideslaunch_type (
Optional
[LaunchType
]) – Specifies the launch type on which your task is running. The launch type that you specify here must match one of the launch type (compatibilities) of the target task. Default: - ‘EC2’ ifisEc2Compatible
for thetaskDefinition
is true, otherwise ‘FARGATE’memory (
Optional
[str
]) – The memory override for the task. Default: - The task definition’s memory valueplatform_version (
Optional
[FargatePlatformVersion
]) – The platform version on which to run your task. Unless you have specific compatibility requirements, you don’t need to specify this. Default: - ECS will set the Fargate platform version to ‘LATEST’propagate_tags (
Optional
[PropagatedTagSource
]) – Specifies whether to propagate the tags from the task definition to the task. If no value is specified, the tags are not propagated. Default: - Tags will not be propagatedrole (
Optional
[IRole
]) – Existing IAM role to run the ECS task. Default: A new IAM role is createdsecurity_groups (
Optional
[Sequence
[ISecurityGroup
]]) – Existing security groups to use for the task’s ENIs. (Only applicable in case the TaskDefinition is configured for AwsVpc networking) Default: A new security group is createdsubnet_selection (
Union
[SubnetSelection
,Dict
[str
,Any
],None
]) – In what subnets to place the task’s ENIs. (Only applicable in case the TaskDefinition is configured for AwsVpc networking) Default: Private subnetstags (
Optional
[Sequence
[Union
[Tag
,Dict
[str
,Any
]]]]) – The metadata that you apply to the task to help you categorize and organize them. Each tag consists of a key and an optional value, both of which you define. Default: - No additional tags are applied to the tasktask_count (
Union
[int
,float
,None
]) – How many tasks should be started when this event is triggered. Default: 1task_role (
Optional
[IRole
]) – The IAM role for the task. Default: - The task definition’s task roledead_letter_queue (
Optional
[IQueue
]) – The SQS queue to be used as deadLetterQueue. Check out the considerations for using a dead-letter queue. The events not successfully delivered are automatically retried for a specified period of time, depending on the retry policy of the target. If an event is not delivered before all retry attempts are exhausted, it will be sent to the dead letter queue. Default: - no dead-letter queuemax_event_age (
Optional
[Duration
]) – The maximum age of a request that Lambda sends to a function for processing. Minimum value of 60. Maximum value of 86400. Default: Duration.hours(24)retry_attempts (
Union
[int
,float
,None
]) – The maximum number of times to retry when the function returns an error. Minimum value of 0. Maximum value of 185. Default: 185
Methods
- bind(_rule, _id=None)
Allows using tasks as target of EventBridge events.
- Parameters:
_rule (
IRule
) –_id (
Optional
[str
]) –
- Return type:
Attributes
- security_groups
The security groups associated with the task.
Only applicable with awsvpc network mode.
- Default:
A new security group is created.