Skip to content
v2.274.0

Schedule Class ​

Schedule for EventBridge Scheduler.

Example ​

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

declare const key: kms.Key;
declare const scheduleGroup: scheduler.CfnScheduleGroup;
declare const targetQueue: sqs.Queue;
declare const deadLetterQueue: sqs.Queue;

const schedulerRole = new iam.Role(this, 'SchedulerRole', {
  assumedBy: new iam.ServicePrincipal('scheduler.amazonaws.com'),
});
// To send the message to the queue
// This policy changes depending on the type of target.
schedulerRole.addToPrincipalPolicy(new iam.PolicyStatement({
  actions: ['sqs:SendMessage'],
  resources: [targetQueue.queueArn],
}));

const createScheduleTask1 = new tasks.EventBridgeSchedulerCreateScheduleTask(this, 'createSchedule', {
  scheduleName: 'TestSchedule',
  actionAfterCompletion: tasks.ActionAfterCompletion.NONE,
  clientToken: 'testToken',
  description: 'TestDescription',
  startDate: new Date(),
  endDate: new Date(new Date().getTime() + 1000 * 60 * 60),
  flexibleTimeWindow: Duration.minutes(5),
  groupName: scheduleGroup.ref,
  kmsKey: key,
  schedule: tasks.Schedule.rate(Duration.minutes(5)),
  timezone: 'UTC',
  enabled: true,
  target: new tasks.EventBridgeSchedulerTarget({
    arn: targetQueue.queueArn,
    role: schedulerRole,
    retryPolicy: {
      maximumRetryAttempts: 2,
      maximumEventAge: Duration.minutes(5),
    },
    deadLetterQueue,
  }),
});

Properties ​

expressionStringstringexpression_stringstrexpressionStringStringExpressionStringstringExpressionString*stringrequired#
The Schedule expression.

Methods ​

cron(options: CronOptions): Schedule // chainable@staticmethod def cron(options: CronOptions) -> Schedulepublic static Schedule cron(CronOptions options)public static Schedule Cron(CronOptions options)func Cron(Options CronOptions) Schedulestatic#
Create a cron-based schedule from a set of cron fields.
oneTime(time: date): Schedule // chainable@staticmethod def one_time(time: datetime) -> Schedulepublic static Schedule oneTime(Instant time)public static Schedule OneTime(DateTime time)func OneTime(Time *time.Time) Schedulestatic#
Construct a one-time schedule from a Date.
rate(duration: Duration): Schedule // chainable@staticmethod def rate(duration: Duration) -> Schedulepublic static Schedule rate(Duration duration)public static Schedule Rate(Duration duration)func Rate(Duration Duration) Schedulestatic#
Construct a rate-based schedule from an interval.

The minimum interval is 1 minute.