# EcsTask

Start a task on an ECS cluster.

Extends: EcsTask
Implements: IRuleTarget

- Source: [`aws-events-targets/lib/ecs-task.ts`](https://github.com/aws/aws-cdk/blob/v2.275.0/packages/aws-cdk-lib/aws-events-targets/lib/ecs-task.ts#L192)
- Type last changed: v2.235.0 · 15 Jan 2026

## 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',
}));
```

## Initializer

```ts
new EcsTask(props: EcsTaskProps)
```

## Properties

- `securityGroups`: [ISecurityGroup](/cdk/api/v2/docs/aws-cdk-lib.aws_ec2.ISecurityGroup.html)[] — The security groups associated with the task.

  **Default:** A new security group is created.

  Only applicable with awsvpc network mode.

## Methods

- `bind(rule: IRuleRef, _id?: string): RuleTargetConfig` — Allows using tasks as target of EventBridge events.
