-
Notifications
You must be signed in to change notification settings - Fork 32
/
sample-vpc-rds-stack.ts
46 lines (38 loc) · 1.78 KB
/
sample-vpc-rds-stack.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import * as cdk from 'aws-cdk-lib';
import * as ec2 from 'aws-cdk-lib/aws-ec2';
import * as rds from 'aws-cdk-lib/aws-rds';
import * as base from '../../lib/template/stack/vpc/vpc-base-stack';
import { Override } from '../../lib/template/stack/base/base-stack';
import { AppContext } from '../../lib/template/app-context';
import { StackConfig } from '../../lib/template/app-config'
export class SampleVpcRdsStack extends base.VpcBaseStack {
constructor(appContext: AppContext, stackConfig: StackConfig) {
super(appContext, stackConfig);
}
@Override
onLookupLegacyVpc(): base.VpcLegacyLookupProps | undefined {
return {
vpcNameLegacy: this.getVariable('VpcName')
};
}
@Override
onPostConstructor(baseVpc?: ec2.IVpc) {
const cluster = new rds.ServerlessCluster(this, 'serverless-rds', {
vpc: baseVpc!,
clusterIdentifier: this.withProjectPrefix(this.stackConfig.ClusterIdentifier),
defaultDatabaseName: this.stackConfig.DatabaseName,
engine: rds.DatabaseClusterEngine.AURORA_MYSQL,
scaling: {
autoPause: cdk.Duration.minutes(10),
minCapacity: rds.AuroraCapacityUnit.ACU_8,
maxCapacity: rds.AuroraCapacityUnit.ACU_32,
},
removalPolicy: cdk.RemovalPolicy.RETAIN,
});
this.putParameter('DatabaseHostName', cluster.clusterEndpoint.hostname);
this.putParameter('DatabaseAddress', cluster.clusterEndpoint.socketAddress);
this.putParameter('DatabaseName', this.stackConfig.DatabaseName);
this.putParameter('DatabaseSecretArn', cluster.secret?.secretArn!);
this.putParameter('DatabaseSecurityGroup', cluster.connections.securityGroups[0].securityGroupId);
}
}