-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathinstance.ts
25 lines (22 loc) · 1.01 KB
/
instance.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
import { Fn } from "aws-cdk-lib";
import { InstanceType } from "aws-cdk-lib/aws-ec2";
import { DatabaseInstance } from "aws-cdk-lib/aws-rds";
import type { DatabaseInstanceProps } from "aws-cdk-lib/aws-rds";
import { GuAppAwareConstruct } from "../../utils/mixin/app-aware-construct";
import type { AppIdentity, GuStack } from "../core";
export interface GuDatabaseInstanceProps extends Omit<DatabaseInstanceProps, "instanceType">, AppIdentity {
instanceType: string;
}
export class GuDatabaseInstance extends GuAppAwareConstruct(DatabaseInstance) {
constructor(scope: GuStack, id: string, props: GuDatabaseInstanceProps) {
// CDK just wants "t3.micro" format, whereas
// some CFN yaml might have the older "db.t3.micro" with the "db." prefix
// This logic ensures the "db." prefix is removed before applying the CFN
const instanceType = new InstanceType(Fn.join("", Fn.split("db.", props.instanceType)));
super(scope, id, {
deletionProtection: true,
...props,
instanceType,
});
}
}