Skip to content

Commit

Permalink
fix(scheduler-targets-alpha): incorrect validation of maximumEventAge (
Browse files Browse the repository at this point in the history
…#32284)

### Issue # (if applicable)

N/A

### Reason for this change

The minimum value of `MaximumEventAgeInSeconds` of RetryPolicy is 60 seconds.
https://docs.aws.amazon.com/ja_jp/AWSCloudFormation/latest/UserGuide/aws-properties-scheduler-schedule-retrypolicy.html

`renderRetryPolicy()` currently throws an error when `maxEventAge` is less than 15 minutes.

### Description of changes

Fixed the minimum value of `maxEventAge` to 1 minute. JSDoc is already correct.

### Description of how you validated changes

Fixed unit tests for maxEventAge.
Fixed a lambda integ test to specify maxEventAge to 1 minute.

### 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
Tietew authored and mazyu36 committed Nov 27, 2024
1 parent 16fbd69 commit 24f4c77
Show file tree
Hide file tree
Showing 23 changed files with 10,622 additions and 15,281 deletions.
4 changes: 2 additions & 2 deletions packages/@aws-cdk/aws-scheduler-targets-alpha/lib/target.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,15 +154,15 @@ export abstract class ScheduleTargetBase {

private renderRetryPolicy(maximumEventAge: Duration | undefined, maximumRetryAttempts: number | undefined): CfnSchedule.RetryPolicyProperty {
const maxMaxAge = Duration.days(1).toSeconds();
const minMaxAge = Duration.minutes(15).toSeconds();
const minMaxAge = Duration.minutes(1).toSeconds();
let maxAge: number = maxMaxAge;
if (maximumEventAge) {
maxAge = maximumEventAge.toSeconds({ integral: true });
if (maxAge > maxMaxAge) {
throw new Error('Maximum event age is 1 day');
}
if (maxAge < minMaxAge) {
throw new Error('Minimum event age is 15 minutes');
throw new Error('Minimum event age is 1 minute');
}
};
let maxAttempts = 185;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -493,16 +493,16 @@ describe('codebuild start build', () => {
})).toThrow(/Maximum event age is 1 day/);
});

test('throws when retry policy max age is less than 15 minutes', () => {
test('throws when retry policy max age is less than 1 minute', () => {
const codebuildProjectTarget = new CodeBuildStartBuild(codebuildProject, {
maxEventAge: Duration.minutes(5),
maxEventAge: Duration.seconds(59),
});

expect(() =>
new Schedule(stack, 'MyScheduleDummy', {
schedule: expr,
target: codebuildProjectTarget,
})).toThrow(/Minimum event age is 15 minutes/);
})).toThrow(/Minimum event age is 1 minute/);
});

test('throws when retry policy max retry attempts is out of the allowed limits', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -501,16 +501,16 @@ describe('codepipeline start execution', () => {
})).toThrow(/Maximum event age is 1 day/);
});

test('throws when retry policy max age is less than 15 minutes', () => {
test('throws when retry policy max age is less than 1 minute', () => {
const codepipelineTarget = new CodePipelineStartPipelineExecution(codepipeline, {
maxEventAge: Duration.minutes(5),
maxEventAge: Duration.seconds(59),
});

expect(() =>
new Schedule(stack, 'MyScheduleDummy', {
schedule: expr,
target: codepipelineTarget,
})).toThrow(/Minimum event age is 15 minutes/);
})).toThrow(/Minimum event age is 1 minute/);
});

test('throws when retry policy max retry attempts is out of the allowed limits', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -587,16 +587,16 @@ describe('eventBridge put events', () => {
})).toThrow(/Maximum event age is 1 day/);
});

test('throws when retry policy max age is less than 15 minutes', () => {
test('throws when retry policy max age is less than 1 minute', () => {
const eventBusTarget = new EventBridgePutEvents(eventBusEventEntry, {
maxEventAge: Duration.minutes(5),
maxEventAge: Duration.seconds(59),
});

expect(() =>
new Schedule(stack, 'MyScheduleDummy', {
schedule: expr,
target: eventBusTarget,
})).toThrow(/Minimum event age is 15 minutes/);
})).toThrow(/Minimum event age is 1 minute/);
});

test('throws when retry policy max retry attempts is out of the allowed limits', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -508,16 +508,16 @@ describe('schedule target', () => {
})).toThrow(/Maximum event age is 1 day/);
});

test('throws when retry policy max age is less than 15 minutes', () => {
test('throws when retry policy max age is less than 1 minute', () => {
const inspectorTarget = new InspectorStartAssessmentRun(template, {
maxEventAge: Duration.minutes(5),
maxEventAge: Duration.seconds(59),
});

expect(() =>
new Schedule(stack, 'MyScheduleDummy', {
schedule: expr,
target: inspectorTarget,
})).toThrow(/Minimum event age is 15 minutes/);
})).toThrow(/Minimum event age is 1 minute/);
});

test('throws when retry policy max retry attempts is out of the allowed limits', () => {
Expand Down
Loading

0 comments on commit 24f4c77

Please sign in to comment.