Skip to content

Commit 27dc8ff

Browse files
authored
feat(scheduler): ScheduleGroup (#26196)
This PR contains implementation of ScheduleGroup. A Schedule is the main resource in Amazon EventBridge Scheduler, this PR adds ScheduleGroup which can be used to group Schedules and on which Schedule depends. Every AWS account comes with a default group for schedules. Customers can also create a custom groups to organise schedules that share a common purpose or belong to the same environment. Schedule has a property `group` that determines what group is the schedule associated with. To be able to test adding schedules to the group I have added property `group` to private class `Schedule` and used `Lazy` functionality to be able to update `group` of the schedule dynamically. Implementation is based on RFC: https://github.com/aws/aws-cdk-rfcs/blob/master/text/0474-event-bridge-scheduler-l2.md Advances #23394 ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent 6bd9a2d commit 27dc8ff

File tree

7 files changed

+725
-7
lines changed

7 files changed

+725
-7
lines changed

packages/@aws-cdk/aws-scheduler-alpha/README.md

+51-2
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ TODO: Schedule is not yet fully implemented. See section in [L2 Event Bridge Sch
4444
Only an L2 class is created that wraps the L1 class and handles the following properties:
4545

4646
- schedule
47+
- schedule group
4748
- target (only LambdaInvoke is supported for now)
4849
- flexibleTimeWindow will be set to `{ mode: 'OFF' }`
4950

@@ -97,7 +98,31 @@ const oneTimeSchedule = new Schedule(this, 'Schedule', {
9798

9899
### Grouping Schedules
99100

100-
TODO: Group is not yet implemented. See section in [L2 Event Bridge Scheduler RFC](https://github.com/aws/aws-cdk-rfcs/blob/master/text/0474-event-bridge-scheduler-l2.md)
101+
Your AWS account comes with a default scheduler group. You can access default group in CDK with:
102+
103+
```text
104+
const defaultGroup = Group.fromDefaultGroup(this, "DefaultGroup");
105+
```
106+
107+
If not specified a schedule is added to the default group. However, you can also add the schedule to a custom scheduling group managed by you:
108+
109+
```text
110+
const group = new Group(this, "Group", {
111+
groupName: "MyGroup",
112+
});
113+
114+
const target = new targets.LambdaInvoke(props.func, {
115+
input: ScheduleTargetInput.fromObject({
116+
"payload": "useful",
117+
}),
118+
});
119+
120+
new Schedule(this, 'Schedule', {
121+
scheduleExpression: ScheduleExpression.rate(Duration.minutes(10)),
122+
target,
123+
group,
124+
});
125+
```
101126

102127
## Scheduler Targets
103128

@@ -164,4 +189,28 @@ TODO: Not yet implemented. See section in [L2 Event Bridge Scheduler RFC](https:
164189

165190
### Metrics for a Group
166191

167-
TODO: Not yet implemented. See section in [L2 Event Bridge Scheduler RFC](https://github.com/aws/aws-cdk-rfcs/blob/master/text/0474-event-bridge-scheduler-l2.md)
192+
To view metrics for a specific group you can use methods on class `Group`:
193+
194+
```ts
195+
const group = new Group(this, "Group", {
196+
groupName: "MyGroup",
197+
});
198+
199+
new cloudwatch.Alarm(this, 'MyGroupErrorAlarm', {
200+
metric: group.metricTargetErrors(),
201+
evaluationPeriods: 1,
202+
threshold: 0
203+
});
204+
205+
// Or use default group
206+
const defaultGroup = Group.fromDefaultGroup(this, "DefaultGroup");
207+
new cloudwatch.Alarm(this, 'DefaultGroupErrorAlarm', {
208+
metric: defaultGroup.metricTargetErrors(),
209+
evaluationPeriods: 1,
210+
threshold: 0
211+
});
212+
```
213+
214+
See full list of metrics and their description at
215+
[Monitoring Using CloudWatch Metrics](https://docs.aws.amazon.com/scheduler/latest/UserGuide/monitoring-cloudwatch.html)
216+
in the *AWS Event Bridge Scheduler User Guide*.

0 commit comments

Comments
 (0)