From 82662549f1d3c9de43881d28aa654743de2c59b5 Mon Sep 17 00:00:00 2001 From: Sunil Yadav Date: Thu, 4 Sep 2025 14:43:38 +0100 Subject: [PATCH 1/3] fix: resolve critical Aurora CDK issues - Add validation for required vpcId and subnetIds props - Set default username to 'clusteradmin' when not provided - Update to latest Aurora engine versions (PostgreSQL 15.4, MySQL 3.04.0) - Fix typo in secret description (Crendetials -> Credentials) - Use validated instanceType variable in cluster creation - Add app.synth() call to generate CloudFormation templates - Update example with realistic placeholder values --- typescript/rds/aurora/aurora.ts | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/typescript/rds/aurora/aurora.ts b/typescript/rds/aurora/aurora.ts index 9fab0d4ae3..8a2f0b0e79 100644 --- a/typescript/rds/aurora/aurora.ts +++ b/typescript/rds/aurora/aurora.ts @@ -137,12 +137,18 @@ export class Aurora extends Stack { //export class Aurora extends Construct { constructor(scope: Construct, id: string, props:AuroraProps) { //constructor(scope: Construct, id: string, props?: cdk.StackProps) { - super(scope, id); + super(scope, id, props); + + // Validate required props + if (!props.vpcId || !props.subnetIds?.length) { + throw new Error('vpcId and subnetIds are required'); + } let subnetIds = props.subnetIds; let instanceType = props.instanceType; let replicaInstances = props.replicaInstances ?? 1; let backupRetentionDays = props.backupRetentionDays ?? 14; + let auroraClusterUsername = props.auroraClusterUsername ?? 'clusteradmin'; let ingressSources = []; if (typeof props.ingressSources !== 'undefined') { @@ -223,12 +229,12 @@ export class Aurora extends Stack { // Declaring postgres engine let auroraEngine = rds.DatabaseClusterEngine.auroraPostgres({ - version: rds.AuroraPostgresEngineVersion.VER_13_4, + version: rds.AuroraPostgresEngineVersion.VER_15_4, }); if (props.engine == 'mysql') { auroraEngine = rds.DatabaseClusterEngine.auroraMysql({ - version: rds.AuroraMysqlEngineVersion.VER_2_10_1, + version: rds.AuroraMysqlEngineVersion.VER_3_04_0, }); } @@ -254,12 +260,12 @@ export class Aurora extends Stack { 'AuroraClusterCredentials', { secretName: props.dbName + 'AuroraClusterCredentials', - description: props.dbName + 'AuroraClusterCrendetials', + description: props.dbName + 'AuroraClusterCredentials', generateSecretString: { excludeCharacters: "\"@/\\ '", generateStringKey: 'password', passwordLength: 30, - secretStringTemplate: JSON.stringify({username: props.auroraClusterUsername}), + secretStringTemplate: JSON.stringify({username: auroraClusterUsername}), }, }, ); @@ -267,7 +273,7 @@ export class Aurora extends Stack { // aurora credentials const auroraClusterCrendentials= rds.Credentials.fromSecret( auroraClusterSecret, - props.auroraClusterUsername, + auroraClusterUsername, ); if (instanceType == null || instanceType == undefined) { @@ -308,7 +314,7 @@ export class Aurora extends Stack { preferredMaintenanceWindow: props.preferredMaintenanceWindow, instanceIdentifierBase: props.dbName, instanceProps: { - instanceType: props.instanceType, + instanceType: instanceType, vpcSubnets: vpcSubnets, vpc: vpc, securityGroups: [dbsg], @@ -521,5 +527,7 @@ new Aurora(app, 'AuroraStack', { engine:"postgresql" }); +app.synth(); + From ac38516d81971e2a97e7f2c884f2cc6c5fe65e98 Mon Sep 17 00:00:00 2001 From: Sunil Yadav Date: Thu, 4 Sep 2025 15:11:11 +0100 Subject: [PATCH 2/3] fix: replace deprecated instanceProps with writer/readers - Use new writer and readers properties instead of deprecated instanceProps - Create writer instance and reader instances based on replicaInstances count - Move vpc, vpcSubnets, and securityGroups to cluster level - Replace instanceIdentifierBase with clusterIdentifier --- typescript/rds/aurora/aurora.ts | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/typescript/rds/aurora/aurora.ts b/typescript/rds/aurora/aurora.ts index 8a2f0b0e79..7af75e2208 100644 --- a/typescript/rds/aurora/aurora.ts +++ b/typescript/rds/aurora/aurora.ts @@ -302,7 +302,17 @@ export class Aurora extends Stack { retention: Duration.days(backupRetentionDays), }, parameterGroup: auroraParameterGroup, - instances: replicaInstances, + writer: rds.ClusterInstance.provisioned('writer', { + instanceType: instanceType, + }), + readers: Array.from({ length: replicaInstances - 1 }, (_, i) => + rds.ClusterInstance.provisioned(`reader${i + 1}`, { + instanceType: instanceType, + }) + ), + vpc: vpc, + vpcSubnets: vpcSubnets, + securityGroups: [dbsg], iamAuthentication: true, storageEncrypted: true, storageEncryptionKey: kmsKey, @@ -312,13 +322,7 @@ export class Aurora extends Stack { cloudwatchLogsExports: cloudwatchLogsExports, cloudwatchLogsRetention: logs.RetentionDays.ONE_MONTH, preferredMaintenanceWindow: props.preferredMaintenanceWindow, - instanceIdentifierBase: props.dbName, - instanceProps: { - instanceType: instanceType, - vpcSubnets: vpcSubnets, - vpc: vpc, - securityGroups: [dbsg], - }, + clusterIdentifier: props.dbName, }); aurora_cluster.applyRemovalPolicy(RemovalPolicy.RETAIN); @@ -521,8 +525,8 @@ const app = new App(); new Aurora(app, 'AuroraStack', { env:{region:"us-east-2"}, description:"Aurora Stack", - vpcId:"vpc-xxx", - subnetIds:["subnet-xxx", "subnet-xxxxSS"], + vpcId:"vpc-xxxxxxxxxx", + subnetIds:["subnet-xxxxxx", "subnet-xxxxxx"], dbName:"sampledb", engine:"postgresql" }); From b4f8256ac735cf4500bb1b518ec22805212a2a9e Mon Sep 17 00:00:00 2001 From: Sunil Yadav Date: Sun, 21 Sep 2025 21:13:17 +0100 Subject: [PATCH 3/3] fix: update subnet_id to avoid construct conflict --- typescript/rds/aurora/aurora.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/typescript/rds/aurora/aurora.ts b/typescript/rds/aurora/aurora.ts index 7af75e2208..dc21b8c957 100644 --- a/typescript/rds/aurora/aurora.ts +++ b/typescript/rds/aurora/aurora.ts @@ -526,7 +526,7 @@ const app = new App(); new Aurora(app, 'AuroraStack', { env:{region:"us-east-2"}, description:"Aurora Stack", vpcId:"vpc-xxxxxxxxxx", - subnetIds:["subnet-xxxxxx", "subnet-xxxxxx"], + subnetIds:["subnet-xxxxxx", "subnet-yyyyyyyy"], dbName:"sampledb", engine:"postgresql" });