Skip to content

Commit

Permalink
feat(scheduler): ScheduleGroup (#26196)
Browse files Browse the repository at this point in the history
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*
  • Loading branch information
filletofish committed Jul 24, 2023
1 parent 6bd9a2d commit 27dc8ff
Show file tree
Hide file tree
Showing 7 changed files with 725 additions and 7 deletions.
53 changes: 51 additions & 2 deletions packages/@aws-cdk/aws-scheduler-alpha/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ TODO: Schedule is not yet fully implemented. See section in [L2 Event Bridge Sch
Only an L2 class is created that wraps the L1 class and handles the following properties:

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

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

### Grouping Schedules

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)
Your AWS account comes with a default scheduler group. You can access default group in CDK with:

```text
const defaultGroup = Group.fromDefaultGroup(this, "DefaultGroup");
```

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:

```text
const group = new Group(this, "Group", {
groupName: "MyGroup",
});
const target = new targets.LambdaInvoke(props.func, {
input: ScheduleTargetInput.fromObject({
"payload": "useful",
}),
});
new Schedule(this, 'Schedule', {
scheduleExpression: ScheduleExpression.rate(Duration.minutes(10)),
target,
group,
});
```

## Scheduler Targets

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

### Metrics for a Group

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)
To view metrics for a specific group you can use methods on class `Group`:

```ts
const group = new Group(this, "Group", {
groupName: "MyGroup",
});

new cloudwatch.Alarm(this, 'MyGroupErrorAlarm', {
metric: group.metricTargetErrors(),
evaluationPeriods: 1,
threshold: 0
});

// Or use default group
const defaultGroup = Group.fromDefaultGroup(this, "DefaultGroup");
new cloudwatch.Alarm(this, 'DefaultGroupErrorAlarm', {
metric: defaultGroup.metricTargetErrors(),
evaluationPeriods: 1,
threshold: 0
});
```

See full list of metrics and their description at
[Monitoring Using CloudWatch Metrics](https://docs.aws.amazon.com/scheduler/latest/UserGuide/monitoring-cloudwatch.html)
in the *AWS Event Bridge Scheduler User Guide*.

0 comments on commit 27dc8ff

Please sign in to comment.