@@ -137,12 +137,18 @@ export class Aurora extends Stack {
137137//export class Aurora extends Construct {
138138 constructor ( scope : Construct , id : string , props :AuroraProps ) {
139139 //constructor(scope: Construct, id: string, props?: cdk.StackProps) {
140- super ( scope , id ) ;
140+ super ( scope , id , props ) ;
141+
142+ // Validate required props
143+ if ( ! props . vpcId || ! props . subnetIds ?. length ) {
144+ throw new Error ( 'vpcId and subnetIds are required' ) ;
145+ }
141146
142147 let subnetIds = props . subnetIds ;
143148 let instanceType = props . instanceType ;
144149 let replicaInstances = props . replicaInstances ?? 1 ;
145150 let backupRetentionDays = props . backupRetentionDays ?? 14 ;
151+ let auroraClusterUsername = props . auroraClusterUsername ?? 'clusteradmin' ;
146152
147153 let ingressSources = [ ] ;
148154 if ( typeof props . ingressSources !== 'undefined' ) {
@@ -223,12 +229,12 @@ export class Aurora extends Stack {
223229
224230 // Declaring postgres engine
225231 let auroraEngine = rds . DatabaseClusterEngine . auroraPostgres ( {
226- version : rds . AuroraPostgresEngineVersion . VER_13_4 ,
232+ version : rds . AuroraPostgresEngineVersion . VER_15_4 ,
227233 } ) ;
228234
229235 if ( props . engine == 'mysql' ) {
230236 auroraEngine = rds . DatabaseClusterEngine . auroraMysql ( {
231- version : rds . AuroraMysqlEngineVersion . VER_2_10_1 ,
237+ version : rds . AuroraMysqlEngineVersion . VER_3_04_0 ,
232238 } ) ;
233239 }
234240
@@ -254,20 +260,20 @@ export class Aurora extends Stack {
254260 'AuroraClusterCredentials' ,
255261 {
256262 secretName : props . dbName + 'AuroraClusterCredentials' ,
257- description : props . dbName + 'AuroraClusterCrendetials ' ,
263+ description : props . dbName + 'AuroraClusterCredentials ' ,
258264 generateSecretString : {
259265 excludeCharacters : "\"@/\\ '" ,
260266 generateStringKey : 'password' ,
261267 passwordLength : 30 ,
262- secretStringTemplate : JSON . stringify ( { username : props . auroraClusterUsername } ) ,
268+ secretStringTemplate : JSON . stringify ( { username : auroraClusterUsername } ) ,
263269 } ,
264270 } ,
265271 ) ;
266272
267273 // aurora credentials
268274 const auroraClusterCrendentials = rds . Credentials . fromSecret (
269275 auroraClusterSecret ,
270- props . auroraClusterUsername ,
276+ auroraClusterUsername ,
271277 ) ;
272278
273279 if ( instanceType == null || instanceType == undefined ) {
@@ -296,7 +302,17 @@ export class Aurora extends Stack {
296302 retention : Duration . days ( backupRetentionDays ) ,
297303 } ,
298304 parameterGroup : auroraParameterGroup ,
299- instances : replicaInstances ,
305+ writer : rds . ClusterInstance . provisioned ( 'writer' , {
306+ instanceType : instanceType ,
307+ } ) ,
308+ readers : Array . from ( { length : replicaInstances - 1 } , ( _ , i ) =>
309+ rds . ClusterInstance . provisioned ( `reader${ i + 1 } ` , {
310+ instanceType : instanceType ,
311+ } )
312+ ) ,
313+ vpc : vpc ,
314+ vpcSubnets : vpcSubnets ,
315+ securityGroups : [ dbsg ] ,
300316 iamAuthentication : true ,
301317 storageEncrypted : true ,
302318 storageEncryptionKey : kmsKey ,
@@ -306,13 +322,7 @@ export class Aurora extends Stack {
306322 cloudwatchLogsExports : cloudwatchLogsExports ,
307323 cloudwatchLogsRetention : logs . RetentionDays . ONE_MONTH ,
308324 preferredMaintenanceWindow : props . preferredMaintenanceWindow ,
309- instanceIdentifierBase : props . dbName ,
310- instanceProps : {
311- instanceType : props . instanceType ,
312- vpcSubnets : vpcSubnets ,
313- vpc : vpc ,
314- securityGroups : [ dbsg ] ,
315- } ,
325+ clusterIdentifier : props . dbName ,
316326 } ) ;
317327
318328 aurora_cluster . applyRemovalPolicy ( RemovalPolicy . RETAIN ) ;
@@ -515,11 +525,13 @@ const app = new App();
515525
516526new Aurora ( app , 'AuroraStack' , {
517527 env :{ region :"us-east-2" } , description :"Aurora Stack" ,
518- vpcId :"vpc-xxx " ,
519- subnetIds :[ "subnet-xxx " , "subnet-xxxxSS " ] ,
528+ vpcId :"vpc-xxxxxxxxxx " ,
529+ subnetIds :[ "subnet-xxxxxx " , "subnet-yyyyyyyy " ] ,
520530 dbName :"sampledb" ,
521531 engine :"postgresql"
522532} ) ;
523533
534+ app . synth ( ) ;
535+
524536
525537
0 commit comments