Schedule

class aws_cdk.aws_events.Schedule

Bases: object

Schedule for scheduled event rules.

Note that rates cannot be defined in fractions of minutes.

See:

https://docs.aws.amazon.com/eventbridge/latest/userguide/scheduled-events.html

ExampleMetadata:

infused

Example:

import aws_cdk.aws_ecs as ecs

# cluster: ecs.ICluster
# task_definition: ecs.TaskDefinition


rule = events.Rule(self, "Rule",
    schedule=events.Schedule.rate(cdk.Duration.hours(1))
)

rule.add_target(targets.EcsTask(
    cluster=cluster,
    task_definition=task_definition,
    task_count=1,
    container_overrides=[targets.ContainerOverride(
        container_name="TheContainer",
        command=["echo", events.EventField.from_path("$.detail.event")]
    )],
    enable_execute_command=True
))

Attributes

expression_string

Retrieve the expression for this schedule.

Static Methods

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

Create a 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: - Any day of the week

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

Return type:

Schedule

classmethod expression(expression)

Construct a schedule from a literal schedule expression.

Parameters:

expression (str) – The expression to use. Must be in a format that EventBridge will recognize

Return type:

Schedule

classmethod rate(duration)

Construct a schedule from an interval and a time unit.

Rates may be defined with any unit of time, but when converted into minutes, the duration must be a positive whole number of minutes.

Parameters:

duration (Duration) –

Return type:

Schedule