I do not clearly understand the compatability/limitations of utilizing both schedule
and eventPattern
in Eventbridge Rules of the AWS CDK (Typescript).
In fact, I know that @Chris Doyle in this post believes them to be mutually exclusive / some form of antipattern.
Yet, when I deploy an Eventbridge Rule of the form:
const eventRule = new eventCDK.Rule(this, "scheduledEventID", {
eventPattern: {detail: {"neatProperty": "myEventProp"}},
schedule: eventCDK.Schedule.cron({
minute: "30",
hour: "*",
weekDay: "1-7",
month: "*"
})
})
I succeed without any error. Upon selecting the created Rule in the AWS console, however, I receive the prompt
Rule scheduledEventID has both event pattern and schedule configured, which is not compatible with Console currently. If you update this rule from Console, only one of them can be kept, do you still want to continue?
Regarding the schedule
property, the documentation clearly states that
You must specify this property, the eventPattern property, or both.
In conclusion, is this behavior unexpected, e.g. should I not be able to specify both in CDK or am I missing a part of the documentation that defines the compatability between these two properties?
Per EventBridge PutRule documentation you are allowed to create a rule that has both kinds of triggers and both would work:
A rule must contain at least an EventPattern or ScheduleExpression. Rules with EventPatterns are triggered when a matching event is observed. Rules with ScheduleExpressions self-trigger based on the given schedule. A rule can have both an EventPattern and a ScheduleExpression, in which case the rule triggers on matching events as well as on a schedule.
This is something that's, as you mentioned, still not allowed through Console and I honestly doubt that it will ever be added there. It makes more sense to create 2 separate rules, one for event pattern and the other for schedule. It's cleaner that way.
Also, this is not the only inconsistency between Console and other AWS options, like CLI and SDK. There are more situations where you can do certain things through the CLI or SDK, but not through the Console, so this is not so uncommon as you might think.