Skip to content
v2.274.0

Amazon EventBridge Scheduler Targets Construct Library ​

Amazon EventBridge Scheduler is a feature from Amazon EventBridge that allows you to create, run, and manage scheduled tasks at scale. With EventBridge Scheduler, you can schedule millions of one-time or recurring tasks across various AWS services without provisioning or managing underlying infrastructure.

This library contains integration classes for Amazon EventBridge Scheduler to call any number of supported AWS Services.

The following targets are supported:

  1. targets.LambdaInvoke: Invoke an AWS Lambda function
  2. targets.StepFunctionsStartExecution: Start an AWS Step Function
  3. targets.CodeBuildStartBuild: Start a CodeBuild job
  4. targets.SqsSendMessage: Send a Message to an Amazon SQS Queue
  5. targets.SnsPublish: Publish messages to an Amazon SNS topic
  6. targets.EventBridgePutEvents: Put Events on EventBridge
  7. targets.InspectorStartAssessmentRun: Start an Amazon Inspector assessment run
  8. targets.KinesisStreamPutRecord: Put a record to an Amazon Kinesis Data Stream
  9. targets.FirehosePutRecord: Put a record to an Amazon Data Firehose
  10. targets.CodePipelineStartPipelineExecution: Start a CodePipeline execution
  11. targets.SageMakerStartPipelineExecution: Start a SageMaker pipeline execution
  12. targets.EcsRunTask: Start a new ECS task
  13. targets.Universal: Invoke a wider set of AWS API

Invoke a Lambda function ​

Use the LambdaInvoke target to invoke a lambda function.

The code snippet below creates an event rule with a Lambda function as a target called every hour by EventBridge Scheduler with a custom payload. You can optionally attach a dead letter queue.

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

const fn = new lambda.Function(this, 'MyFunc', {
    runtime: lambda.Runtime.NODEJS_LATEST,
    handler: 'index.handler',
    code: lambda.Code.fromInline(`exports.handler = handler.toString()`),
});

const dlq = new sqs.Queue(this, "DLQ", {
    queueName: 'MyDLQ',
});

const target = new targets.LambdaInvoke(fn, {
    deadLetterQueue: dlq,
    maxEventAge: Duration.minutes(1),
    retryAttempts: 3,
    input: ScheduleTargetInput.fromObject({
        'payload': 'useful'
    }),
});

const schedule = new Schedule(this, 'Schedule', {
    schedule: ScheduleExpression.rate(Duration.hours(1)),
    target
});
python
import aws_cdk.aws_lambda as lambda_


fn = lambda_.Function(self, "MyFunc",
    runtime=lambda_.Runtime.NODEJS_LATEST,
    handler="index.handler",
    code=lambda_.Code.from_inline("exports.handler = handler.toString()")
)

dlq = sqs.Queue(self, "DLQ",
    queue_name="MyDLQ"
)

target = targets.LambdaInvoke(fn,
    dead_letter_queue=dlq,
    max_event_age=Duration.minutes(1),
    retry_attempts=3,
    input=ScheduleTargetInput.from_object({
        "payload": "useful"
    })
)

schedule = Schedule(self, "Schedule",
    schedule=ScheduleExpression.rate(Duration.hours(1)),
    target=target
)
java
import software.amazon.awscdk.services.lambda.*;


Function fn = Function.Builder.create(this, "MyFunc")
        .runtime(Runtime.NODEJS_LATEST)
        .handler("index.handler")
        .code(Code.fromInline("exports.handler = handler.toString()"))
        .build();

Queue dlq = Queue.Builder.create(this, "DLQ")
        .queueName("MyDLQ")
        .build();

LambdaInvoke target = LambdaInvoke.Builder.create(fn)
        .deadLetterQueue(dlq)
        .maxEventAge(Duration.minutes(1))
        .retryAttempts(3)
        .input(ScheduleTargetInput.fromObject(Map.of(
                "payload", "useful")))
        .build();

Schedule schedule = Schedule.Builder.create(this, "Schedule")
        .schedule(ScheduleExpression.rate(Duration.hours(1)))
        .target(target)
        .build();
csharp
using Amazon.CDK.AWS.Lambda;


var fn = new Function(this, "MyFunc", new FunctionProps {
    Runtime = Runtime.NODEJS_LATEST,
    Handler = "index.handler",
    Code = Code.FromInline("exports.handler = handler.toString()")
});

var dlq = new Queue(this, "DLQ", new QueueProps {
    QueueName = "MyDLQ"
});

var target = new LambdaInvoke(fn, new ScheduleTargetBaseProps {
    DeadLetterQueue = dlq,
    MaxEventAge = Duration.Minutes(1),
    RetryAttempts = 3,
    Input = ScheduleTargetInput.FromObject(new Dictionary<string, string> {
        { "payload", "useful" }
    })
});

var schedule = new Schedule(this, "Schedule", new ScheduleProps {
    Schedule = ScheduleExpression.Rate(Duration.Hours(1)),
    Target = target
});
go
import "github.com/aws/aws-cdk-go/awscdk"


fn := lambda.NewFunction(this, jsii.String("MyFunc"), &FunctionProps{
	Runtime: lambda.Runtime_NODEJS_LATEST(),
	Handler: jsii.String("index.handler"),
	Code: lambda.Code_FromInline(jsii.String("exports.handler = handler.toString()")),
})

dlq := sqs.NewQueue(this, jsii.String("DLQ"), &QueueProps{
	QueueName: jsii.String("MyDLQ"),
})

target := targets.NewLambdaInvoke(fn, &ScheduleTargetBaseProps{
	DeadLetterQueue: dlq,
	MaxEventAge: awscdk.Duration_Minutes(jsii.Number(1)),
	RetryAttempts: jsii.Number(3),
	Input: awscdk.ScheduleTargetInput_FromObject(map[string]*string{
		"payload": jsii.String("useful"),
	}),
})

schedule := awscdk.NewSchedule(this, jsii.String("Schedule"), &ScheduleProps{
	Schedule: awscdk.ScheduleExpression_Rate(awscdk.Duration_Hours(jsii.Number(1))),
	Target: Target,
})

Start an AWS Step Function ​

Use the StepFunctionsStartExecution target to start a new execution on a StepFunction.

The code snippet below creates an event rule with a Step Function as a target called every hour by EventBridge Scheduler with a custom payload.

ts
import * as sfn from 'aws-cdk-lib/aws-stepfunctions';
import * as tasks from 'aws-cdk-lib/aws-stepfunctions-tasks';

const payload = {
  Name: "MyParameter",
  Value: '🌥️',
};

const putParameterStep = new tasks.CallAwsService(this, 'PutParameter', {
  service: 'ssm',
  action: 'putParameter',
  iamResources: ['*'],
  parameters: {
    "Name.$": '$.Name',
    "Value.$": '$.Value',
    Type: 'String',
    Overwrite: true,
  },
});

const stateMachine = new sfn.StateMachine(this, 'StateMachine', {
  definitionBody: sfn.DefinitionBody.fromChainable(putParameterStep)
});

new Schedule(this, 'Schedule', {
  schedule: ScheduleExpression.rate(Duration.hours(1)),
  target: new targets.StepFunctionsStartExecution(stateMachine, {
    input: ScheduleTargetInput.fromObject(payload),
  }),
});
python
import aws_cdk.aws_stepfunctions as sfn
import aws_cdk.aws_stepfunctions_tasks as tasks


payload = {
    "Name": "MyParameter",
    "Value": "🌥️"
}

put_parameter_step = tasks.CallAwsService(self, "PutParameter",
    service="ssm",
    action="putParameter",
    iam_resources=["*"],
    parameters={
        "Name.$": "$.Name",
        "Value.$": "$.Value",
        "Type": "String",
        "Overwrite": True
    }
)

state_machine = sfn.StateMachine(self, "StateMachine",
    definition_body=sfn.DefinitionBody.from_chainable(put_parameter_step)
)

Schedule(self, "Schedule",
    schedule=ScheduleExpression.rate(Duration.hours(1)),
    target=targets.StepFunctionsStartExecution(state_machine,
        input=ScheduleTargetInput.from_object(payload)
    )
)
java
import software.amazon.awscdk.services.stepfunctions.*;
import software.amazon.awscdk.services.stepfunctions.tasks.*;


Map<String, String> payload = Map.of(
        "Name", "MyParameter",
        "Value", "🌥️");

CallAwsService putParameterStep = CallAwsService.Builder.create(this, "PutParameter")
        .service("ssm")
        .action("putParameter")
        .iamResources(List.of("*"))
        .parameters(Map.of(
                "Name.$", "$.Name",
                "Value.$", "$.Value",
                "Type", "String",
                "Overwrite", true))
        .build();

StateMachine stateMachine = StateMachine.Builder.create(this, "StateMachine")
        .definitionBody(DefinitionBody.fromChainable(putParameterStep))
        .build();

Schedule.Builder.create(this, "Schedule")
        .schedule(ScheduleExpression.rate(Duration.hours(1)))
        .target(StepFunctionsStartExecution.Builder.create(stateMachine)
                .input(ScheduleTargetInput.fromObject(payload))
                .build())
        .build();
csharp
using Amazon.CDK.AWS.StepFunctions;
using Amazon.CDK.AWS.StepFunctions.Tasks;


IDictionary<string, string> payload = new Dictionary<string, string> {
    { "Name", "MyParameter" },
    { "Value", "🌥️" }
};

var putParameterStep = new CallAwsService(this, "PutParameter", new CallAwsServiceProps {
    Service = "ssm",
    Action = "putParameter",
    IamResources = new [] { "*" },
    Parameters = new Dictionary<string, object> {
        { "Name.$", "$.Name" },
        { "Value.$", "$.Value" },
        { "Type", "String" },
        { "Overwrite", true }
    }
});

var stateMachine = new StateMachine(this, "StateMachine", new StateMachineProps {
    DefinitionBody = DefinitionBody.FromChainable(putParameterStep)
});

new Schedule(this, "Schedule", new ScheduleProps {
    Schedule = ScheduleExpression.Rate(Duration.Hours(1)),
    Target = new StepFunctionsStartExecution(stateMachine, new ScheduleTargetBaseProps {
        Input = ScheduleTargetInput.FromObject(payload)
    })
});
go
import "github.com/aws/aws-cdk-go/awscdk"
import tasks "github.com/aws/aws-cdk-go/awscdk"


payload := map[string]*string{
	"Name": jsii.String("MyParameter"),
	"Value": jsii.String("🌥️"),
}

putParameterStep := tasks.NewCallAwsService(this, jsii.String("PutParameter"), &CallAwsServiceProps{
	Service: jsii.String("ssm"),
	Action: jsii.String("putParameter"),
	IamResources: []*string{
		jsii.String("*"),
	},
	Parameters: map[string]interface{}{
		"Name.$": jsii.String("$.Name"),
		"Value.$": jsii.String("$.Value"),
		"Type": jsii.String("String"),
		"Overwrite": jsii.Boolean(true),
	},
})

stateMachine := sfn.NewStateMachine(this, jsii.String("StateMachine"), &StateMachineProps{
	DefinitionBody: sfn.DefinitionBody_FromChainable(putParameterStep),
})

awscdk.NewSchedule(this, jsii.String("Schedule"), &ScheduleProps{
	Schedule: awscdk.ScheduleExpression_Rate(awscdk.Duration_Hours(jsii.Number(1))),
	Target: targets.NewStepFunctionsStartExecution(stateMachine, &ScheduleTargetBaseProps{
		Input: awscdk.ScheduleTargetInput_FromObject(payload),
	}),
})

Start a CodeBuild job ​

Use the CodeBuildStartBuild target to start a new build run on a CodeBuild project.

The code snippet below creates an event rule with a CodeBuild project as target which is called every hour by EventBridge Scheduler.

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

declare const project: codebuild.Project;

new Schedule(this, 'Schedule', {
  schedule: ScheduleExpression.rate(Duration.minutes(60)),
  target: new targets.CodeBuildStartBuild(project),
});
python
import aws_cdk.aws_codebuild as codebuild

# project: codebuild.Project


Schedule(self, "Schedule",
    schedule=ScheduleExpression.rate(Duration.minutes(60)),
    target=targets.CodeBuildStartBuild(project)
)
java
import software.amazon.awscdk.services.codebuild.*;

Project project;


Schedule.Builder.create(this, "Schedule")
        .schedule(ScheduleExpression.rate(Duration.minutes(60)))
        .target(new CodeBuildStartBuild(project))
        .build();
csharp
using Amazon.CDK.AWS.CodeBuild;

Project project;


new Schedule(this, "Schedule", new ScheduleProps {
    Schedule = ScheduleExpression.Rate(Duration.Minutes(60)),
    Target = new CodeBuildStartBuild(project)
});
go
import codebuild "github.com/aws/aws-cdk-go/awscdk"

var project Project


awscdk.NewSchedule(this, jsii.String("Schedule"), &ScheduleProps{
	Schedule: awscdk.ScheduleExpression_Rate(awscdk.Duration_Minutes(jsii.Number(60))),
	Target: targets.NewCodeBuildStartBuild(project),
})

Send a Message To an SQS Queue ​

Use the SqsSendMessage target to send a message to an SQS Queue.

The code snippet below creates an event rule with an SQS Queue as a target called every hour by EventBridge Scheduler with a custom payload.

Contains the messageGroupId to use when the target is a FIFO queue. If you specify a FIFO queue as a target, the queue must have content-based deduplication enabled.

ts
const payload = 'test';
const messageGroupId = 'id';
const queue = new sqs.Queue(this, 'MyQueue', {
  fifo: true,
  contentBasedDeduplication: true,
});

const target = new targets.SqsSendMessage(queue, {
    input: ScheduleTargetInput.fromText(payload),
    messageGroupId,
});

new Schedule(this, 'Schedule', {
    schedule: ScheduleExpression.rate(Duration.minutes(1)),
    target
});
python
payload = "test"
message_group_id = "id"
queue = sqs.Queue(self, "MyQueue",
    fifo=True,
    content_based_deduplication=True
)

target = targets.SqsSendMessage(queue,
    input=ScheduleTargetInput.from_text(payload),
    message_group_id=message_group_id
)

Schedule(self, "Schedule",
    schedule=ScheduleExpression.rate(Duration.minutes(1)),
    target=target
)
java
String payload = "test";
String messageGroupId = "id";
Queue queue = Queue.Builder.create(this, "MyQueue")
        .fifo(true)
        .contentBasedDeduplication(true)
        .build();

SqsSendMessage target = SqsSendMessage.Builder.create(queue)
        .input(ScheduleTargetInput.fromText(payload))
        .messageGroupId(messageGroupId)
        .build();

Schedule.Builder.create(this, "Schedule")
        .schedule(ScheduleExpression.rate(Duration.minutes(1)))
        .target(target)
        .build();
csharp
var payload = "test";
var messageGroupId = "id";
var queue = new Queue(this, "MyQueue", new QueueProps {
    Fifo = true,
    ContentBasedDeduplication = true
});

var target = new SqsSendMessage(queue, new SqsSendMessageProps {
    Input = ScheduleTargetInput.FromText(payload),
    MessageGroupId = messageGroupId
});

new Schedule(this, "Schedule", new ScheduleProps {
    Schedule = ScheduleExpression.Rate(Duration.Minutes(1)),
    Target = target
});
go
payload := "test"
messageGroupId := "id"
queue := sqs.NewQueue(this, jsii.String("MyQueue"), &QueueProps{
	Fifo: jsii.Boolean(true),
	ContentBasedDeduplication: jsii.Boolean(true),
})

target := targets.NewSqsSendMessage(queue, &SqsSendMessageProps{
	Input: awscdk.ScheduleTargetInput_FromText(payload),
	MessageGroupId: jsii.String(MessageGroupId),
})

awscdk.NewSchedule(this, jsii.String("Schedule"), &ScheduleProps{
	Schedule: awscdk.ScheduleExpression_Rate(awscdk.Duration_Minutes(jsii.Number(1))),
	Target: Target,
})

Publish messages to an Amazon SNS topic ​

Use the SnsPublish target to publish messages to an Amazon SNS topic.

The code snippets below create an event rule with a Amazon SNS topic as a target. It's called every hour by Amazon EventBridge Scheduler with a custom payload.

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

const topic = new sns.Topic(this, 'Topic');

const payload = {
  message: 'Hello scheduler!',
};

const target = new targets.SnsPublish(topic, {
  input: ScheduleTargetInput.fromObject(payload),
});

new Schedule(this, 'Schedule', {
  schedule: ScheduleExpression.rate(Duration.hours(1)),
  target,
});
python
import aws_cdk.aws_sns as sns


topic = sns.Topic(self, "Topic")

payload = {
    "message": "Hello scheduler!"
}

target = targets.SnsPublish(topic,
    input=ScheduleTargetInput.from_object(payload)
)

Schedule(self, "Schedule",
    schedule=ScheduleExpression.rate(Duration.hours(1)),
    target=target
)
java
import software.amazon.awscdk.services.sns.*;


Topic topic = new Topic(this, "Topic");

Map<String, String> payload = Map.of(
        "message", "Hello scheduler!");

SnsPublish target = SnsPublish.Builder.create(topic)
        .input(ScheduleTargetInput.fromObject(payload))
        .build();

Schedule.Builder.create(this, "Schedule")
        .schedule(ScheduleExpression.rate(Duration.hours(1)))
        .target(target)
        .build();
csharp
using Amazon.CDK.AWS.SNS;


var topic = new Topic(this, "Topic");

IDictionary<string, string> payload = new Dictionary<string, string> {
    { "message", "Hello scheduler!" }
};

var target = new SnsPublish(topic, new ScheduleTargetBaseProps {
    Input = ScheduleTargetInput.FromObject(payload)
});

new Schedule(this, "Schedule", new ScheduleProps {
    Schedule = ScheduleExpression.Rate(Duration.Hours(1)),
    Target = target
});
go
import sns "github.com/aws/aws-cdk-go/awscdk"


topic := sns.NewTopic(this, jsii.String("Topic"))

payload := map[string]*string{
	"message": jsii.String("Hello scheduler!"),
}

target := targets.NewSnsPublish(topic, &ScheduleTargetBaseProps{
	Input: awscdk.ScheduleTargetInput_FromObject(payload),
})

awscdk.NewSchedule(this, jsii.String("Schedule"), &ScheduleProps{
	Schedule: awscdk.ScheduleExpression_Rate(awscdk.Duration_Hours(jsii.Number(1))),
	Target: Target,
})

Send events to an EventBridge event bus ​

Use the EventBridgePutEvents target to send events to an EventBridge event bus.

The code snippet below creates an event rule with an EventBridge event bus as a target called every hour by EventBridge Scheduler with a custom event payload.

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

const eventBus = new events.EventBus(this, 'EventBus', {
  eventBusName: 'DomainEvents',
});

const eventEntry: targets.EventBridgePutEventsEntry = {
  eventBus,
  source: 'PetService',
  detail: ScheduleTargetInput.fromObject({ Name: 'Fluffy' }),
  detailType: '🐶',
};

new Schedule(this, 'Schedule', {
  schedule: ScheduleExpression.rate(Duration.hours(1)),
  target: new targets.EventBridgePutEvents(eventEntry),
});
python
import aws_cdk.aws_events as events


event_bus = events.EventBus(self, "EventBus",
    event_bus_name="DomainEvents"
)

event_entry = targets.EventBridgePutEventsEntry(
    event_bus=event_bus,
    source="PetService",
    detail=ScheduleTargetInput.from_object({"Name": "Fluffy"}),
    detail_type="🐶"
)

Schedule(self, "Schedule",
    schedule=ScheduleExpression.rate(Duration.hours(1)),
    target=targets.EventBridgePutEvents(event_entry)
)
java
import software.amazon.awscdk.services.events.*;


EventBus eventBus = EventBus.Builder.create(this, "EventBus")
        .eventBusName("DomainEvents")
        .build();

EventBridgePutEventsEntry eventEntry = EventBridgePutEventsEntry.builder()
        .eventBus(eventBus)
        .source("PetService")
        .detail(ScheduleTargetInput.fromObject(Map.of("Name", "Fluffy")))
        .detailType("🐶")
        .build();

Schedule.Builder.create(this, "Schedule")
        .schedule(ScheduleExpression.rate(Duration.hours(1)))
        .target(new EventBridgePutEvents(eventEntry))
        .build();
csharp
using Amazon.CDK.AWS.Events;


var eventBus = new EventBus(this, "EventBus", new EventBusProps {
    EventBusName = "DomainEvents"
});

var eventEntry = new EventBridgePutEventsEntry {
    EventBus = eventBus,
    Source = "PetService",
    Detail = ScheduleTargetInput.FromObject(new Dictionary<string, string> { { "Name", "Fluffy" } }),
    DetailType = "🐶"
};

new Schedule(this, "Schedule", new ScheduleProps {
    Schedule = ScheduleExpression.Rate(Duration.Hours(1)),
    Target = new EventBridgePutEvents(eventEntry)
});
go
import events "github.com/aws/aws-cdk-go/awscdk"


eventBus := events.NewEventBus(this, jsii.String("EventBus"), &EventBusProps{
	EventBusName: jsii.String("DomainEvents"),
})

eventEntry := &EventBridgePutEventsEntry{
	EventBus: EventBus,
	Source: jsii.String("PetService"),
	Detail: awscdk.ScheduleTargetInput_FromObject(map[string]*string{
		"Name": jsii.String("Fluffy"),
	}),
	DetailType: jsii.String("🐶"),
}

awscdk.NewSchedule(this, jsii.String("Schedule"), &ScheduleProps{
	Schedule: awscdk.ScheduleExpression_Rate(awscdk.Duration_Hours(jsii.Number(1))),
	Target: targets.NewEventBridgePutEvents(eventEntry),
})

Start an Amazon Inspector assessment run ​

Use the InspectorStartAssessmentRun target to start an Inspector assessment run.

The code snippet below creates an event rule with an assessment template as the target which is called every hour by EventBridge Scheduler.

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

declare const cfnAssessmentTemplate: inspector.CfnAssessmentTemplate;

const assessmentTemplate = inspector.AssessmentTemplate.fromCfnAssessmentTemplate(this, 'MyAssessmentTemplate', cfnAssessmentTemplate);

new Schedule(this, 'Schedule', {
  schedule: ScheduleExpression.rate(Duration.minutes(60)),
  target: new targets.InspectorStartAssessmentRun(assessmentTemplate),
});
python
import aws_cdk.aws_inspector as inspector

# cfn_assessment_template: inspector.CfnAssessmentTemplate


assessment_template = inspector.AssessmentTemplate.from_cfn_assessment_template(self, "MyAssessmentTemplate", cfn_assessment_template)

Schedule(self, "Schedule",
    schedule=ScheduleExpression.rate(Duration.minutes(60)),
    target=targets.InspectorStartAssessmentRun(assessment_template)
)
java
import software.amazon.awscdk.services.inspector.*;

CfnAssessmentTemplate cfnAssessmentTemplate;


IAssessmentTemplate assessmentTemplate = AssessmentTemplate.fromCfnAssessmentTemplate(this, "MyAssessmentTemplate", cfnAssessmentTemplate);

Schedule.Builder.create(this, "Schedule")
        .schedule(ScheduleExpression.rate(Duration.minutes(60)))
        .target(new InspectorStartAssessmentRun(assessmentTemplate))
        .build();
csharp
using Amazon.CDK.AWS.Inspector;

CfnAssessmentTemplate cfnAssessmentTemplate;


var assessmentTemplate = AssessmentTemplate.FromCfnAssessmentTemplate(this, "MyAssessmentTemplate", cfnAssessmentTemplate);

new Schedule(this, "Schedule", new ScheduleProps {
    Schedule = ScheduleExpression.Rate(Duration.Minutes(60)),
    Target = new InspectorStartAssessmentRun(assessmentTemplate)
});
go
import inspector "github.com/aws/aws-cdk-go/awscdk"

var cfnAssessmentTemplate CfnAssessmentTemplate


assessmentTemplate := inspector.AssessmentTemplate_FromCfnAssessmentTemplate(this, jsii.String("MyAssessmentTemplate"), cfnAssessmentTemplate)

awscdk.NewSchedule(this, jsii.String("Schedule"), &ScheduleProps{
	Schedule: awscdk.ScheduleExpression_Rate(awscdk.Duration_Minutes(jsii.Number(60))),
	Target: targets.NewInspectorStartAssessmentRun(assessmentTemplate),
})

Put a record to an Amazon Kinesis Data Stream ​

Use the KinesisStreamPutRecord target to put a record to an Amazon Kinesis Data Stream.

The code snippet below creates an event rule with a stream as the target which is called every hour by EventBridge Scheduler.

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

const stream = new kinesis.Stream(this, 'MyStream');

new Schedule(this, 'Schedule', {
  schedule: ScheduleExpression.rate(Duration.minutes(60)),
  target: new targets.KinesisStreamPutRecord(stream, {
    partitionKey: 'key',
  }),
});
python
import aws_cdk.aws_kinesis as kinesis


stream = kinesis.Stream(self, "MyStream")

Schedule(self, "Schedule",
    schedule=ScheduleExpression.rate(Duration.minutes(60)),
    target=targets.KinesisStreamPutRecord(stream,
        partition_key="key"
    )
)
java
import software.amazon.awscdk.services.kinesis.*;


Stream stream = new Stream(this, "MyStream");

Schedule.Builder.create(this, "Schedule")
        .schedule(ScheduleExpression.rate(Duration.minutes(60)))
        .target(KinesisStreamPutRecord.Builder.create(stream)
                .partitionKey("key")
                .build())
        .build();
csharp
using Amazon.CDK.AWS.Kinesis;


var stream = new Stream(this, "MyStream");

new Schedule(this, "Schedule", new ScheduleProps {
    Schedule = ScheduleExpression.Rate(Duration.Minutes(60)),
    Target = new KinesisStreamPutRecord(stream, new KinesisStreamPutRecordProps {
        PartitionKey = "key"
    })
});
go
import kinesis "github.com/aws/aws-cdk-go/awscdk"


stream := kinesis.NewStream(this, jsii.String("MyStream"))

awscdk.NewSchedule(this, jsii.String("Schedule"), &ScheduleProps{
	Schedule: awscdk.ScheduleExpression_Rate(awscdk.Duration_Minutes(jsii.Number(60))),
	Target: targets.NewKinesisStreamPutRecord(stream, &KinesisStreamPutRecordProps{
		PartitionKey: jsii.String("key"),
	}),
})

Put a record to an Amazon Data Firehose ​

Use the FirehosePutRecord target to put a record to an Amazon Data Firehose delivery stream.

The code snippet below creates an event rule with a delivery stream as a target called every hour by EventBridge Scheduler with a custom payload.

ts
import * as firehose from 'aws-cdk-lib/aws-kinesisfirehose';
declare const deliveryStream: firehose.IDeliveryStream;

const payload = {
  Data: "record",
};

new Schedule(this, 'Schedule', {
  schedule: ScheduleExpression.rate(Duration.minutes(60)),
  target: new targets.FirehosePutRecord(deliveryStream, {
    input: ScheduleTargetInput.fromObject(payload),
  }),
});
python
import aws_cdk.aws_kinesisfirehose as firehose
# delivery_stream: firehose.IDeliveryStream


payload = {
    "Data": "record"
}

Schedule(self, "Schedule",
    schedule=ScheduleExpression.rate(Duration.minutes(60)),
    target=targets.FirehosePutRecord(delivery_stream,
        input=ScheduleTargetInput.from_object(payload)
    )
)
java
import software.amazon.awscdk.services.kinesisfirehose.*;
IDeliveryStream deliveryStream;


Map<String, String> payload = Map.of(
        "Data", "record");

Schedule.Builder.create(this, "Schedule")
        .schedule(ScheduleExpression.rate(Duration.minutes(60)))
        .target(FirehosePutRecord.Builder.create(deliveryStream)
                .input(ScheduleTargetInput.fromObject(payload))
                .build())
        .build();
csharp
using Amazon.CDK.AWS.KinesisFirehose;
IDeliveryStream deliveryStream;


IDictionary<string, string> payload = new Dictionary<string, string> {
    { "Data", "record" }
};

new Schedule(this, "Schedule", new ScheduleProps {
    Schedule = ScheduleExpression.Rate(Duration.Minutes(60)),
    Target = new FirehosePutRecord(deliveryStream, new ScheduleTargetBaseProps {
        Input = ScheduleTargetInput.FromObject(payload)
    })
});
go
import firehose "github.com/aws/aws-cdk-go/awscdk"
var deliveryStream IDeliveryStream


payload := map[string]*string{
	"Data": jsii.String("record"),
}

awscdk.NewSchedule(this, jsii.String("Schedule"), &ScheduleProps{
	Schedule: awscdk.ScheduleExpression_Rate(awscdk.Duration_Minutes(jsii.Number(60))),
	Target: targets.NewFirehosePutRecord(deliveryStream, &ScheduleTargetBaseProps{
		Input: awscdk.ScheduleTargetInput_FromObject(payload),
	}),
})

Start a CodePipeline execution ​

Use the CodePipelineStartPipelineExecution target to start a new execution for a CodePipeline pipeline.

The code snippet below creates an event rule with a CodePipeline pipeline as the target which is called every hour by EventBridge Scheduler.

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

declare const pipeline: codepipeline.Pipeline;

new Schedule(this, 'Schedule', {
  schedule: ScheduleExpression.rate(Duration.minutes(60)),
  target: new targets.CodePipelineStartPipelineExecution(pipeline),
});
python
import aws_cdk.aws_codepipeline as codepipeline

# pipeline: codepipeline.Pipeline


Schedule(self, "Schedule",
    schedule=ScheduleExpression.rate(Duration.minutes(60)),
    target=targets.CodePipelineStartPipelineExecution(pipeline)
)
java
import software.amazon.awscdk.services.codepipeline.*;

Pipeline pipeline;


Schedule.Builder.create(this, "Schedule")
        .schedule(ScheduleExpression.rate(Duration.minutes(60)))
        .target(new CodePipelineStartPipelineExecution(pipeline))
        .build();
csharp
using Amazon.CDK.AWS.CodePipeline;

Pipeline pipeline;


new Schedule(this, "Schedule", new ScheduleProps {
    Schedule = ScheduleExpression.Rate(Duration.Minutes(60)),
    Target = new CodePipelineStartPipelineExecution(pipeline)
});
go
import codepipeline "github.com/aws/aws-cdk-go/awscdk"

var pipeline Pipeline


awscdk.NewSchedule(this, jsii.String("Schedule"), &ScheduleProps{
	Schedule: awscdk.ScheduleExpression_Rate(awscdk.Duration_Minutes(jsii.Number(60))),
	Target: targets.NewCodePipelineStartPipelineExecution(pipeline),
})

Start a SageMaker pipeline execution ​

Use the SageMakerStartPipelineExecution target to start a new execution for a SageMaker pipeline.

The code snippet below creates an event rule with a SageMaker pipeline as the target which is called every hour by EventBridge Scheduler.

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

declare const pipeline: sagemaker.IPipeline;

new Schedule(this, 'Schedule', {
  schedule: ScheduleExpression.rate(Duration.minutes(60)),
  target: new targets.SageMakerStartPipelineExecution(pipeline, {
    pipelineParameterList: [{
      name: 'parameter-name',
      value: 'parameter-value',
    }],
  }),
});
python
import aws_cdk.aws_sagemaker as sagemaker

# pipeline: sagemaker.IPipeline


Schedule(self, "Schedule",
    schedule=ScheduleExpression.rate(Duration.minutes(60)),
    target=targets.SageMakerStartPipelineExecution(pipeline,
        pipeline_parameter_list=[targets.SageMakerPipelineParameter(
            name="parameter-name",
            value="parameter-value"
        )]
    )
)
java
import software.amazon.awscdk.services.sagemaker.*;

IPipeline pipeline;


Schedule.Builder.create(this, "Schedule")
        .schedule(ScheduleExpression.rate(Duration.minutes(60)))
        .target(SageMakerStartPipelineExecution.Builder.create(pipeline)
                .pipelineParameterList(List.of(SageMakerPipelineParameter.builder()
                        .name("parameter-name")
                        .value("parameter-value")
                        .build()))
                .build())
        .build();
csharp
using Amazon.CDK.AWS.Sagemaker;

IPipeline pipeline;


new Schedule(this, "Schedule", new ScheduleProps {
    Schedule = ScheduleExpression.Rate(Duration.Minutes(60)),
    Target = new SageMakerStartPipelineExecution(pipeline, new SageMakerStartPipelineExecutionProps {
        PipelineParameterList = new [] { new SageMakerPipelineParameter {
            Name = "parameter-name",
            Value = "parameter-value"
        } }
    })
});
go
import sagemaker "github.com/aws/aws-cdk-go/awscdk"

var pipeline IPipeline


awscdk.NewSchedule(this, jsii.String("Schedule"), &ScheduleProps{
	Schedule: awscdk.ScheduleExpression_Rate(awscdk.Duration_Minutes(jsii.Number(60))),
	Target: targets.NewSageMakerStartPipelineExecution(pipeline, &SageMakerStartPipelineExecutionProps{
		PipelineParameterList: []SageMakerPipelineParameter{
			&SageMakerPipelineParameter{
				Name: jsii.String("parameter-name"),
				Value: jsii.String("parameter-value"),
			},
		},
	}),
})

Schedule an ECS task run ​

Use the EcsRunTask target to schedule an ECS task run for a cluster.

The code snippet below creates an event rule with a Fargate task definition and cluster as the target which is called every hour by EventBridge Scheduler.

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

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

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

# cluster: ecs.ICluster
# task_definition: ecs.FargateTaskDefinition


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

ICluster cluster;
FargateTaskDefinition taskDefinition;


Schedule.Builder.create(this, "Schedule")
        .schedule(ScheduleExpression.rate(Duration.minutes(60)))
        .target(EcsRunFargateTask.Builder.create(cluster)
                .taskDefinition(taskDefinition)
                .build())
        .build();
csharp
using Amazon.CDK.AWS.ECS;

ICluster cluster;
FargateTaskDefinition taskDefinition;


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

var cluster ICluster
var taskDefinition FargateTaskDefinition


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

The code snippet below creates an event rule with a EC2 task definition and cluster as the target which is called every hour by EventBridge Scheduler.

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
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
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,
	}),
})

Invoke a wider set of AWS API ​

Use the Universal target to invoke AWS API. See <https://docs.aws.amazon.com/scheduler/latest/UserGuide/managing-targets-universal.html>

The code snippet below creates an event rule with AWS API as the target which is called at midnight every day by EventBridge Scheduler.

ts
new Schedule(this, 'Schedule', {
  schedule: ScheduleExpression.cron({
    minute: '0',
    hour: '0',
  }),
  target: new targets.Universal({
    service: 'rds',
    action: 'stopDBCluster',
    input: ScheduleTargetInput.fromObject({
      DbClusterIdentifier: 'my-db',
    }),
  }),
});
python
Schedule(self, "Schedule",
    schedule=ScheduleExpression.cron(
        minute="0",
        hour="0"
    ),
    target=targets.Universal(
        service="rds",
        action="stopDBCluster",
        input=ScheduleTargetInput.from_object({
            "DbClusterIdentifier": "my-db"
        })
    )
)
java
Schedule.Builder.create(this, "Schedule")
        .schedule(ScheduleExpression.cron(CronOptionsWithTimezone.builder()
                .minute("0")
                .hour("0")
                .build()))
        .target(Universal.Builder.create()
                .service("rds")
                .action("stopDBCluster")
                .input(ScheduleTargetInput.fromObject(Map.of(
                        "DbClusterIdentifier", "my-db")))
                .build())
        .build();
csharp
new Schedule(this, "Schedule", new ScheduleProps {
    Schedule = ScheduleExpression.Cron(new CronOptionsWithTimezone {
        Minute = "0",
        Hour = "0"
    }),
    Target = new Universal(new UniversalTargetProps {
        Service = "rds",
        Action = "stopDBCluster",
        Input = ScheduleTargetInput.FromObject(new Dictionary<string, string> {
            { "DbClusterIdentifier", "my-db" }
        })
    })
});
go
awscdk.NewSchedule(this, jsii.String("Schedule"), &ScheduleProps{
	Schedule: awscdk.ScheduleExpression_Cron(&CronOptionsWithTimezone{
		Minute: jsii.String("0"),
		Hour: jsii.String("0"),
	}),
	Target: targets.NewUniversal(&UniversalTargetProps{
		Service: jsii.String("rds"),
		Action: jsii.String("stopDBCluster"),
		Input: awscdk.ScheduleTargetInput_FromObject(map[string]*string{
			"DbClusterIdentifier": jsii.String("my-db"),
		}),
	}),
})

The service must be in lowercase and the action must be in camelCase.

By default, an IAM policy for the Scheduler is extracted from the API call. The action in the policy is constructed using the service and action prop. Re-using the example above, the action will be rds:stopDBCluster. Note that not all IAM actions follow the same pattern. In such scenario, please use the policyStatements prop to override the policy:

ts
new Schedule(this, 'Schedule', {
  schedule: ScheduleExpression.rate(Duration.minutes(60)),
  target: new targets.Universal({
    service: 'sqs',
    action: 'sendMessage',
    policyStatements: [
      new iam.PolicyStatement({
        actions: ['sqs:SendMessage'],
        resources: ['arn:aws:sqs:us-east-1:123456789012:my_queue'],
      }),
      new iam.PolicyStatement({
        actions: ['kms:Decrypt', 'kms:GenerateDataKey*'],
        resources: ['arn:aws:kms:us-east-1:123456789012:key/0987dcba-09fe-87dc-65ba-ab0987654321'],
      }),
    ],
  }),
});
python
Schedule(self, "Schedule",
    schedule=ScheduleExpression.rate(Duration.minutes(60)),
    target=targets.Universal(
        service="sqs",
        action="sendMessage",
        policy_statements=[
            iam.PolicyStatement(
                actions=["sqs:SendMessage"],
                resources=["arn:aws:sqs:us-east-1:123456789012:my_queue"]
            ),
            iam.PolicyStatement(
                actions=["kms:Decrypt", "kms:GenerateDataKey*"],
                resources=["arn:aws:kms:us-east-1:123456789012:key/0987dcba-09fe-87dc-65ba-ab0987654321"]
            )
        ]
    )
)
java
Schedule.Builder.create(this, "Schedule")
        .schedule(ScheduleExpression.rate(Duration.minutes(60)))
        .target(Universal.Builder.create()
                .service("sqs")
                .action("sendMessage")
                .policyStatements(List.of(
                    PolicyStatement.Builder.create()
                            .actions(List.of("sqs:SendMessage"))
                            .resources(List.of("arn:aws:sqs:us-east-1:123456789012:my_queue"))
                            .build(),
                    PolicyStatement.Builder.create()
                            .actions(List.of("kms:Decrypt", "kms:GenerateDataKey*"))
                            .resources(List.of("arn:aws:kms:us-east-1:123456789012:key/0987dcba-09fe-87dc-65ba-ab0987654321"))
                            .build()))
                .build())
        .build();
csharp
new Schedule(this, "Schedule", new ScheduleProps {
    Schedule = ScheduleExpression.Rate(Duration.Minutes(60)),
    Target = new Universal(new UniversalTargetProps {
        Service = "sqs",
        Action = "sendMessage",
        PolicyStatements = new [] {
            new PolicyStatement(new PolicyStatementProps {
                Actions = new [] { "sqs:SendMessage" },
                Resources = new [] { "arn:aws:sqs:us-east-1:123456789012:my_queue" }
            }),
            new PolicyStatement(new PolicyStatementProps {
                Actions = new [] { "kms:Decrypt", "kms:GenerateDataKey*" },
                Resources = new [] { "arn:aws:kms:us-east-1:123456789012:key/0987dcba-09fe-87dc-65ba-ab0987654321" }
            }) }
    })
});
go
awscdk.NewSchedule(this, jsii.String("Schedule"), &ScheduleProps{
	Schedule: awscdk.ScheduleExpression_Rate(awscdk.Duration_Minutes(jsii.Number(60))),
	Target: targets.NewUniversal(&UniversalTargetProps{
		Service: jsii.String("sqs"),
		Action: jsii.String("sendMessage"),
		PolicyStatements: []PolicyStatement{
			iam.NewPolicyStatement(&PolicyStatementProps{
				Actions: []*string{
					jsii.String("sqs:SendMessage"),
				},
				Resources: []*string{
					jsii.String("arn:aws:sqs:us-east-1:123456789012:my_queue"),
				},
			}),
			iam.NewPolicyStatement(&PolicyStatementProps{
				Actions: []*string{
					jsii.String("kms:Decrypt"),
					jsii.String("kms:GenerateDataKey*"),
				},
				Resources: []*string{
					jsii.String("arn:aws:kms:us-east-1:123456789012:key/0987dcba-09fe-87dc-65ba-ab0987654321"),
				},
			}),
		},
	}),
})

Note: The default policy uses * in the resources field as CDK does not have a straight forward way to auto-discover the resources permission required. It is recommended that you scope the field down to specific resources to have a better security posture.

Types ​

NameKindSummary
CodeBuildStartBuildClassUse an AWS CodeBuild as a target for AWS EventBridge Scheduler.
CodePipelineStartPipelineExecutionClassUse an AWS CodePipeline pipeline as a target for AWS EventBridge Scheduler.
Ec2TaskPropsStructProperties for scheduling an ECS Task on EC2.
EcsRunEc2TaskClassSchedule an ECS Task on EC2 using AWS EventBridge Scheduler.
EcsRunFargateTaskClassSchedule an ECS Task on Fargate using AWS EventBridge Scheduler.
EcsRunTaskClassSchedule an ECS Task using AWS EventBridge Scheduler.
EcsRunTaskBasePropsStructParameters for scheduling ECS Run Task (common to EC2 and Fargate launch types).
EventBridgePutEventsClassSend an event to an AWS EventBridge by AWS EventBridge Scheduler.
EventBridgePutEventsEntryStructAn entry to be sent to EventBridge.
FargateTaskPropsStructProperties for scheduling an ECS Fargate Task.
FirehosePutRecordClassUse an Amazon Data Firehose as a target for AWS EventBridge Scheduler.
InspectorStartAssessmentRunClassUse an Amazon Inspector as a target for AWS EventBridge Scheduler.
KinesisStreamPutRecordClassUse an Amazon Kinesis Data Streams as a target for AWS EventBridge Scheduler.
KinesisStreamPutRecordPropsStructProperties for a Kinesis Data Streams Target.
LambdaInvokeClassUse an AWS Lambda function as a target for AWS EventBridge Scheduler.
SageMakerPipelineParameterStructProperties for a pipeline parameter.
SageMakerStartPipelineExecutionClassUse a SageMaker pipeline as a target for AWS EventBridge Scheduler.
SageMakerStartPipelineExecutionPropsStructProperties for a SageMaker Target.
ScheduleTargetBaseClassBase class for Schedule Targets.
ScheduleTargetBasePropsStructBase properties for a Schedule Target.
SnsPublishClassUse an Amazon SNS topic as a target for AWS EventBridge Scheduler.
SqsSendMessageClassUse an Amazon SQS Queue as a target for AWS EventBridge Scheduler.
SqsSendMessagePropsStructProperties for a SQS Queue Target.
StepFunctionsStartExecutionClassUse an AWS Step function as a target for AWS EventBridge Scheduler.
TagStructMetadata that you apply to a resource to help categorize and organize the resource.
UniversalClassUse a wider set of AWS API as a target for AWS EventBridge Scheduler.
UniversalTargetPropsStructProperties for a Universal Target.