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
fix awslint
  • Loading branch information
gracelu0 committed Mar 3, 2025
commit bbfa11a55308065bb6e62983b4b9be8a15209466
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",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added this exemption as scheduleGroup is not an attribute of Schedule

"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"
]
}
6 changes: 3 additions & 3 deletions packages/@aws-cdk/aws-scheduler-alpha/lib/group.ts
Original file line number Diff line number Diff line change
@@ -342,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: '-',
});
@@ -356,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',
14 changes: 11 additions & 3 deletions packages/@aws-cdk/aws-scheduler-alpha/lib/schedule-group.ts
Original file line number Diff line number Diff line change
@@ -5,6 +5,9 @@ import { Arn, ArnFormat, Aws, IResource, Names, RemovalPolicy, Resource, Stack }
import { addConstructMetadata } from 'aws-cdk-lib/core/lib/metadata-resource';
import { Construct } from 'constructs';

/**
* Properties for a Schedule Group.
*/
export interface ScheduleGroupProps {
/**
* The name of the schedule group.
@@ -23,6 +26,9 @@ export interface ScheduleGroupProps {
readonly removalPolicy?: RemovalPolicy;
}

/**
* Interface representing a created or an imported `ScheduleGroup`.
*/
export interface IScheduleGroup extends IResource {
/**
* The name of the schedule group
@@ -288,7 +294,9 @@ abstract class ScheduleGroupBase extends Resource implements IScheduleGroup {
});
}
}

/**
* A Schedule Group.
* @resource AWS::Scheduler::ScheduleGroup
*/
export class ScheduleGroup extends ScheduleGroupBase {
@@ -338,12 +346,12 @@ export class ScheduleGroup extends ScheduleGroupBase {
public readonly scheduleGroupName: string;
public readonly scheduleGroupArn: string;

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

this.scheduleGroupName = props.scheduleGroupName ?? Names.uniqueResourceName(this, {
this.scheduleGroupName = props?.scheduleGroupName ?? Names.uniqueResourceName(this, {
maxLength: 64,
separator: '-',
});
@@ -352,7 +360,7 @@ export class ScheduleGroup extends ScheduleGroupBase {
name: this.scheduleGroupName,
});

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

this.scheduleGroupArn = this.getResourceArnAttribute(resource.attrArn, {
service: 'scheduler',
35 changes: 24 additions & 11 deletions packages/@aws-cdk/aws-scheduler-alpha/lib/schedule.ts
Original file line number Diff line number Diff line change
@@ -1,38 +1,40 @@
import { Duration, IResource, Resource, Token } from 'aws-cdk-lib';
import { Arn, ArnFormat, Duration, IResource, Resource, Token } from 'aws-cdk-lib';
import * as cloudwatch from 'aws-cdk-lib/aws-cloudwatch';
import * as kms from 'aws-cdk-lib/aws-kms';
import { CfnSchedule } from 'aws-cdk-lib/aws-scheduler';
import { addConstructMetadata } from 'aws-cdk-lib/core/lib/metadata-resource';
import { Construct } from 'constructs';
import { IGroup } from './group';
import { ScheduleExpression } from './schedule-expression';
import { IScheduleTarget } from './target';
import { IScheduleGroup } from './schedule-group';
import { IScheduleTarget } from './target';

/**
* Interface representing a created or an imported `Schedule`.
*/
export interface ISchedule extends IResource {
/**
* The name of the schedule.
* The arn of the schedule.
* @attribute
*/
readonly scheduleName: string;
readonly scheduleArn: string;

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

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

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

/**
@@ -259,6 +261,17 @@ export class Schedule extends Resource implements ISchedule {
return this.metricAll('InvocationsSentToDeadLetterCount_Truncated_MessageSizeExceeded', props);
}

/**
* Import an existing schedule using the ARN.
*/
public static fromScheduleArn(scope: Construct, id: string, scheduleArn: string): ISchedule {
class Import extends Resource implements ISchedule {
public readonly scheduleArn = scheduleArn;
public readonly scheduleName = Arn.split(scheduleArn, ArnFormat.SLASH_RESOURCE_NAME).resourceName!.split('/')[1];
}
return new Import(scope, id);
}

/**
* The schedule group associated with this schedule.
* @deprecated Use `scheduleGroup` instead. `group` will be removed when this module is stabilized.
@@ -324,7 +337,7 @@ export class Schedule extends Resource implements ISchedule {
},
scheduleExpression: props.schedule.expressionString,
scheduleExpressionTimezone: props.schedule.timeZone?.timezoneName,
groupName: this.group?.groupName,
groupName: this.scheduleGroup?.scheduleGroupName ?? this.group?.groupName,
state: (props.enabled ?? true) ? 'ENABLED' : 'DISABLED',
kmsKeyArn: this.key?.keyArn,
target: {
@@ -348,7 +361,7 @@ export class Schedule extends Resource implements ISchedule {
this.scheduleArn = this.getResourceArnAttribute(resource.attrArn, {
service: 'scheduler',
resource: 'schedule',
resourceName: `${this.group?.groupName ?? 'default'}/${this.physicalName}`,
resourceName: `${this.scheduleGroup?.scheduleGroupName ?? this.group?.groupName ?? 'default'}/${this.physicalName}`,
});
}

13 changes: 12 additions & 1 deletion packages/@aws-cdk/aws-scheduler-alpha/lib/target.ts
Original file line number Diff line number Diff line change
@@ -31,39 +31,50 @@ export interface ScheduleTargetConfig {

/**
* What input to pass to the target
* @default - No input
*/
readonly input?: ScheduleTargetInput;

/**
* A `RetryPolicy` object that includes information about the retry policy settings, including the maximum age of an event, and the maximum number of times EventBridge Scheduler will try to deliver the event to a target.
* @default - Maximum retry attempts of 185 and maximum age of 86400 seconds (1 day)
*/
readonly retryPolicy?: CfnSchedule.RetryPolicyProperty;

/**
* An object that contains information about an Amazon SQS queue that EventBridge Scheduler uses as a dead-letter queue for your schedule. If specified, EventBridge Scheduler delivers failed events that could not be successfully delivered to a target to the queue.\
* An object that contains information about an Amazon SQS queue that EventBridge Scheduler uses as a dead-letter queue for your schedule.
* If specified, EventBridge Scheduler delivers failed events that could not be successfully delivered to a target to the queue.
* @default - No dead-letter queue
*/
readonly deadLetterConfig?: CfnSchedule.DeadLetterConfigProperty;

/**
* The templated target type for the Amazon ECS RunTask API Operation.
* @default - No parameters
*/
readonly ecsParameters?: CfnSchedule.EcsParametersProperty;

/**
* The templated target type for the EventBridge PutEvents API operation.
* @default - No parameters
*/
readonly eventBridgeParameters?: CfnSchedule.EventBridgeParametersProperty;

/**
* The templated target type for the Amazon Kinesis PutRecord API operation.
* @default - No parameters
*/
readonly kinesisParameters?: CfnSchedule.KinesisParametersProperty;

/**
* The templated target type for the Amazon SageMaker StartPipelineExecution API operation.
* @default - No parameters
*/
readonly sageMakerPipelineParameters?: CfnSchedule.SageMakerPipelineParametersProperty;

/**
* The templated target type for the Amazon SQS SendMessage API Operation
* @default - No parameters
*/
readonly sqsParameters?: CfnSchedule.SqsParametersProperty;
}
Original file line number Diff line number Diff line change
@@ -5,8 +5,8 @@ import * as iam from 'aws-cdk-lib/aws-iam';
import * as lambda from 'aws-cdk-lib/aws-lambda';
import { CfnScheduleGroup } from 'aws-cdk-lib/aws-scheduler';
import { IScheduleTarget, ScheduleExpression, ScheduleTargetConfig } from '../lib';
import { ScheduleGroup, ScheduleGroupProps } from '../lib/schedule-group';
import { Schedule } from '../lib/schedule';
import { ScheduleGroup, ScheduleGroupProps } from '../lib/schedule-group';

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

expect(schedule1.group).toEqual(group);
expect(schedule2.group).toEqual(group);
expect(schedule1.scheduleGroup).toBe(group);
expect(schedule2.scheduleGroup).toBe(group);

Template.fromStack(stack).hasResource('AWS::Scheduler::Schedule', {
Properties: {
@@ -150,8 +150,8 @@ describe('Schedule Group', () => {
target: new SomeLambdaTarget(func, role),
});

expect(schedule1.group).toEqual(group);
expect(schedule2.group).toEqual(group);
expect(schedule1.scheduleGroup).toBe(group);
expect(schedule2.scheduleGroup).toBe(group);

Template.fromStack(stack).hasResource('AWS::Scheduler::Schedule', {
Properties: {