Skip to content
v2.275.0

EcsRunEc2Task Class ​

Schedule an ECS Task on EC2 using AWS EventBridge Scheduler.

Example ​

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

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

new Schedule(this, 'Schedule', {
  schedule: ScheduleExpression.rate(cdk.Duration.minutes(60)),
  target: new targets.EcsRunEc2Task(cluster, {
    taskDefinition,
  }),
});
python
import aws_cdk.aws_ecs as ecs

# cluster: ecs.ICluster
# task_definition: ecs.Ec2TaskDefinition


Schedule(self, "Schedule",
    schedule=ScheduleExpression.rate(cdk.Duration.minutes(60)),
    target=targets.EcsRunEc2Task(cluster,
        task_definition=task_definition
    )
)
java
import software.amazon.awscdk.services.ecs.*;

ICluster cluster;
Ec2TaskDefinition taskDefinition;


Schedule.Builder.create(this, "Schedule")
        .schedule(ScheduleExpression.rate(Duration.minutes(60)))
        .target(EcsRunEc2Task.Builder.create(cluster)
                .taskDefinition(taskDefinition)
                .build())
        .build();
csharp
// Install: dotnet add package Amazon.CDK.Lib
using Amazon.CDK.AWS.ECS;

ICluster cluster;
Ec2TaskDefinition taskDefinition;


new Schedule(this, "Schedule", new ScheduleProps {
    Schedule = ScheduleExpression.Rate(Duration.Minutes(60)),
    Target = new EcsRunEc2Task(cluster, new Ec2TaskProps {
        TaskDefinition = taskDefinition
    })
});
go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
import ecs "github.com/aws/aws-cdk-go/awscdk"

var cluster ICluster
var taskDefinition Ec2TaskDefinition


awscdk.NewSchedule(this, jsii.String("Schedule"), &ScheduleProps{
	Schedule: awscdk.ScheduleExpression_Rate(cdk.Duration_Minutes(jsii.Number(60))),
	Target: targets.NewEcsRunEc2Task(cluster, &Ec2TaskProps{
		TaskDefinition: *TaskDefinition,
	}),
})

Initializer ​

ts
new EcsRunEc2Task(cluster: ICluster, props: Ec2TaskProps)
python
EcsRunEc2Task(cluster: ICluster, props: Ec2TaskProps)
java
new EcsRunEc2Task(ICluster cluster, Ec2TaskProps props)
csharp
new EcsRunEc2Task(ICluster cluster, Ec2TaskProps props)
go
NewEcsRunEc2Task(Cluster ICluster, Props Ec2TaskProps)

Methods ​

bind(schedule: ISchedule): ScheduleTargetConfigdef bind(self, schedule: ISchedule) -> ScheduleTargetConfigpublic ScheduleTargetConfig bind(ISchedule schedule)public ScheduleTargetConfig Bind(ISchedule schedule)func Bind(Schedule ISchedule) ScheduleTargetConfig#
Create a return a Schedule Target Configuration for the given schedule.
returns

Returns: a Schedule Target Configuration