Skip to content

Commit 8266254

Browse files
author
Sunil Yadav
committed
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
1 parent f968615 commit 8266254

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

typescript/rds/aurora/aurora.ts

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -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) {
@@ -308,7 +314,7 @@ export class Aurora extends Stack {
308314
preferredMaintenanceWindow: props.preferredMaintenanceWindow,
309315
instanceIdentifierBase: props.dbName,
310316
instanceProps: {
311-
instanceType: props.instanceType,
317+
instanceType: instanceType,
312318
vpcSubnets: vpcSubnets,
313319
vpc: vpc,
314320
securityGroups: [dbsg],
@@ -521,5 +527,7 @@ new Aurora(app, 'AuroraStack', {
521527
engine:"postgresql"
522528
});
523529

530+
app.synth();
531+
524532

525533

0 commit comments

Comments
 (0)