-
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
aws_secretsmanager: RotationSchedule cron expression support #24062
Comments
Another approach to the proposed solution is to expose 2 new props in the One called
Looking at the docs for the L1 construct, it seems you can't pass both the |
For now you can use property overrides. So in this case one can write: declare const schedule: Schedule;
const cfnSchedule = rotationSchedule.node.defaultChild as CfnRotationSchedule;
cfnSchedule.addPropertyOverride('RotationRules.ScheduleExpression', schedule.expressionString);
cfnSchedule.addPropertyDeletionOverride('RotationRules.AutomaticallyAfterDays'); And the solution could be simply adding the other parameter |
Or a yet another approach. As both things are down below and a class with two static methods declare const stack: Stack;
declare const everySixHours: Schedule;
declare const threeDays: Duration;
const rotation1Schedule = new RotationSchedule(stack, 'Rotation1Schedule', {
...
rotationRule: RotationRule.onSchedule(everySixHours)
});
const rotation2Schedule = new RotationSchedule(stack, 'Rotation1Schedule', {
...
rotationRule: RotationRule.automaticallyAfter(threeDays)
}); It would then remove the ambiguity. |
For anyone struggeling with a workaround for Layer2 construct Although the Layer 2 construct const schedule: Schedule;
const mySecret = new secretsManager.Secret()
new secretsManager.SecretRotation(this, `SecretRotation`, {
secret: mySecret,
application: secretsmanager.SecretRotationApplication.MYSQL_ROTATION_MULTI_USER,
vpc: props.vpc,
vpcSubnets: props.subnets,
target: this.instance,
excludeCharacters: ' %+~`#$&*()|[]{}:;<>?!\'/@"\\',
});
if (props.secretRotationScheduleExpression) {
const cfnSecretRotationSchedule = databaseSecret.node.findAll().find((child) => {
return child instanceof CfnRotationSchedule;
}) as CfnRotationSchedule;
if (cfnSecretRotationSchedule) {
cfnSecretRotationSchedule.addPropertyOverride('RotationRules.ScheduleExpression', schedule.expressionString);
cfnSecretRotationSchedule.addPropertyDeletionOverride('RotationRules.AutomaticallyAfterDays');
} else {
throw new Error('CfnRotationSchedule not found for mySecret');
}
} |
Describe the feature
Secrets Manager and CloudFormation support using a cron schedule expression for secret rotation:
Maybe I'm missing it, but I cannot find equivalent functionality in CDK. It looks like only setting a rotation period is supported:
Request: Support cron schedule expressions in RotationSchedule, SecretRotation, and Secret#addRotationSchedule.
See: #19980
Use Case
I would like to control more precisely when secret rotation happens, and this functionality exists in the underlying service but is not exposed in CDK.
Proposed Solution
Similar to the CloudFormation resource, a
schedule
property could be added to the relevant props interfaces alongsideautomaticallyAfter
. The type of this property would be a flexible schedule object similar toaws_events.Schedule
.Unfortunately, this results in an awkward interface where one but not both of the
schedule
orautomaticallyAfter
properties is required. A better solution would be to have a single property that supports either rate or cron expression type. For exampleautomaticallyAfter
could acceptDuration | Schedule
. However then the name of that prop would be awkward. Unfortunately I can't think of a great way to express that interface in a backwards-compatible way. The ideal would be to just have aschedule
property withoutautomaticallyAfter
but that would not be backwards-compatible.Other Information
Use
CfnRotationSchedule
L1 as a workaround. Unfortunately it requires manually setting up the permissions for the rotation function as well.Acknowledgements
CDK version used
2.63.2
Environment details (OS name and version, etc.)
macOS 12.6.1
The text was updated successfully, but these errors were encountered: