Skip to content

Commit 99740b3

Browse files
authored
feat(secretsmanager): validate maximum value of automaticallyAfter in RotationSchedule (#27592)
I added a validation for whether `automaticallyAfter` in `RotationSchedule` is not greater than 1000 days. We discussed in the following threads. #27570 (review) #27570 (review) ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent 14fa190 commit 99740b3

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

packages/aws-cdk-lib/aws-secretsmanager/lib/rotation-schedule.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ export interface RotationScheduleOptions {
3737
* Specifies the number of days after the previous rotation before
3838
* Secrets Manager triggers the next automatic rotation.
3939
*
40+
* The maximum value is 1000 days.
41+
*
4042
* A value of zero (`Duration.days(0)`) will not create RotationRules.
4143
*
4244
* @default Duration.days(30)
@@ -125,6 +127,9 @@ export class RotationSchedule extends Resource {
125127
}
126128

127129
let automaticallyAfterDays: number | undefined = undefined;
130+
if (props.automaticallyAfter && props.automaticallyAfter.toDays() > 1000) {
131+
throw new Error(`automaticallyAfter must not be greater than 1000 days, got ${props.automaticallyAfter.toDays()} days`);
132+
}
128133
if (props.automaticallyAfter?.toMilliseconds() !== 0) {
129134
automaticallyAfterDays = props.automaticallyAfter?.toDays() || 30;
130135
}

packages/aws-cdk-lib/aws-secretsmanager/test/rotation-schedule.test.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -651,3 +651,21 @@ test('rotation schedule should have a dependency on lambda permissions', () => {
651651
],
652652
});
653653
});
654+
655+
test('automaticallyAfter must not be greater than 1000 days', () => {
656+
// GIVEN
657+
const secret = new secretsmanager.Secret(stack, 'Secret');
658+
const rotationLambda = new lambda.Function(stack, 'Lambda', {
659+
runtime: lambda.Runtime.NODEJS_LATEST,
660+
code: lambda.Code.fromInline('export.handler = event => event;'),
661+
handler: 'index.handler',
662+
});
663+
664+
// WHEN
665+
// THEN
666+
expect(() => new secretsmanager.RotationSchedule(stack, 'RotationSchedule', {
667+
secret,
668+
rotationLambda,
669+
automaticallyAfter: Duration.days(1001),
670+
})).toThrow(/automaticallyAfter must not be greater than 1000 days, got 1001 days/);
671+
});

0 commit comments

Comments
 (0)