Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(scheduler-alpha): deprecate Group in favour of ScheduleGroup #33678

Merged
merged 7 commits into from
Mar 5, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
deprecate schedule group
  • Loading branch information
gracelu0 committed Mar 3, 2025
commit dff6a4040a334c5a12a8cb52bf41efe2b8ca1fb5
24 changes: 12 additions & 12 deletions packages/@aws-cdk/aws-scheduler-alpha/README.md
Original file line number Diff line number Diff line change
@@ -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,
});
```

@@ -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.fromDefaulScheduleGroup(this, "DefaultScheduleGroup");
new cloudwatch.Alarm(this, 'DefaultScheduleGroupErrorAlarm', {
metric: defaultScheduleGroup.metricTargetErrors(),
evaluationPeriods: 1,
threshold: 0
});
6 changes: 4 additions & 2 deletions packages/@aws-cdk/aws-scheduler-alpha/lib/group.ts
Original file line number Diff line number Diff line change
@@ -290,7 +290,7 @@ abstract class GroupBase extends Resource implements IGroup {
}
/**
* @resource AWS::Scheduler::ScheduleGroup
* @deprecated Use `ScheduleGroup` instead.
* @deprecated Use `ScheduleGroup` instead. `Group` will be removed when this module is stabilized.
*/
export class Group extends GroupBase {
/**
@@ -299,7 +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
* @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);
@@ -316,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');
@@ -327,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({
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
@@ -3,3 +3,4 @@ export * from './input';
export * from './schedule';
export * from './group';
export * from './target';
export * from './schedule-group';
Original file line number Diff line number Diff line change
@@ -315,7 +315,7 @@ export class ScheduleGroup extends ScheduleGroupBase {
* @param scope construct scope
* @param id construct id
*/
public static fromDefaultGroup(scope: Construct, id: string): IScheduleGroup {
public static fromDefaultScheduleGroup(scope: Construct, id: string): IScheduleGroup {
return ScheduleGroup.fromScheduleGroupName(scope, id, 'default');
}

22 changes: 22 additions & 0 deletions packages/@aws-cdk/aws-scheduler-alpha/lib/schedule.ts
Original file line number Diff line number Diff line change
@@ -7,6 +7,7 @@ import { Construct } from 'constructs';
import { IGroup } from './group';
import { ScheduleExpression } from './schedule-expression';
import { IScheduleTarget } from './target';
import { IScheduleGroup } from './schedule-group';

/**
* Interface representing a created or an imported `Schedule`.
@@ -19,9 +20,15 @@ export interface ISchedule extends IResource {

/**
* The schedule group associated with this schedule.
* @deprecated Use `scheduleGroup` instead. `group` will be removed when this module is stabilized.
*/
readonly group?: IGroup;

/**
* The schedule group associated with this schedule.
*/
readonly scheduleGroup?: IScheduleGroup;

/**
* The arn of the schedule.
*/
@@ -104,9 +111,17 @@ export interface ScheduleProps {
* The schedule's group.
*
* @default - By default a schedule will be associated with the `default` group.
* @deprecated Use `scheduleGroup` instead. `group` will be removed when this module is stabilized.
*/
readonly group?: IGroup;

/**
* The schedule's group.
*
* @default - By default a schedule will be associated with the `default` group.
*/
readonly scheduleGroup?: IScheduleGroup;

/**
* Indicates whether the schedule is enabled.
*
@@ -246,9 +261,15 @@ export class Schedule extends Resource implements ISchedule {

/**
* The schedule group associated with this schedule.
* @deprecated Use `scheduleGroup` instead. `group` will be removed when this module is stabilized.
*/
public readonly group?: IGroup;

/**
* The schedule group associated with this schedule.
*/
public readonly scheduleGroup?: IScheduleGroup;

/**
* The arn of the schedule.
*/
@@ -277,6 +298,7 @@ export class Schedule extends Resource implements ISchedule {
addConstructMetadata(this, props);

this.group = props.group;
this.scheduleGroup = props.scheduleGroup;

const targetConfig = props.target.bind(this);

26 changes: 13 additions & 13 deletions packages/@aws-cdk/aws-scheduler-alpha/test/group.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { testDeprecated } from '@aws-cdk/cdk-build-tools';
import { App, Duration, RemovalPolicy, Stack } from 'aws-cdk-lib';
import { Match, Template } from 'aws-cdk-lib/assertions';
import * as cw from 'aws-cdk-lib/aws-cloudwatch';
@@ -7,7 +8,6 @@ import { CfnScheduleGroup } from 'aws-cdk-lib/aws-scheduler';
import { IScheduleTarget, ScheduleExpression, ScheduleTargetConfig } from '../lib';
import { Group, GroupProps } from '../lib/group';
import { Schedule } from '../lib/schedule';

class SomeLambdaTarget implements IScheduleTarget {
public constructor(private readonly fn: lambda.IFunction, private readonly role: iam.IRole) {
}
@@ -36,7 +36,7 @@ describe('Schedule Group', () => {
});
});

test('creates a group with default properties', () => {
testDeprecated('creates a group with default properties', () => {
const props: GroupProps = {};
const group = new Group(stack, 'TestGroup', props);

@@ -49,7 +49,7 @@ describe('Schedule Group', () => {
expect(resource.name).toEqual(group.groupName);
});

test('creates a group with removal policy', () => {
testDeprecated('creates a group with removal policy', () => {
const props: GroupProps = {
removalPolicy: RemovalPolicy.RETAIN,
};
@@ -60,7 +60,7 @@ describe('Schedule Group', () => {
});
});

test('creates a group with specified name', () => {
testDeprecated('creates a group with specified name', () => {
const props: GroupProps = {
groupName: 'MyGroup',
};
@@ -76,7 +76,7 @@ describe('Schedule Group', () => {
});
});

test('creates a group from ARN', () => {
testDeprecated('creates a group from ARN', () => {
const groupArn = 'arn:aws:scheduler:region:account-id:schedule-group/group-name';
const group = Group.fromGroupArn(stack, 'TestGroup', groupArn);

@@ -87,7 +87,7 @@ describe('Schedule Group', () => {
expect(groups).toEqual({});
});

test('creates a group from name', () => {
testDeprecated('creates a group from name', () => {
const groupName = 'MyGroup';
const group = Group.fromGroupName(stack, 'TestGroup', groupName);

@@ -98,7 +98,7 @@ describe('Schedule Group', () => {
expect(groups).toEqual({});
});

test('creates a group from default group', () => {
testDeprecated('creates a group from default group', () => {
const group = Group.fromDefaultGroup(stack, 'DefaultGroup');

expect(group.groupArn).toBeDefined();
@@ -108,7 +108,7 @@ describe('Schedule Group', () => {
expect(groups).toEqual({});
});

test('adds schedules to the group', () => {
testDeprecated('adds schedules to the group', () => {
const props: GroupProps = {
groupName: 'MyGroup',
};
@@ -136,7 +136,7 @@ describe('Schedule Group', () => {
});
});

test('adds schedules to the group with unspecified name', () => {
testDeprecated('adds schedules to the group with unspecified name', () => {
const group = new Group(stack, 'TestGroup', {});
const role = iam.Role.fromRoleArn(stack, 'ImportedRole', 'arn:aws:iam::123456789012:role/someRole');

@@ -161,7 +161,7 @@ describe('Schedule Group', () => {
});
});

test('grantReadSchedules', () => {
testDeprecated('grantReadSchedules', () => {
// GIVEN
const props: GroupProps = {
groupName: 'MyGroup',
@@ -201,7 +201,7 @@ describe('Schedule Group', () => {
});
});

test('grantWriteSchedules', () => {
testDeprecated('grantWriteSchedules', () => {
// GIVEN
const props: GroupProps = {
groupName: 'MyGroup',
@@ -242,7 +242,7 @@ describe('Schedule Group', () => {
});
});

test('grantDeleteSchedules', () => {
testDeprecated('grantDeleteSchedules', () => {
// GIVEN
const props: GroupProps = {
groupName: 'MyGroup',
@@ -324,7 +324,7 @@ describe('Schedule Group Metrics', () => {
});
});

test('Invocations Failed to Deliver to DLQ Metrics', () => {
testDeprecated('Invocations Failed to Deliver to DLQ Metrics', () => {
// GIVEN
const app = new App();
const props: GroupProps = {
Loading
Oops, something went wrong.