-
Notifications
You must be signed in to change notification settings - Fork 4k
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
feat(scheduler-alpha): target properties override #27603
Changes from 5 commits
dd7ed9d
51ab22e
ede8e75
22ce09d
97aef76
b8ac3e7
a3c91ef
7a7a66e
9001791
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
@@ -1,9 +1,10 @@ | ||||||||
import { IResource, Resource } from 'aws-cdk-lib'; | ||||||||
import { Duration, IResource, Resource } 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 { Construct } from 'constructs'; | ||||||||
import { IGroup } from './group'; | ||||||||
import { ScheduleTargetInput } from './input'; | ||||||||
import { ScheduleExpression } from './schedule-expression'; | ||||||||
import { IScheduleTarget } from './target'; | ||||||||
|
||||||||
|
@@ -15,10 +16,12 @@ export interface ISchedule extends IResource { | |||||||
* The name of the schedule. | ||||||||
*/ | ||||||||
readonly scheduleName: string; | ||||||||
|
||||||||
/** | ||||||||
* The schedule group associated with this schedule. | ||||||||
*/ | ||||||||
readonly group?: IGroup; | ||||||||
|
||||||||
/** | ||||||||
* The arn of the schedule. | ||||||||
*/ | ||||||||
|
@@ -30,6 +33,54 @@ export interface ISchedule extends IResource { | |||||||
readonly key?: kms.IKey; | ||||||||
} | ||||||||
|
||||||||
export interface ScheduleTargetProps { | ||||||||
/** | ||||||||
* The text, or well-formed JSON, passed to the target. | ||||||||
* | ||||||||
* If you are configuring a templated Lambda, AWS Step Functions, or Amazon EventBridge target, | ||||||||
* the input must be a well-formed JSON. For all other target types, a JSON is not required. | ||||||||
* | ||||||||
* @default - The target's input is used. | ||||||||
*/ | ||||||||
readonly input?: ScheduleTargetInput; | ||||||||
/** | ||||||||
* The maximum amount of time, in seconds, to continue to make retry attempts. | ||||||||
* | ||||||||
* @default - The target's maximumEventAgeInSeconds is used. | ||||||||
*/ | ||||||||
readonly maximumEventAge?: Duration; | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it's called |
||||||||
/** | ||||||||
* The maximum number of retry attempts to make before the request fails. | ||||||||
* | ||||||||
* @default - The target's maximumRetryAttempts is used. | ||||||||
*/ | ||||||||
readonly maximumRetryAttempts?: number; | ||||||||
} | ||||||||
|
||||||||
export interface ScheduleTargetProps { | ||||||||
/** | ||||||||
* The text, or well-formed JSON, passed to the target. | ||||||||
* | ||||||||
* If you are configuring a templated Lambda, AWS Step Functions, or Amazon EventBridge target, | ||||||||
* the input must be a well-formed JSON. For all other target types, a JSON is not required. | ||||||||
* | ||||||||
* @default - The target's input is used. | ||||||||
*/ | ||||||||
readonly input?: ScheduleTargetInput; | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
/** | ||||||||
* The maximum amount of time, in seconds, to continue to make retry attempts. | ||||||||
* | ||||||||
* @default - The target's maximumEventAgeInSeconds is used. | ||||||||
*/ | ||||||||
readonly maximumEventAge?: Duration; | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
/** | ||||||||
* The maximum number of retry attempts to make before the request fails. | ||||||||
* | ||||||||
* @default - The target's maximumRetryAttempts is used. | ||||||||
*/ | ||||||||
readonly maximumRetryAttempts?: number; | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Renamed to |
||||||||
} | ||||||||
|
||||||||
/** | ||||||||
* Construction properties for `Schedule`. | ||||||||
*/ | ||||||||
|
@@ -45,6 +96,11 @@ export interface ScheduleProps { | |||||||
*/ | ||||||||
readonly target: IScheduleTarget; | ||||||||
|
||||||||
/** | ||||||||
* Allows to override target properties when creating a new schedule. | ||||||||
*/ | ||||||||
readonly targetOverrides?: ScheduleTargetProps; | ||||||||
|
||||||||
/** | ||||||||
* The name of the schedule. | ||||||||
* | ||||||||
|
@@ -211,6 +267,13 @@ export class Schedule extends Resource implements ISchedule { | |||||||
this.key.grantEncryptDecrypt(targetConfig.role); | ||||||||
} | ||||||||
|
||||||||
const retryPolicy = { | ||||||||
maximumEventAgeInSeconds: props.targetOverrides?.maximumEventAge?.toSeconds() ?? targetConfig.retryPolicy?.maximumEventAgeInSeconds, | ||||||||
maximumRetryAttempts: props.targetOverrides?.maximumRetryAttempts ?? targetConfig.retryPolicy?.maximumRetryAttempts, | ||||||||
}; | ||||||||
|
||||||||
this.validateRetryPolicy(retryPolicy.maximumEventAgeInSeconds, retryPolicy.maximumRetryAttempts); | ||||||||
|
||||||||
const resource = new CfnSchedule(this, 'Resource', { | ||||||||
name: this.physicalName, | ||||||||
flexibleTimeWindow: { mode: 'OFF' }, | ||||||||
|
@@ -222,9 +285,11 @@ export class Schedule extends Resource implements ISchedule { | |||||||
target: { | ||||||||
arn: targetConfig.arn, | ||||||||
roleArn: targetConfig.role.roleArn, | ||||||||
input: targetConfig.input?.bind(this), | ||||||||
input: props.targetOverrides?.input ? | ||||||||
props.targetOverrides?.input?.bind(this) : | ||||||||
targetConfig.input?.bind(this), | ||||||||
deadLetterConfig: targetConfig.deadLetterConfig, | ||||||||
retryPolicy: targetConfig.retryPolicy, | ||||||||
retryPolicy: retryPolicy.maximumEventAgeInSeconds || retryPolicy.maximumRetryAttempts ? retryPolicy : undefined, | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't like this, it's unnecessarily complicated. And what if we add a prop to |
||||||||
ecsParameters: targetConfig.ecsParameters, | ||||||||
kinesisParameters: targetConfig.kinesisParameters, | ||||||||
eventBridgeParameters: targetConfig.eventBridgeParameters, | ||||||||
|
@@ -240,4 +305,13 @@ export class Schedule extends Resource implements ISchedule { | |||||||
resourceName: `${this.group?.groupName ?? 'default'}/${this.physicalName}`, | ||||||||
}); | ||||||||
} | ||||||||
|
||||||||
private validateRetryPolicy(maximumEventAgeInSeconds: number | undefined, maximumRetryAttempts: number | undefined) { | ||||||||
if (maximumEventAgeInSeconds && (maximumEventAgeInSeconds < 60 || maximumEventAgeInSeconds > 86400)) { | ||||||||
throw new Error(`maximumEventAgeInSeconds must be between 60 and 86400, got ${maximumEventAgeInSeconds}`); | ||||||||
} | ||||||||
if (maximumRetryAttempts && (maximumRetryAttempts < 0 || maximumRetryAttempts > 185)) { | ||||||||
throw new Error(`maximumRetryAttempts must be between 0 and 185, got ${maximumRetryAttempts}`); | ||||||||
} | ||||||||
} | ||||||||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.