Skip to content

Commit be4154b

Browse files
authored
fix(scheduler-alpha): remove targetOverrides prop from Schedule (#31799)
### Issue # (if applicable) N/A ### Reason for this change The `targetOverrides` prop is adding confusion to the API as it override what is set on the target. A better way to reuse target props would be: ```ts const targetBaseProps = { input: ...someInput... } const schedule1 = new Schedule(this, 'Schedule', { scheduleExpression: ScheduleExpression.cron({ day: '20' }), target: new targets.LambdaInvoke(props.func, { ...targetBaseProps, // override whatever or not to override }), }), }); ``` ### Description of changes Removed `targetOverrides` prop and the related tests. Also updated the integ test which was using the prop. ### Description of how you validated changes Removing a prop so n/a. ### 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* ---- BREAKING CHANGE: This PR removes the `targetOverrides` prop from the `Schedule` construct.
1 parent 7bebf40 commit be4154b

12 files changed

+39
-340
lines changed

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

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -285,25 +285,6 @@ const target = new targets.LambdaInvoke(fn, {
285285
});
286286
```
287287

288-
## Overriding Target Properties
289-
290-
If you wish to reuse the same target in multiple schedules, you can override target properties like `input`,
291-
`retryAttempts` and `maxEventAge` when creating a Schedule using the `targetOverrides` parameter:
292-
293-
```ts
294-
declare const target: targets.LambdaInvoke;
295-
296-
const oneTimeSchedule = new Schedule(this, 'Schedule', {
297-
schedule: ScheduleExpression.rate(cdk.Duration.hours(12)),
298-
target,
299-
targetOverrides: {
300-
input: ScheduleTargetInput.fromText('Overriding Target Input'),
301-
maxEventAge: Duration.seconds(180),
302-
retryAttempts: 5,
303-
},
304-
});
305-
```
306-
307288
## Monitoring
308289

309290
You can monitor Amazon EventBridge Scheduler using CloudWatch, which collects raw data

packages/@aws-cdk/aws-scheduler-alpha/lib/schedule.ts

Lines changed: 3 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import * as kms from 'aws-cdk-lib/aws-kms';
44
import { CfnSchedule } from 'aws-cdk-lib/aws-scheduler';
55
import { Construct } from 'constructs';
66
import { IGroup } from './group';
7-
import { ScheduleTargetInput } from './input';
87
import { ScheduleExpression } from './schedule-expression';
98
import { IScheduleTarget } from './target';
109

@@ -26,37 +25,6 @@ export interface ISchedule extends IResource {
2625
* The arn of the schedule.
2726
*/
2827
readonly scheduleArn: string;
29-
30-
/**
31-
* The customer managed KMS key that EventBridge Scheduler will use to encrypt and decrypt your data.
32-
*/
33-
readonly key?: kms.IKey;
34-
}
35-
36-
export interface ScheduleTargetProps {
37-
/**
38-
* The text, or well-formed JSON, passed to the target.
39-
*
40-
* If you are configuring a templated Lambda, AWS Step Functions, or Amazon EventBridge target,
41-
* the input must be a well-formed JSON. For all other target types, a JSON is not required.
42-
*
43-
* @default - The target's input is used.
44-
*/
45-
readonly input?: ScheduleTargetInput;
46-
47-
/**
48-
* The maximum amount of time, in seconds, to continue to make retry attempts.
49-
*
50-
* @default - The target's maximumEventAgeInSeconds is used.
51-
*/
52-
readonly maxEventAge?: Duration;
53-
54-
/**
55-
* The maximum number of retry attempts to make before the request fails.
56-
*
57-
* @default - The target's maximumRetryAttempts is used.
58-
*/
59-
readonly retryAttempts?: number;
6028
}
6129

6230
/**
@@ -115,11 +83,6 @@ export interface ScheduleProps {
11583
*/
11684
readonly target: IScheduleTarget;
11785

118-
/**
119-
* Allows to override target properties when creating a new schedule.
120-
*/
121-
readonly targetOverrides?: ScheduleTargetProps;
122-
12386
/**
12487
* The name of the schedule.
12588
*
@@ -342,11 +305,9 @@ export class Schedule extends Resource implements ISchedule {
342305
target: {
343306
arn: targetConfig.arn,
344307
roleArn: targetConfig.role.roleArn,
345-
input: props.targetOverrides?.input ?
346-
props.targetOverrides?.input?.bind(this) :
347-
targetConfig.input?.bind(this),
308+
input: targetConfig.input?.bind(this),
348309
deadLetterConfig: targetConfig.deadLetterConfig,
349-
retryPolicy: this.renderRetryPolicy(props.targetOverrides?.maxEventAge?.toSeconds(), props.targetOverrides?.retryAttempts),
310+
retryPolicy: this.renderRetryPolicy(),
350311
ecsParameters: targetConfig.ecsParameters,
351312
kinesisParameters: targetConfig.kinesisParameters,
352313
eventBridgeParameters: targetConfig.eventBridgeParameters,
@@ -366,14 +327,9 @@ export class Schedule extends Resource implements ISchedule {
366327
});
367328
}
368329

369-
private renderRetryPolicy(
370-
maximumEventAgeInSeconds?: number,
371-
maximumRetryAttempts?: number,
372-
): CfnSchedule.RetryPolicyProperty | undefined {
330+
private renderRetryPolicy(): CfnSchedule.RetryPolicyProperty | undefined {
373331
const policy = {
374332
...this.retryPolicy,
375-
maximumEventAgeInSeconds: maximumEventAgeInSeconds ?? this.retryPolicy?.maximumEventAgeInSeconds,
376-
maximumRetryAttempts: maximumRetryAttempts ?? this.retryPolicy?.maximumRetryAttempts,
377333
};
378334

379335
if (policy.maximumEventAgeInSeconds && (policy.maximumEventAgeInSeconds < 60 || policy.maximumEventAgeInSeconds > 86400)) {

packages/@aws-cdk/aws-scheduler-alpha/test/input.test.ts

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -146,24 +146,4 @@ describe('schedule target input', () => {
146146
},
147147
});
148148
});
149-
150-
test('can override target input', () => {
151-
// WHEN
152-
const input = ScheduleTargetInput.fromText('Original Input');
153-
new Schedule(stack, 'TestSchedule', {
154-
schedule: expr,
155-
target: new SomeLambdaTarget(func, input),
156-
targetOverrides: {
157-
input: ScheduleTargetInput.fromText('Overridden Input'),
158-
},
159-
enabled: false,
160-
});
161-
162-
// THEN
163-
Template.fromStack(stack).hasResourceProperties('AWS::Scheduler::Schedule', {
164-
Target: {
165-
Input: '"Overridden Input"',
166-
},
167-
});
168-
});
169149
});

packages/@aws-cdk/aws-scheduler-alpha/test/integ.schedule.js.snapshot/aws-cdk-scheduler-schedule.assets.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk/aws-scheduler-alpha/test/integ.schedule.js.snapshot/aws-cdk-scheduler-schedule.template.json

Lines changed: 4 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -103,16 +103,16 @@
103103
"Properties": {
104104
"Name": "TestGroup"
105105
},
106-
"UpdateReplacePolicy": "Retain",
107-
"DeletionPolicy": "Retain"
106+
"UpdateReplacePolicy": "Delete",
107+
"DeletionPolicy": "Delete"
108108
},
109109
"UnnamedGroupBE3E48EE": {
110110
"Type": "AWS::Scheduler::ScheduleGroup",
111111
"Properties": {
112112
"Name": "awscdkschedulerschedule-UnnamedGroup-97DBE50D"
113113
},
114-
"UpdateReplacePolicy": "Retain",
115-
"DeletionPolicy": "Retain"
114+
"UpdateReplacePolicy": "Delete",
115+
"DeletionPolicy": "Delete"
116116
},
117117
"DefaultSchedule597B0B2C": {
118118
"Type": "AWS::Scheduler::Schedule",
@@ -236,36 +236,6 @@
236236
}
237237
}
238238
},
239-
"TargetOverrideScheduleFF8CB184": {
240-
"Type": "AWS::Scheduler::Schedule",
241-
"Properties": {
242-
"FlexibleTimeWindow": {
243-
"Mode": "OFF"
244-
},
245-
"ScheduleExpression": "rate(12 hours)",
246-
"ScheduleExpressionTimezone": "Etc/UTC",
247-
"State": "ENABLED",
248-
"Target": {
249-
"Arn": {
250-
"Fn::GetAtt": [
251-
"Function76856677",
252-
"Arn"
253-
]
254-
},
255-
"Input": "\"Changed Text\"",
256-
"RetryPolicy": {
257-
"MaximumEventAgeInSeconds": 360,
258-
"MaximumRetryAttempts": 5
259-
},
260-
"RoleArn": {
261-
"Fn::GetAtt": [
262-
"Role1ABCC5F0",
263-
"Arn"
264-
]
265-
}
266-
}
267-
}
268-
},
269239
"AllSchedulerErrorsAlarmA3246F8C": {
270240
"Type": "AWS::CloudWatch::Alarm",
271241
"Properties": {

packages/@aws-cdk/aws-scheduler-alpha/test/integ.schedule.js.snapshot/cdk.out

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk/aws-scheduler-alpha/test/integ.schedule.js.snapshot/integ.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk/aws-scheduler-alpha/test/integ.schedule.js.snapshot/integtestscheduleDefaultTestDeployAssert24CB3896.assets.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk/aws-scheduler-alpha/test/integ.schedule.js.snapshot/manifest.json

Lines changed: 13 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)