CronOptions Struct
Options to configure a cron expression.
All fields are strings so you can use complex expressions. Absence of a field implies '*' or '?', whichever one is appropriate.
Example
ts
import * as events from 'aws-cdk-lib/aws-events';
import * as targets from 'aws-cdk-lib/aws-events-targets';
declare const fn: lambda.Function;
const rule = new events.Rule(this, 'Schedule Rule', {
schedule: events.Schedule.cron({ minute: '0', hour: '4' }),
});
rule.addTarget(new targets.LambdaFunction(fn));
python
import aws_cdk.aws_events as events
import aws_cdk.aws_events_targets as targets
# fn: lambda.Function
rule = events.Rule(self, "Schedule Rule",
schedule=events.Schedule.cron(minute="0", hour="4")
)
rule.add_target(targets.LambdaFunction(fn))
java
import software.amazon.awscdk.services.events.*;
import software.amazon.awscdk.services.events.targets.*;
Function fn;
Rule rule = Rule.Builder.create(this, "Schedule Rule")
.schedule(Schedule.cron(CronOptions.builder().minute("0").hour("4").build()))
.build();
rule.addTarget(new LambdaFunction(fn));
csharp
// Install: dotnet add package Amazon.CDK.Lib
using Amazon.CDK.AWS.Events;
using Amazon.CDK.AWS.Events.Targets;
Function fn;
var rule = new Rule(this, "Schedule Rule", new RuleProps {
Schedule = Schedule.Cron(new CronOptions { Minute = "0", Hour = "4" })
});
rule.AddTarget(new LambdaFunction(fn));
go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
import "github.com/aws/aws-cdk-go/awscdk"
import targets "github.com/aws/aws-cdk-go/awscdk"
var fn Function
rule := events.NewRule(this, jsii.String("Schedule Rule"), &RuleProps{
Schedule: events.Schedule_Cron(&CronOptions{
Minute: jsii.String("0"),
Hour: jsii.String("4"),
}),
})
rule.AddTarget(targets.NewLambdaFunction(fn))
Properties
The day of the month to run this rule at.
Default: Every day of the month
The hour to run this rule at.
Default: Every hour
The minute to run this rule at.
Default: Every minute
The month to run this rule at.
Default: Every month
weekDayoptionalstringweek_dayoptionalstrweekDayoptionalStringWeekDayoptionalstringWeekDayoptional*string#The day of the week to run this rule at.
Default: Any day of the week
The year to run this rule at.
Default: Every year