Skip to content
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

feat(rds): specify PreferredMaintenanceWindow in reader or writer props #29686

Merged
merged 11 commits into from
Apr 5, 2024
12 changes: 12 additions & 0 deletions packages/aws-cdk-lib/aws-rds/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1224,3 +1224,15 @@ new rds.DatabaseCluster(this, 'DatabaseCluster', {
preferredMaintenanceWindow: 'Sat:22:15-Sat:22:45',
});
```
You can also use writer or readers props like:
Konosh93 marked this conversation as resolved.
Show resolved Hide resolved

```ts
new DatabaseCluster(stack, 'DatabaseCluster', {
engine: DatabaseClusterEngine.AURORA,
vpc: vpc,
writer: ClusterInstance.provisioned('Instance1', {
preferredMaintenanceWindow: 'Sat:22:15-Sat:22:45',
}),
preferredMaintenanceWindow: 'Sat:22:15-Sat:22:45',
});
```
12 changes: 12 additions & 0 deletions packages/aws-cdk-lib/aws-rds/lib/aurora-cluster-instance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,17 @@ export interface ClusterInstanceOptions {
*/
readonly publiclyAccessible?: boolean;

/**
* A preferred maintenance window day/time range. Should be specified as a range ddd:hh24:mi-ddd:hh24:mi (24H Clock UTC).
*
* Example: 'Sun:23:45-Mon:00:15'
*
* @default - 30-minute window selected at random from an 8-hour block of time for
* each AWS Region, occurring on a random day of the week.
* @see https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/USER_UpgradeDBInstance.Maintenance.html#Concepts.DBMaintenance
*/
readonly preferredMaintenanceWindow?: string;

/**
* The parameters in the DBParameterGroup to create automatically
*
Expand Down Expand Up @@ -499,6 +510,7 @@ class AuroraClusterInstance extends Resource implements IAuroraClusterInstance {
// Instance properties
dbInstanceClass: props.instanceType ? databaseInstanceType(instanceType) : undefined,
publiclyAccessible,
preferredMaintenanceWindow: props.preferredMaintenanceWindow,
enablePerformanceInsights: enablePerformanceInsights || props.enablePerformanceInsights, // fall back to undefined if not set
performanceInsightsKmsKeyId: props.performanceInsightEncryptionKey?.keyArn,
performanceInsightsRetentionPeriod: enablePerformanceInsights
Expand Down
23 changes: 23 additions & 0 deletions packages/aws-cdk-lib/aws-rds/test/cluster.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,29 @@ describe('cluster new api', () => {
},
});

// THEN
const template = Template.fromStack(stack);
// maintenance window is set
template.hasResourceProperties('AWS::RDS::DBInstance', Match.objectLike({
PreferredMaintenanceWindow: PREFERRED_MAINTENANCE_WINDOW,
}));
});
test('preferredMaintenanceWindow provided in reader or writer', () => {
// GIVEN
const stack = testStack();
const vpc = new ec2.Vpc(stack, 'VPC');

const PREFERRED_MAINTENANCE_WINDOW: string = 'Sun:12:00-Sun:13:00';

// WHEN
new DatabaseCluster(stack, 'Database', {
engine: DatabaseClusterEngine.AURORA,
vpc: vpc,
writer: ClusterInstance.provisioned('Instance1', {
preferredMaintenanceWindow: PREFERRED_MAINTENANCE_WINDOW,
}),
Konosh93 marked this conversation as resolved.
Show resolved Hide resolved
});

// THEN
const template = Template.fromStack(stack);
// maintenance window is set
Expand Down