Skip to content

Commit f9b28b9

Browse files
authored
fix(rds): monitoringInterval in DatabaseClusterProps does not work with token (#33516)
### Issue # (if applicable) Closes #33504. ### Reason for this change `monitoringInterval` prop in `DatabaseClusterProps` should accept a token. ### Description of changes Skip validations if `monitoringInterval` is a token. ### Describe any new or updated permissions being added N/A ### Description of how you validated changes Added a unit test. ### 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*
1 parent 3b07346 commit f9b28b9

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

packages/aws-cdk-lib/aws-rds/lib/cluster.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -889,7 +889,10 @@ abstract class DatabaseClusterNew extends DatabaseClusterBase {
889889
if (props.enableClusterLevelEnhancedMonitoring && !props.monitoringInterval) {
890890
throw new ValidationError('`monitoringInterval` must be set when `enableClusterLevelEnhancedMonitoring` is true.', this);
891891
}
892-
if (props.monitoringInterval && [0, 1, 5, 10, 15, 30, 60].indexOf(props.monitoringInterval.toSeconds()) === -1) {
892+
if (
893+
props.monitoringInterval && !props.monitoringInterval.isUnresolved() &&
894+
[0, 1, 5, 10, 15, 30, 60].indexOf(props.monitoringInterval.toSeconds()) === -1
895+
) {
893896
throw new ValidationError(`'monitoringInterval' must be one of 0, 1, 5, 10, 15, 30, or 60 seconds, got: ${props.monitoringInterval.toSeconds()} seconds.`, this);
894897
}
895898

packages/aws-cdk-lib/aws-rds/test/cluster.test.ts

+25
Original file line numberDiff line numberDiff line change
@@ -3147,6 +3147,31 @@ describe('cluster', () => {
31473147
});
31483148
}).toThrow(`'monitoringInterval' must be one of 0, 1, 5, 10, 15, 30, or 60 seconds, got: ${monitoringInterval.toSeconds()} seconds.`);
31493149
});
3150+
3151+
test('accept token for monitoring interval', () => {
3152+
// GIVEN
3153+
const stack = testStack();
3154+
const vpc = new ec2.Vpc(stack, 'VPC');
3155+
const parameter = new cdk.CfnParameter(stack, 'MonitoringIntervalParameter', { type: 'Number' });
3156+
3157+
// WHEN
3158+
new DatabaseCluster(stack, 'Database', {
3159+
engine: DatabaseClusterEngine.auroraMysql({ version: AuroraMysqlEngineVersion.VER_3_07_1 }),
3160+
credentials: {
3161+
username: 'admin',
3162+
password: cdk.SecretValue.unsafePlainText('tooshort'),
3163+
},
3164+
vpc,
3165+
writer: ClusterInstance.serverlessV2('writer'),
3166+
monitoringInterval: cdk.Duration.seconds(parameter.valueAsNumber),
3167+
enableClusterLevelEnhancedMonitoring: true,
3168+
});
3169+
3170+
// THEN
3171+
Template.fromStack(stack).hasResourceProperties('AWS::RDS::DBCluster', {
3172+
MonitoringInterval: { Ref: 'MonitoringIntervalParameter' },
3173+
});
3174+
});
31503175
});
31513176

31523177
test('addRotationSingleUser()', () => {

0 commit comments

Comments
 (0)