in cdk/lib/rds-stack.ts [34:110]
constructor(scope: Construct, id: string, props: RDSStackProps) {
super(scope, id, props);
const dbId = `postgres-rds-instance-${props.stage}`;
const rdsInstanceType = InstanceType.of(InstanceClass.M5, InstanceSize.LARGE);
const pwdSecretName = "rds-password";
if(props.primaryRdsInstance) {
this.postgresRDSInstance = new DatabaseInstanceReadReplica(this, dbId, {
instanceIdentifier: dbId,
sourceDatabaseInstance: props.primaryRdsInstance,
vpc: props.vpc,
securityGroups: [props.securityGroup],
vpcPlacement: { subnetType: SubnetType.ISOLATED },
multiAz: false,
instanceType: rdsInstanceType,
storageType: StorageType.GP2,
port: this.rdsPort,
});
} else {
const rdsPasswordSecret = new Secret(this, pwdSecretName, {
secretName: pwdSecretName,
replicaRegions: props.secretReplicationRegions.map(x => {return {region: x}}),
generateSecretString: {
excludeCharacters: `/@" `,
excludePunctuation: true,
includeSpace: false,
excludeNumbers: false,
excludeLowercase: false,
excludeUppercase: false,
passwordLength: 24
}
});
this.postgresRDSInstance = new DatabaseInstance(this, dbId,
{
instanceIdentifier: dbId,
instanceType: rdsInstanceType,
engine: DatabaseInstanceEngine.postgres({
version: PostgresEngineVersion.VER_10_17,
}),
vpc: props.vpc,
credentials: {
username: this.rdsDbUser,
password: rdsPasswordSecret.secretValue,
},
securityGroups: [props.securityGroup],
vpcPlacement: { subnetType: SubnetType.ISOLATED },
multiAz: false,
allocatedStorage: 25,
storageType: StorageType.GP2,
databaseName: this.rdsDbName,
port: this.rdsPort,
}
);
}
this.rdsDatabasePasswordSecretName = new CfnOutput(this, "rdsDatabasePasswordSecretName", {
value: pwdSecretName,
description: "Secret Manager secret name for RDS instance password"
});
this.rdsEndpointOutput = new CfnOutput(this, "rdsEndpoint", {
value: this.postgresRDSInstance.instanceEndpoint.socketAddress,
description: "Endpoint to access RDS instance"
});
this.rdsUsernameOutput = new CfnOutput(this, "rdsUsername", {
value: this.rdsDbUser,
description: "Root user of RDS instance"
});
this.rdsDatabaseOutput = new CfnOutput(this, "rdsDatabase", {
value: this.rdsDbName,
description: "Default database of RDS instance"
});
}