Skip to content

Commit

Permalink
feat(rds): support backtrackWindow in DatabaseCluster (#17160)
Browse files Browse the repository at this point in the history
This is a small PR to fix #9369 without needing to use an escape hatch.

Fixes  #9369

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
jamesorlakin committed Oct 26, 2021
1 parent 7689869 commit fcd17e9
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
11 changes: 11 additions & 0 deletions packages/@aws-cdk/aws-rds/lib/cluster.ts
Expand Up @@ -40,6 +40,16 @@ interface DatabaseClusterBaseProps {
*/
readonly instanceProps: InstanceProps;

/**
* The number of seconds to set a cluster's target backtrack window to.
* This feature is only supported by the Aurora MySQL database engine and
* cannot be enabled on existing clusters.
*
* @see https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/AuroraMySQL.Managing.Backtrack.html
* @default 0 seconds (no backtrack)
*/
readonly backtrackWindow?: Duration

/**
* Backup settings
*
Expand Down Expand Up @@ -364,6 +374,7 @@ abstract class DatabaseClusterNew extends DatabaseClusterBase {
deletionProtection: defaultDeletionProtection(props.deletionProtection, props.removalPolicy),
enableIamDatabaseAuthentication: props.iamAuthentication,
// Admin
backtrackWindow: props.backtrackWindow?.toSeconds(),
backupRetentionPeriod: props.backup?.retention?.toDays(),
preferredBackupWindow: props.backup?.preferredWindow,
preferredMaintenanceWindow: props.preferredMaintenanceWindow,
Expand Down
20 changes: 20 additions & 0 deletions packages/@aws-cdk/aws-rds/test/cluster.test.ts
Expand Up @@ -2032,6 +2032,26 @@ describe('cluster', () => {
CopyTagsToSnapshot: true,
});
});

test('cluster has BacktrackWindow in seconds', () => {
// GIVEN
const stack = testStack();
const vpc = new ec2.Vpc(stack, 'VPC');

// WHEN
new DatabaseCluster(stack, 'Database', {
engine: DatabaseClusterEngine.AURORA,
instanceProps: {
vpc,
},
backtrackWindow: cdk.Duration.days(1),
});

// THEN
expect(stack).toHaveResourceLike('AWS::RDS::DBCluster', {
BacktrackWindow: 24 * 60 * 60,
});
});
});

test.each([
Expand Down

0 comments on commit fcd17e9

Please sign in to comment.