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): support local write forwarding for an aurora PostgreSQL cluster #31803

Merged
merged 10 commits into from
Oct 19, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,16 @@ new rds.DatabaseCluster(stack, 'DatabaseCluster', {
enableLocalWriteForwarding: true,
});

new rds.DatabaseCluster(stack, 'DatabaseClusterPostgresql', {
engine: rds.DatabaseClusterEngine.auroraPostgres({ version: rds.AuroraPostgresEngineVersion.VER_16_4 }),
writer: rds.ClusterInstance.serverlessV2('writerInstance'),
readers: [
rds.ClusterInstance.serverlessV2('readerInstance1'),
],
vpc,
enableLocalWriteForwarding: true,
});

new integ.IntegTest(app, 'EnableLocalWriteForwardingClusterStackInteg', {
testCases: [stack],
});
3 changes: 2 additions & 1 deletion packages/aws-cdk-lib/aws-rds/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ new rds.DatabaseCluster(this, 'DatabaseCluster', {
});
```

**Note**: Local write forwarding is only supported for Aurora MySQL 3.04 and higher.
**Note**: Local write forwarding is supported only for Aurora MySQL 3.04 or higher, and for Aurora PostgreSQL
16.4 or higher (for version 16), 15.8 or higher (for version 15), and 14.13 or higher (for version 14).

Use `DatabaseClusterFromSnapshot` to create a cluster from a snapshot:

Expand Down
9 changes: 3 additions & 6 deletions packages/aws-cdk-lib/aws-rds/lib/cluster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -389,9 +389,11 @@ interface DatabaseClusterBaseProps {
/**
* Whether read replicas can forward write operations to the writer DB instance in the DB cluster.
*
* This setting can only be enabled for Aurora MySQL 3.04 and higher clusters.
* This setting can only be enabled for Aurora MySQL 3.04 or higher, and for Aurora PostgreSQL 16.4
* or higher (for version 16), 15.8 or higher (for version 15), and 14.13 or higher (for version 14).
*
* @see https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/aurora-mysql-write-forwarding.html
* @see https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/aurora-postgresql-write-forwarding.html
*
* @default false
*/
Expand Down Expand Up @@ -737,11 +739,6 @@ abstract class DatabaseClusterNew extends DatabaseClusterBase {
});
}

// enableLocalWriteForwarding cannot be configured, including false, on Aurora clusters other than MySQL.
if (props.enableLocalWriteForwarding !== undefined && !['aurora', 'aurora-mysql'].includes(props.engine.engineType)) {
throw new Error(`\'enableLocalWriteForwarding\' is only supported for Aurora Mysql cluster engine type, got: ${props.engine.engineType}`);
}

const enablePerformanceInsights = props.enablePerformanceInsights
|| props.performanceInsightRetention !== undefined || props.performanceInsightEncryptionKey !== undefined;
if (enablePerformanceInsights && props.enablePerformanceInsights === false) {
Expand Down
24 changes: 14 additions & 10 deletions packages/aws-cdk-lib/aws-rds/test/cluster.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ describe('cluster new api', () => {
});

describe('enableLocalWriteForwarding', () => {
test('set enableLocalWriteForwarding', () => {
test('set enableLocalWriteForwarding for aurora mysql', () => {
// GIVEN
const stack = testStack();
const vpc = new ec2.Vpc(stack, 'VPC');
Expand All @@ -197,20 +197,24 @@ describe('cluster new api', () => {
});
});

test.each([true, false])('throw error for enableLocalWriteForwarding with aurora postgresql cluster', (enableLocalWriteForwarding) => {
test('set enableLocalWriteForwarding for aurora postgresql', () => {
// GIVEN
const stack = testStack();
const vpc = new ec2.Vpc(stack, 'VPC');

// WHEN
expect(() => {
new DatabaseCluster(stack, 'Database', {
engine: DatabaseClusterEngine.auroraPostgres({ version: AuroraPostgresEngineVersion.VER_16_3 }),
vpc,
enableLocalWriteForwarding,
writer: ClusterInstance.serverlessV2('writer'),
});
}).toThrow('\'enableLocalWriteForwarding\' is only supported for Aurora Mysql cluster engine type, got: aurora-postgresql');
new DatabaseCluster(stack, 'Database', {
engine: DatabaseClusterEngine.auroraPostgres({ version: AuroraPostgresEngineVersion.VER_16_4 }),
vpc,
enableLocalWriteForwarding: true,
writer: ClusterInstance.serverlessV2('writer'),
});

// THEN
const template = Template.fromStack(stack);
template.hasResourceProperties('AWS::RDS::DBCluster', {
EnableLocalWriteForwarding: true,
});
});
});

Expand Down
Loading