Schedule

class aws_cdk.aws_stepfunctions_tasks.Schedule(*args: Any, **kwargs)

Bases: object

Schedule for EventBridge Scheduler.

ExampleMetadata:

infused

Example:

import aws_cdk.aws_scheduler as scheduler
import aws_cdk.aws_kms as kms

# key: kms.Key
# schedule_group: scheduler.CfnScheduleGroup
# target_queue: sqs.Queue
# dead_letter_queue: sqs.Queue


scheduler_role = iam.Role(self, "SchedulerRole",
    assumed_by=iam.ServicePrincipal("scheduler.amazonaws.com")
)
# To send the message to the queue
# This policy changes depending on the type of target.
scheduler_role.add_to_principal_policy(iam.PolicyStatement(
    actions=["sqs:SendMessage"],
    resources=[target_queue.queue_arn]
))

create_schedule_task1 = tasks.EventBridgeSchedulerCreateScheduleTask(self, "createSchedule",
    schedule_name="TestSchedule",
    action_after_completion=tasks.ActionAfterCompletion.NONE,
    client_token="testToken",
    description="TestDescription",
    start_date=Date(),
    end_date=Date(Date().get_time() + 1000 * 60 * 60),
    flexible_time_window=Duration.minutes(5),
    group_name=schedule_group.ref,
    kms_key=key,
    schedule=tasks.Schedule.rate(Duration.minutes(5)),
    timezone="UTC",
    enabled=True,
    target=tasks.EventBridgeSchedulerTarget(
        arn=target_queue.queue_arn,
        role=scheduler_role,
        retry_policy=tasks.RetryPolicy(
            maximum_retry_attempts=2,
            maximum_event_age=Duration.minutes(5)
        ),
        dead_letter_queue=dead_letter_queue
    )
)

Attributes

expression_string

The Schedule expression.

Static Methods

classmethod cron(*, day=None, hour=None, minute=None, month=None, week_day=None, year=None)

Create a cron-based schedule from a set of cron fields.

Parameters:
  • day (Optional[str]) – The day of the month to run this rule at. Default: - Every day of the month

  • hour (Optional[str]) – The hour to run this rule at. Default: - Every hour

  • minute (Optional[str]) – The minute to run this rule at. Default: - Every minute

  • month (Optional[str]) – The month to run this rule at. Default: - Every month

  • week_day (Optional[str]) – The day of the week to run this rule at. Default: - Whichever day of the week that day falls on

  • year (Optional[str]) – The year to run this rule at. Default: - Every year

Return type:

Schedule

classmethod one_time(time)

Construct a one-time schedule from a Date.

Parameters:

time (datetime) –

Return type:

Schedule

classmethod rate(duration)

Construct a rate-based schedule from an interval.

The minimum interval is 1 minute.

Parameters:

duration (Duration) –

Return type:

Schedule