diff --git a/packages/aws-cdk-lib/aws-secretsmanager/lib/rotation-schedule.ts b/packages/aws-cdk-lib/aws-secretsmanager/lib/rotation-schedule.ts index ee978a28f6d19..187efeb58947e 100644 --- a/packages/aws-cdk-lib/aws-secretsmanager/lib/rotation-schedule.ts +++ b/packages/aws-cdk-lib/aws-secretsmanager/lib/rotation-schedule.ts @@ -127,21 +127,19 @@ export class RotationSchedule extends Resource { // Prevent secrets deletions when rotation is in place props.secret.denyAccountRootDelete(); - if (props.automaticallyAfter && props.automaticallyAfter.toMilliseconds() === 0) { - return; + if (!props.automaticallyAfter || props.automaticallyAfter.toMilliseconds() !== 0) { + const rotationRules = { + automaticallyAfterDays: props.automaticallyAfter?.toDays() || 30, + }; + + new CfnRotationSchedule(this, 'Resource', { + secretId: props.secret.secretArn, + rotationLambdaArn: props.rotationLambda?.functionArn, + hostedRotationLambda: props.hostedRotation?.bind(props.secret, this), + rotationRules, + rotateImmediatelyOnUpdate: props.rotateImmediatelyOnUpdate, + }); } - - const rotationRules = { - automaticallyAfterDays: props.automaticallyAfter?.toDays() || 30, - }; - - new CfnRotationSchedule(this, 'Resource', { - secretId: props.secret.secretArn, - rotationLambdaArn: props.rotationLambda?.functionArn, - hostedRotationLambda: props.hostedRotation?.bind(props.secret, this), - rotationRules, - rotateImmediatelyOnUpdate: props.rotateImmediatelyOnUpdate, - }); } }