@digitraffic/common 2025.9.22-1 → 2025.9.24-2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import { type InstanceType, type ISecurityGroup, type IVpc } from "aws-cdk-lib/aws-ec2";
|
|
2
2
|
import { type AuroraPostgresEngineVersion, DatabaseCluster, type DatabaseClusterProps, type IParameterGroup } from "aws-cdk-lib/aws-rds";
|
|
3
|
+
import { Key } from "aws-cdk-lib/aws-kms";
|
|
3
4
|
import { Stack } from "aws-cdk-lib/core";
|
|
4
5
|
import type { Construct } from "constructs/lib/construct.js";
|
|
5
6
|
import type { InfraStackConfiguration } from "./intra-stack-configuration.js";
|
|
6
7
|
export interface DbConfiguration {
|
|
7
8
|
readonly cluster?: ClusterConfiguration;
|
|
8
9
|
readonly clusterImport?: ClusterImportConfiguration;
|
|
10
|
+
readonly storageEncrypted?: boolean;
|
|
9
11
|
readonly customParameterGroups: AuroraPostgresEngineVersion[];
|
|
10
12
|
readonly workmem?: number;
|
|
11
13
|
/** superuser username and password are fetched from this secret, using keys
|
|
@@ -23,7 +25,6 @@ export interface ClusterConfiguration {
|
|
|
23
25
|
readonly securityGroupId: string;
|
|
24
26
|
readonly snapshotIdentifier?: string;
|
|
25
27
|
readonly dbVersion: AuroraPostgresEngineVersion;
|
|
26
|
-
readonly storageEncrypted?: boolean;
|
|
27
28
|
readonly writer: ClusterDbInstanceConfiguration;
|
|
28
29
|
readonly readers: ClusterDbInstanceConfiguration[];
|
|
29
30
|
}
|
|
@@ -57,6 +58,7 @@ export declare class DbStack extends Stack {
|
|
|
57
58
|
clusterIdentifier: string;
|
|
58
59
|
constructor(scope: Construct, id: string, isc: InfraStackConfiguration, configuration: DbConfiguration);
|
|
59
60
|
createParameterGroups(customVersions: AuroraPostgresEngineVersion[], workmem: number): IParameterGroup[];
|
|
60
|
-
createClusterParameters(secretArn: string, clusterConfiguration: ClusterConfiguration, instanceName: string, vpc: IVpc, securityGroup: ISecurityGroup, parameterGroup: IParameterGroup): DatabaseClusterProps;
|
|
61
|
-
|
|
61
|
+
createClusterParameters(secretArn: string, clusterConfiguration: ClusterConfiguration, instanceName: string, vpc: IVpc, securityGroup: ISecurityGroup, parameterGroup: IParameterGroup, storageEncrypted: boolean | undefined, rdsKey: Key | undefined): DatabaseClusterProps;
|
|
62
|
+
createRDSKey(instanceName: string, environmentName: string): Key;
|
|
63
|
+
createAuroraCluster(isc: InfraStackConfiguration, configuration: DbConfiguration, clusterConfiguration: ClusterConfiguration, parameterGroups: IParameterGroup[], instanceName: string, rdsKey: Key | undefined): DatabaseCluster;
|
|
62
64
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { SecurityGroup, SubnetType, } from "aws-cdk-lib/aws-ec2";
|
|
2
2
|
import { CfnDBInstance, ClusterInstance, Credentials, DatabaseCluster, DatabaseClusterEngine, DatabaseClusterFromSnapshot, InstanceUpdateBehaviour, ParameterGroup, } from "aws-cdk-lib/aws-rds";
|
|
3
3
|
import { Secret } from "aws-cdk-lib/aws-secretsmanager";
|
|
4
|
+
import { Key } from "aws-cdk-lib/aws-kms";
|
|
4
5
|
import { Duration, RemovalPolicy, Stack } from "aws-cdk-lib/core";
|
|
5
6
|
import { exportValue, importVpc } from "../import-util.js";
|
|
6
7
|
import { createParameter } from "../stack/parameters.js";
|
|
@@ -50,9 +51,13 @@ export class DbStack extends Stack {
|
|
|
50
51
|
(!configuration.cluster && !configuration.clusterImport)) {
|
|
51
52
|
throw new Error("Configure either cluster or clusterImport");
|
|
52
53
|
}
|
|
54
|
+
const instanceName = isc.environmentName + "-db";
|
|
55
|
+
const rdsKey = configuration?.storageEncrypted
|
|
56
|
+
? this.createRDSKey(instanceName, isc.environmentName)
|
|
57
|
+
: undefined;
|
|
53
58
|
// create cluster if this is wanted, should do it only once
|
|
54
59
|
if (configuration.cluster) {
|
|
55
|
-
const cluster = this.createAuroraCluster(isc, configuration, configuration.cluster, parameterGroups);
|
|
60
|
+
const cluster = this.createAuroraCluster(isc, configuration, configuration.cluster, parameterGroups, instanceName, rdsKey);
|
|
56
61
|
exportValue(this, isc.environmentName, DbStack.CLUSTER_IDENTIFIER_EXPORT_NAME, cluster.clusterIdentifier);
|
|
57
62
|
exportValue(this, isc.environmentName, DbStack.CLUSTER_WRITE_ENDPOINT_EXPORT_NAME, cluster.clusterEndpoint.hostname);
|
|
58
63
|
exportValue(this, isc.environmentName, DbStack.CLUSTER_READ_ENDPOINT_EXPORT_NAME, cluster.clusterReadEndpoint.hostname);
|
|
@@ -86,7 +91,7 @@ export class DbStack extends Stack {
|
|
|
86
91
|
return pg;
|
|
87
92
|
});
|
|
88
93
|
}
|
|
89
|
-
createClusterParameters(secretArn, clusterConfiguration, instanceName, vpc, securityGroup, parameterGroup) {
|
|
94
|
+
createClusterParameters(secretArn, clusterConfiguration, instanceName, vpc, securityGroup, parameterGroup, storageEncrypted, rdsKey) {
|
|
90
95
|
const secret = Secret.fromSecretCompleteArn(this, "DBSecret", secretArn);
|
|
91
96
|
const defaultDbInstanceProps = {
|
|
92
97
|
autoMinorVersionUpgrade: true,
|
|
@@ -133,11 +138,20 @@ export class DbStack extends Stack {
|
|
|
133
138
|
credentials: Credentials.fromPassword(secret.secretValueFromJson("db.superuser").unsafeUnwrap(), secret.secretValueFromJson("db.superuser.password")),
|
|
134
139
|
parameterGroup,
|
|
135
140
|
monitoringInterval: Duration.seconds(30),
|
|
136
|
-
storageEncrypted:
|
|
141
|
+
storageEncrypted: storageEncrypted ?? true,
|
|
142
|
+
...(rdsKey ? { storageEncryptionKey: rdsKey } : {}),
|
|
137
143
|
};
|
|
138
144
|
}
|
|
139
|
-
|
|
140
|
-
|
|
145
|
+
createRDSKey(instanceName, environmentName) {
|
|
146
|
+
return new Key(this, "RDSKey", {
|
|
147
|
+
alias: `${environmentName}/db`,
|
|
148
|
+
enableKeyRotation: true,
|
|
149
|
+
description: `KMS key for RDS cluster ${instanceName}`,
|
|
150
|
+
removalPolicy: RemovalPolicy.RETAIN,
|
|
151
|
+
pendingWindow: Duration.days(30),
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
createAuroraCluster(isc, configuration, clusterConfiguration, parameterGroups, instanceName, rdsKey) {
|
|
141
155
|
const securityGroup = SecurityGroup.fromSecurityGroupId(this, "securitygroup", clusterConfiguration.securityGroupId);
|
|
142
156
|
const vpc = configuration.vpc
|
|
143
157
|
? configuration.vpc
|
|
@@ -145,16 +159,19 @@ export class DbStack extends Stack {
|
|
|
145
159
|
if (parameterGroups[0] === undefined) {
|
|
146
160
|
throw Error("ParameterGroups should not be empty");
|
|
147
161
|
}
|
|
148
|
-
const parameters = this.createClusterParameters(configuration.secretArn, clusterConfiguration, instanceName, vpc, securityGroup, parameterGroups[0]);
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
162
|
+
const parameters = this.createClusterParameters(configuration.secretArn, clusterConfiguration, instanceName, vpc, securityGroup, parameterGroups[0], configuration.storageEncrypted, rdsKey);
|
|
163
|
+
let cluster;
|
|
164
|
+
if (clusterConfiguration.snapshotIdentifier) {
|
|
165
|
+
cluster = new DatabaseClusterFromSnapshot(this, instanceName, {
|
|
152
166
|
...parameters,
|
|
153
167
|
...{
|
|
154
168
|
snapshotIdentifier: clusterConfiguration.snapshotIdentifier,
|
|
155
169
|
},
|
|
156
|
-
})
|
|
157
|
-
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
else {
|
|
173
|
+
cluster = new DatabaseCluster(this, instanceName, parameters);
|
|
174
|
+
}
|
|
158
175
|
// this workaround should prevent stack failing on version upgrade
|
|
159
176
|
// https://github.com/aws/aws-cdk/issues/21758
|
|
160
177
|
// https://github.com/aws/aws-cdk/pull/22185
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@digitraffic/common",
|
|
3
|
-
"version": "2025.9.
|
|
3
|
+
"version": "2025.9.24-2",
|
|
4
4
|
"description": "",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"repository": {
|
|
@@ -127,19 +127,19 @@
|
|
|
127
127
|
"zod": "^3.25.76"
|
|
128
128
|
},
|
|
129
129
|
"devDependencies": {
|
|
130
|
-
"@aws-sdk/client-api-gateway": "^3.
|
|
131
|
-
"@aws-sdk/client-s3": "^3.
|
|
132
|
-
"@aws-sdk/client-secrets-manager": "^3.
|
|
133
|
-
"@aws-sdk/client-sns": "^3.
|
|
134
|
-
"@aws-sdk/lib-storage": "^3.
|
|
130
|
+
"@aws-sdk/client-api-gateway": "^3.895.0",
|
|
131
|
+
"@aws-sdk/client-s3": "^3.895.0",
|
|
132
|
+
"@aws-sdk/client-secrets-manager": "^3.895.0",
|
|
133
|
+
"@aws-sdk/client-sns": "^3.895.0",
|
|
134
|
+
"@aws-sdk/lib-storage": "^3.895.0",
|
|
135
135
|
"@date-fns/tz": "^1.4.1",
|
|
136
136
|
"@digitraffic/eslint-config": "^3.2.5",
|
|
137
137
|
"@jest/globals": "^30.1.2",
|
|
138
138
|
"@rushstack/eslint-config": "^4.4.0",
|
|
139
|
-
"@rushstack/heft": "^0.74.
|
|
140
|
-
"@rushstack/heft-jest-plugin": "^0.16.
|
|
141
|
-
"@rushstack/heft-lint-plugin": "^0.7.
|
|
142
|
-
"@rushstack/heft-typescript-plugin": "^0.9.
|
|
139
|
+
"@rushstack/heft": "^0.74.5",
|
|
140
|
+
"@rushstack/heft-jest-plugin": "^0.16.14",
|
|
141
|
+
"@rushstack/heft-lint-plugin": "^0.7.6",
|
|
142
|
+
"@rushstack/heft-typescript-plugin": "^0.9.14",
|
|
143
143
|
"@smithy/fetch-http-handler": "^5.2.1",
|
|
144
144
|
"@smithy/types": "^4.5.0",
|
|
145
145
|
"@types/aws-lambda": "8.10.152",
|
|
@@ -150,9 +150,9 @@
|
|
|
150
150
|
"@types/lodash-es": "4.17.12",
|
|
151
151
|
"@types/madge": "5.0.3",
|
|
152
152
|
"@types/node": "22.18.1",
|
|
153
|
-
"@typescript-eslint/eslint-plugin": "^8.
|
|
154
|
-
"@typescript-eslint/parser": "^8.
|
|
155
|
-
"aws-cdk-lib": "^2.
|
|
153
|
+
"@typescript-eslint/eslint-plugin": "^8.44.1",
|
|
154
|
+
"@typescript-eslint/parser": "^8.44.1",
|
|
155
|
+
"aws-cdk-lib": "^2.216.0",
|
|
156
156
|
"aws-sdk": "^2.1692.0",
|
|
157
157
|
"change-case": "^5.4.4",
|
|
158
158
|
"constructs": "^10.4.2",
|
|
@@ -165,7 +165,7 @@
|
|
|
165
165
|
"jest": "^30.1.3",
|
|
166
166
|
"jest-junit": "^16.0.0",
|
|
167
167
|
"ky": "^1.10.0",
|
|
168
|
-
"lefthook": "^1.13.
|
|
168
|
+
"lefthook": "^1.13.4",
|
|
169
169
|
"lodash": "^4.17.21",
|
|
170
170
|
"lodash-es": "^4.17.21",
|
|
171
171
|
"madge": "^8.0.0",
|
|
@@ -173,10 +173,10 @@
|
|
|
173
173
|
"pg-promise": "^12.1.3",
|
|
174
174
|
"pg-query-stream": "^4.10.3",
|
|
175
175
|
"rimraf": "^6.0.1",
|
|
176
|
-
"ts-jest": "^29.4.
|
|
176
|
+
"ts-jest": "^29.4.4",
|
|
177
177
|
"typescript": "^5.9.2",
|
|
178
178
|
"velocityjs": "^2.1.5",
|
|
179
|
-
"zod": "^4.1.
|
|
179
|
+
"zod": "^4.1.11"
|
|
180
180
|
},
|
|
181
181
|
"scripts": {
|
|
182
182
|
"build": "heft build --clean",
|