Skip to content
v2.275.0

EcsTaskProps Struct ​

Properties to define an ECS Event Task.

Example ​

ts
import * as ecs from 'aws-cdk-lib/aws-ecs';

declare const cluster: ecs.ICluster;
declare const taskDefinition: ecs.TaskDefinition;

const rule = new events.Rule(this, 'Rule', {
  schedule: events.Schedule.rate(cdk.Duration.hours(1)),
});

rule.addTarget(new targets.EcsTask({
  cluster,
  taskDefinition,
  taskCount: 1,

  // Overrides the cpu and memory values in the task definition
  cpu: '512',
  memory: '512',
}));

Properties ​

assignPublicIpoptionalbooleanassign_public_ipoptionalboolassignPublicIpoptionalBooleanAssignPublicIpoptionalboolAssignPublicIpoptional*bool#
Specifies whether the task's elastic network interface receives a public IP address.

Default: true if the subnet type is PUBLIC, otherwise false

You can specify true only when LaunchType is set to FARGATE.

clusterIClusterclusterIClusterclusterIClusterClusterIClusterClusterIClusterrequired#
Cluster where service will be deployed.
containerOverridesoptionalContainerOverride[]container_overridesoptionaltyping.List[ContainerOverride]containerOverridesoptionalList<ContainerOverride>ContainerOverridesoptionalContainerOverride[]ContainerOverridesoptional*[]ContainerOverride#
Container setting overrides.

Key is the name of the container to override, value is the values you want to override.

cpuoptionalstringcpuoptionalstrcpuoptionalStringCpuoptionalstringCpuoptional*string#
The CPU override for the task.

Default: The task definition's CPU value

deadLetterQueueoptionalIQueuedead_letter_queueoptionalIQueuedeadLetterQueueoptionalIQueueDeadLetterQueueoptionalIQueueDeadLetterQueueoptionalIQueue#
The SQS queue to be used as deadLetterQueue. Check out the [considerations for using a dead-letter queue](https://docs.aws.amazon.com/eventbridge/latest/userguide/rule-dlq.html#dlq-considerations).

Default: no dead-letter queue

notes

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.

enableExecuteCommandoptionalbooleanenable_execute_commandoptionalboolenableExecuteCommandoptionalBooleanEnableExecuteCommandoptionalboolEnableExecuteCommandoptional*bool= false#
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.

ephemeralStorageoptionalEphemeralStorageOverrideephemeral_storageoptionalEphemeralStorageOverrideephemeralStorageoptionalEphemeralStorageOverrideEphemeralStorageoptionalEphemeralStorageOverrideEphemeralStorageoptionalEphemeralStorageOverride#
The ephemeral storage setting override for the task.

Default: The task definition's ephemeral storage value

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.
executionRoleoptionalIRoleexecution_roleoptionalIRoleexecutionRoleoptionalIRoleExecutionRoleoptionalIRoleExecutionRoleoptionalIRole#
The execution role for the task.

Default: The task definition's execution role

The Amazon Resource Name (ARN) of the task execution role override for the task.

inferenceAcceleratorOverridesoptionalInferenceAcceleratorOverride[]inference_accelerator_overridesoptionaltyping.List[InferenceAcceleratorOverride]inferenceAcceleratorOverridesoptionalList<InferenceAcceleratorOverride>InferenceAcceleratorOverridesoptionalInferenceAcceleratorOverride[]InferenceAcceleratorOverridesoptional*[]InferenceAcceleratorOverride#
The Elastic Inference accelerator override for the task.

Default: The task definition's inference accelerator overrides

launchTypeoptionalLaunchTypelaunch_typeoptionalLaunchTypelaunchTypeoptionalLaunchTypeLaunchTypeoptionalLaunchTypeLaunchTypeoptionalLaunchType#
Specifies the launch type on which your task is running.

Default: 'EC2' if isEc2Compatible for the taskDefinition is true, otherwise 'FARGATE'

The launch type that you specify here must match one of the launch type (compatibilities) of the target task.

maxEventAgeoptionalDurationmax_event_ageoptionalDurationmaxEventAgeoptionalDurationMaxEventAgeoptionalDurationMaxEventAgeoptionalDuration= Duration.hours(24)#
The maximum age of a request that Lambda sends to a function for processing.

Minimum value of 60. Maximum value of 86400.

memoryoptionalstringmemoryoptionalstrmemoryoptionalStringMemoryoptionalstringMemoryoptional*string#
The memory override for the task.

Default: The task definition's memory value

platformVersionoptionalFargatePlatformVersionplatform_versionoptionalFargatePlatformVersionplatformVersionoptionalFargatePlatformVersionPlatformVersionoptionalFargatePlatformVersionPlatformVersionoptionalFargatePlatformVersion#
The platform version on which to run your task.

Default: ECS will set the Fargate platform version to 'LATEST'

Unless you have specific compatibility requirements, you don't need to specify this.

propagateTagsoptionalPropagatedTagSourcepropagate_tagsoptionalPropagatedTagSourcepropagateTagsoptionalPropagatedTagSourcePropagateTagsoptionalPropagatedTagSourcePropagateTagsoptionalPropagatedTagSource#
Specifies whether to propagate the tags from the task definition to the task.

Default: Tags will not be propagated

If no value is specified, the tags are not propagated.

retryAttemptsoptionalnumberretry_attemptsoptionalint | floatretryAttemptsoptionalNumberRetryAttemptsoptionaldoubleRetryAttemptsoptional*float64= 185#
The maximum number of times to retry when the function returns an error.

Minimum value of 0. Maximum value of 185.

roleoptionalIRoleroleoptionalIRoleroleoptionalIRoleRoleoptionalIRoleRoleoptionalIRole#
Existing IAM role to run the ECS task.

Default: A new IAM role is created

securityGroupsoptionalISecurityGroup[]security_groupsoptionaltyping.List[ISecurityGroup]securityGroupsoptionalList<ISecurityGroup>SecurityGroupsoptionalISecurityGroup[]SecurityGroupsoptional*[]ISecurityGroup#
Existing security groups to use for the task's ENIs.

Default: A new security group is created

(Only applicable in case the TaskDefinition is configured for AwsVpc networking)

subnetSelectionoptionalSubnetSelectionsubnet_selectionoptionalSubnetSelectionsubnetSelectionoptionalSubnetSelectionSubnetSelectionoptionalSubnetSelectionSubnetSelectionoptionalSubnetSelection#
In what subnets to place the task's ENIs.

Default: Private subnets

(Only applicable in case the TaskDefinition is configured for AwsVpc networking)

tagsoptionalTag[]tagsoptionaltyping.List[Tag]tagsoptionalList<Tag>TagsoptionalTag[]Tagsoptional*[]Tag#
The metadata that you apply to the task to help you categorize and organize them.

Default: No additional tags are applied to the task

Each tag consists of a key and an optional value, both of which you define.

taskCountoptionalnumbertask_countoptionalint | floattaskCountoptionalNumberTaskCountoptionaldoubleTaskCountoptional*float64= 1#
How many tasks should be started when this event is triggered.
taskDefinitionITaskDefinitiontask_definitionITaskDefinitiontaskDefinitionITaskDefinitionTaskDefinitionITaskDefinitionTaskDefinitionITaskDefinitionrequired#
Task Definition of the task that should be started.
taskRoleoptionalIRoletask_roleoptionalIRoletaskRoleoptionalIRoleTaskRoleoptionalIRoleTaskRoleoptionalIRole#
The IAM role for the task.

Default: The task definition's task role