Skip to content

Commit

Permalink
fix(scheduler-alpha): deprecate Group in favour of ScheduleGroup (#…
Browse files Browse the repository at this point in the history
…33678)

### Issue # (if applicable)

n/a

### Reason for this change

The `awslint` rules enforce naming to be consistent with CloudFormation resources. In this case, the CFN resource is `AWS::Scheduler::ScheduleGroup` but the construct was named `Group` when it should be `ScheduleGroup`.

When this module is stabilized, `Group` will be completely removed.

### Description of changes

- Mark `Group` and related methods as deprecated. Deprecation 
- Introduce new class `ScheduleGroup` (duplicate of Group, just renamed)
- Addressed most `awslint` exemptions in the module
- Update any logic referencing `group` to reference `scheduleGroup`
- Updated README examples

### Describe any new or updated permissions being added

n/a

### Description of how you validated changes

Updated unit tests

### Checklist
- [x] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md)

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
gracelu0 authored Mar 5, 2025
1 parent 4bc151b commit 4d8eae9
Show file tree
Hide file tree
Showing 12 changed files with 826 additions and 58 deletions.
24 changes: 12 additions & 12 deletions packages/@aws-cdk/aws-scheduler-alpha/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,22 +100,22 @@ const oneTimeSchedule = new Schedule(this, 'Schedule', {
Your AWS account comes with a default scheduler group. You can access the default group in CDK with:

```ts
const defaultGroup = Group.fromDefaultGroup(this, "DefaultGroup");
const defaultScheduleGroup = ScheduleGroup.fromDefaultScheduleGroup(this, "DefaultGroup");
```

You can add a schedule to a custom scheduling group managed by you. If a custom group is not specified, the schedule is added to the default group.

```ts
declare const target: targets.LambdaInvoke;

const group = new Group(this, "Group", {
groupName: "MyGroup",
const scheduleGroup = new ScheduleGroup(this, "ScheduleGroup", {
scheduleGroupName: "MyScheduleGroup",
});

new Schedule(this, 'Schedule', {
schedule: ScheduleExpression.rate(Duration.minutes(10)),
target,
group,
scheduleGroup,
});
```

Expand Down Expand Up @@ -300,25 +300,25 @@ new cloudwatch.Alarm(this, 'SchedulesErrorAlarm', {
});
```

### Metrics for a Group
### Metrics for a Schedule Group

To view metrics for a specific group you can use methods on class `Group`:
To view metrics for a specific group you can use methods on class `ScheduleGroup`:

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

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

// Or use default group
const defaultGroup = Group.fromDefaultGroup(this, "DefaultGroup");
new cloudwatch.Alarm(this, 'DefaultGroupErrorAlarm', {
metric: defaultGroup.metricTargetErrors(),
const defaultScheduleGroup = ScheduleGroup.fromDefaultScheduleGroup(this, "DefaultScheduleGroup");
new cloudwatch.Alarm(this, 'DefaultScheduleGroupErrorAlarm', {
metric: defaultScheduleGroup.metricTargetErrors(),
evaluationPeriods: 1,
threshold: 0
});
Expand Down
17 changes: 2 additions & 15 deletions packages/@aws-cdk/aws-scheduler-alpha/awslint.json
Original file line number Diff line number Diff line change
@@ -1,23 +1,10 @@
{
"exclude": [
"construct-ctor-props-optional:@aws-cdk/aws-scheduler-alpha.Group",
"props-physical-name:@aws-cdk/aws-scheduler-alpha.GroupProps",
"from-method:@aws-cdk/aws-scheduler-alpha.Schedule",
"attribute-tag:@aws-cdk/aws-scheduler-alpha.Schedule.scheduleArn",
"attribute-tag:@aws-cdk/aws-scheduler-alpha.Schedule.scheduleName",
"attribute-tag:@aws-cdk/aws-scheduler-alpha.Schedule.scheduleGroup",
"docs-public-apis:@aws-cdk/aws-scheduler-alpha.ContextAttribute.name",
"docs-public-apis:@aws-cdk/aws-scheduler-alpha.Group",
"docs-public-apis:@aws-cdk/aws-scheduler-alpha.GroupProps",
"docs-public-apis:@aws-cdk/aws-scheduler-alpha.IGroup",
"props-default-doc:@aws-cdk/aws-scheduler-alpha.ScheduleProps.targetOverrides",
"props-default-doc:@aws-cdk/aws-scheduler-alpha.ScheduleTargetConfig.deadLetterConfig",
"props-default-doc:@aws-cdk/aws-scheduler-alpha.ScheduleTargetConfig.ecsParameters",
"props-default-doc:@aws-cdk/aws-scheduler-alpha.ScheduleTargetConfig.eventBridgeParameters",
"props-default-doc:@aws-cdk/aws-scheduler-alpha.ScheduleTargetConfig.input",
"props-default-doc:@aws-cdk/aws-scheduler-alpha.ScheduleTargetConfig.kinesisParameters",
"props-default-doc:@aws-cdk/aws-scheduler-alpha.ScheduleTargetConfig.retryPolicy",
"props-default-doc:@aws-cdk/aws-scheduler-alpha.ScheduleTargetConfig.sageMakerPipelineParameters",
"props-default-doc:@aws-cdk/aws-scheduler-alpha.ScheduleTargetConfig.sqsParameters",
"docs-public-apis:@aws-cdk/aws-scheduler-alpha.ScheduleTargetProps"
"docs-public-apis:@aws-cdk/aws-scheduler-alpha.IGroup"
]
}
10 changes: 7 additions & 3 deletions packages/@aws-cdk/aws-scheduler-alpha/lib/group.ts
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,7 @@ abstract class GroupBase extends Resource implements IGroup {
}
/**
* @resource AWS::Scheduler::ScheduleGroup
* @deprecated Use `ScheduleGroup` instead. `Group` will be removed when this module is stabilized.
*/
export class Group extends GroupBase {
/**
Expand All @@ -298,6 +299,7 @@ export class Group extends GroupBase {
* @param scope construct scope
* @param id construct id
* @param groupArn the ARN of the group to import (e.g. `arn:aws:scheduler:region:account-id:schedule-group/group-name`)
* @deprecated Use `ScheduleGroup.fromScheduleGroupArn()` instead.
*/
public static fromGroupArn(scope: Construct, id: string, groupArn: string): IGroup {
const arnComponents = Stack.of(scope).splitArn(groupArn, ArnFormat.SLASH_RESOURCE_NAME);
Expand All @@ -314,6 +316,7 @@ export class Group extends GroupBase {
*
* @param scope construct scope
* @param id construct id
* @deprecated Use `ScheduleGroup.fromDefaultScheduleGroup()` instead.
*/
public static fromDefaultGroup(scope: Construct, id: string): IGroup {
return Group.fromGroupName(scope, id, 'default');
Expand All @@ -325,6 +328,7 @@ export class Group extends GroupBase {
* @param scope construct scope
* @param id construct id
* @param groupName the name of the existing group to import
* @deprecated Use `ScheduleGroup.fromScheduleGroupName()` instead.
*/
public static fromGroupName(scope: Construct, id: string, groupName: string): IGroup {
const groupArn = Stack.of(scope).formatArn({
Expand All @@ -338,12 +342,12 @@ export class Group extends GroupBase {
public readonly groupName: string;
public readonly groupArn: string;

public constructor(scope: Construct, id: string, props: GroupProps) {
public constructor(scope: Construct, id: string, props?: GroupProps) {
super(scope, id);
// Enhanced CDK Analytics Telemetry
addConstructMetadata(this, props);

this.groupName = props.groupName ?? Names.uniqueResourceName(this, {
this.groupName = props?.groupName ?? Names.uniqueResourceName(this, {
maxLength: 64,
separator: '-',
});
Expand All @@ -352,7 +356,7 @@ export class Group extends GroupBase {
name: this.groupName,
});

group.applyRemovalPolicy(props.removalPolicy);
group.applyRemovalPolicy(props?.removalPolicy);

this.groupArn = this.getResourceArnAttribute(group.attrArn, {
service: 'scheduler',
Expand Down
1 change: 1 addition & 0 deletions packages/@aws-cdk/aws-scheduler-alpha/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ export * from './input';
export * from './schedule';
export * from './group';
export * from './target';
export * from './schedule-group';
Loading

0 comments on commit 4d8eae9

Please sign in to comment.