@digitraffic/common 2024.1.24-3 → 2024.1.30-1
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.
- package/dist/__test__/api/handler-factory.test.d.mts +1 -0
- package/dist/__test__/api/handler-factory.test.mjs +43 -0
- package/dist/__test__/api/response.test.d.mts +1 -0
- package/dist/__test__/api/response.test.mjs +86 -0
- package/dist/__test__/imports.test.d.mts +1 -0
- package/dist/__test__/imports.test.mjs +332 -0
- package/dist/__test__/marine/id_utils.test.d.mts +1 -0
- package/dist/__test__/marine/id_utils.test.mjs +44 -0
- package/dist/__test__/promise/promise.test.d.mts +1 -0
- package/dist/__test__/promise/promise.test.mjs +130 -0
- package/dist/__test__/runtime/dt-logger.test.d.mts +1 -0
- package/dist/__test__/runtime/dt-logger.test.mjs +108 -0
- package/dist/__test__/secrets/secret-holder.test.d.mts +1 -0
- package/dist/__test__/secrets/secret-holder.test.mjs +89 -0
- package/dist/__test__/secrets/secret.test.d.mts +1 -0
- package/dist/__test__/secrets/secret.test.mjs +42 -0
- package/dist/__test__/test/httpserver.test.d.mts +1 -0
- package/dist/__test__/test/httpserver.test.mjs +154 -0
- package/dist/__test__/types/lambda-response.test.d.mts +1 -0
- package/dist/__test__/types/lambda-response.test.mjs +58 -0
- package/dist/__test__/utils/date-utils.test.d.mts +1 -0
- package/dist/__test__/utils/date-utils.test.mjs +27 -0
- package/dist/__test__/utils/geometry.test.d.mts +1 -0
- package/dist/__test__/utils/geometry.test.mjs +24 -0
- package/dist/__test__/utils/logging.test.d.mts +1 -0
- package/dist/__test__/utils/logging.test.mjs +78 -0
- package/dist/__test__/utils/utils.test.d.mts +1 -0
- package/dist/__test__/utils/utils.test.mjs +43 -0
- package/dist/aws/infra/api/handler-factory.mjs +4 -0
- package/dist/aws/infra/api/integration.d.mts +2 -2
- package/dist/aws/infra/api/integration.mjs +4 -1
- package/dist/aws/infra/api/response.d.mts +1 -1
- package/dist/aws/infra/api/responses.d.mts +1 -1
- package/dist/aws/infra/api/responses.mjs +2 -0
- package/dist/aws/infra/api/static-integration.mjs +1 -1
- package/dist/aws/infra/canaries/canary-alarm.d.mts +1 -1
- package/dist/aws/infra/canaries/canary-alarm.mjs +2 -0
- package/dist/aws/infra/canaries/canary-parameters.mjs +1 -1
- package/dist/aws/infra/canaries/canary-role.mjs +1 -0
- package/dist/aws/infra/canaries/canary.d.mts +2 -2
- package/dist/aws/infra/canaries/canary.mjs +2 -0
- package/dist/aws/infra/canaries/database-canary.d.mts +2 -2
- package/dist/aws/infra/canaries/database-canary.mjs +2 -0
- package/dist/aws/infra/canaries/database-checker.d.mts +1 -1
- package/dist/aws/infra/canaries/database-checker.mjs +7 -1
- package/dist/aws/infra/canaries/url-canary.d.mts +2 -2
- package/dist/aws/infra/canaries/url-canary.mjs +3 -0
- package/dist/aws/infra/canaries/url-checker.d.mts +1 -1
- package/dist/aws/infra/canaries/url-checker.mjs +4 -1
- package/dist/aws/infra/documentation.mjs +5 -1
- package/dist/aws/infra/import-util.d.mts +1 -1
- package/dist/aws/infra/import-util.mjs +4 -3
- package/dist/aws/infra/scheduler.mjs +2 -0
- package/dist/aws/infra/security-rule.d.mts +1 -1
- package/dist/aws/infra/security-rule.mjs +1 -0
- package/dist/aws/infra/sqs-integration.d.mts +1 -1
- package/dist/aws/infra/sqs-integration.mjs +3 -1
- package/dist/aws/infra/sqs-queue.d.mts +1 -1
- package/dist/aws/infra/sqs-queue.mjs +2 -1
- package/dist/aws/infra/stack/lambda-configs.d.mts +4 -4
- package/dist/aws/infra/stack/lambda-configs.mjs +4 -2
- package/dist/aws/infra/stack/monitoredfunction.d.mts +3 -3
- package/dist/aws/infra/stack/monitoredfunction.mjs +20 -16
- package/dist/aws/infra/stack/parameters.mjs +1 -0
- package/dist/aws/infra/stack/rest_apis.d.mts +2 -2
- package/dist/aws/infra/stack/rest_apis.mjs +6 -1
- package/dist/aws/infra/stack/stack-checking-aspect.d.mts +2 -2
- package/dist/aws/infra/stack/stack-checking-aspect.mjs +6 -1
- package/dist/aws/infra/stack/stack.d.mts +5 -5
- package/dist/aws/infra/stack/stack.mjs +9 -0
- package/dist/aws/infra/stack/subscription.mjs +4 -0
- package/dist/aws/infra/stacks/db-dns-stack.d.mts +1 -1
- package/dist/aws/infra/stacks/db-dns-stack.mjs +1 -0
- package/dist/aws/infra/stacks/db-proxy-stack.d.mts +3 -3
- package/dist/aws/infra/stacks/db-proxy-stack.mjs +4 -2
- package/dist/aws/infra/stacks/db-stack.d.mts +3 -3
- package/dist/aws/infra/stacks/db-stack.mjs +11 -7
- package/dist/aws/infra/stacks/intra-stack-configuration.d.mts +1 -1
- package/dist/aws/infra/stacks/network-stack.d.mts +2 -2
- package/dist/aws/infra/stacks/network-stack.mjs +8 -0
- package/dist/aws/infra/usage-plans.d.mts +1 -1
- package/dist/aws/infra/usage-plans.mjs +1 -0
- package/dist/aws/runtime/apikey.d.mts +2 -2
- package/dist/aws/runtime/apikey.mjs +2 -1
- package/dist/aws/runtime/digitraffic-integration-response.d.mts +1 -1
- package/dist/aws/runtime/dt-logger.mjs +6 -2
- package/dist/aws/runtime/messaging.d.mts +2 -2
- package/dist/aws/runtime/s3.d.mts +2 -2
- package/dist/aws/runtime/s3.mjs +2 -1
- package/dist/aws/runtime/secrets/dbsecret.d.mts +1 -1
- package/dist/aws/runtime/secrets/proxy-holder.mjs +1 -0
- package/dist/aws/runtime/secrets/rds-holder.mjs +1 -0
- package/dist/aws/runtime/secrets/secret-holder.d.mts +1 -1
- package/dist/aws/runtime/secrets/secret-holder.mjs +6 -1
- package/dist/aws/runtime/secrets/secret.mjs +4 -2
- package/dist/aws/types/errors.mjs +1 -0
- package/dist/aws/types/lambda-response.mjs +5 -0
- package/dist/aws/types/model-with-reference.mjs +1 -1
- package/dist/database/cached.d.mts +1 -1
- package/dist/database/database.mjs +1 -0
- package/dist/database/last-updated.d.mts +1 -1
- package/dist/test/db-testutils.d.mts +1 -1
- package/dist/test/db-testutils.mjs +1 -1
- package/dist/test/httpserver.mjs +7 -3
- package/dist/test/secrets-manager.d.mts +1 -1
- package/dist/test/secrets-manager.mjs +1 -1
- package/dist/test/testutils.mjs +1 -1
- package/dist/types/http-error.mjs +1 -0
- package/dist/types/nullable.d.mts +1 -1
- package/dist/utils/api-model.d.mts +2 -2
- package/dist/utils/api-model.mjs +1 -1
- package/dist/utils/geojson-types.d.mts +1 -1
- package/dist/utils/geojson-types.mjs +4 -2
- package/dist/utils/geometry.d.mts +1 -1
- package/dist/utils/geometry.mjs +3 -0
- package/dist/utils/retry.d.mts +2 -2
- package/dist/utils/retry.mjs +2 -2
- package/dist/utils/slack.mjs +1 -0
- package/dist/utils/utils.d.mts +2 -2
- package/package.json +11 -6
- package/src/@types/geojson-validation/index.d.mts +0 -4
- package/src/aws/infra/api/handler-factory.mts +0 -86
- package/src/aws/infra/api/integration.mts +0 -147
- package/src/aws/infra/api/response.mts +0 -165
- package/src/aws/infra/api/responses.mts +0 -127
- package/src/aws/infra/api/static-integration.mts +0 -108
- package/src/aws/infra/canaries/Synthetics.d.mts +0 -21
- package/src/aws/infra/canaries/canary-alarm.mts +0 -33
- package/src/aws/infra/canaries/canary-keys.mts +0 -3
- package/src/aws/infra/canaries/canary-parameters.mts +0 -19
- package/src/aws/infra/canaries/canary-role.mts +0 -73
- package/src/aws/infra/canaries/canary.mts +0 -44
- package/src/aws/infra/canaries/database-canary.mts +0 -98
- package/src/aws/infra/canaries/database-checker.mts +0 -163
- package/src/aws/infra/canaries/url-canary.mts +0 -98
- package/src/aws/infra/canaries/url-checker.mts +0 -388
- package/src/aws/infra/documentation.mts +0 -142
- package/src/aws/infra/import-util.mts +0 -57
- package/src/aws/infra/scheduler.mts +0 -59
- package/src/aws/infra/security-rule.mts +0 -38
- package/src/aws/infra/sqs-integration.mts +0 -106
- package/src/aws/infra/sqs-queue.mts +0 -162
- package/src/aws/infra/stack/lambda-configs.mts +0 -135
- package/src/aws/infra/stack/monitoredfunction.mts +0 -352
- package/src/aws/infra/stack/parameters.mts +0 -74
- package/src/aws/infra/stack/rest_apis.mts +0 -322
- package/src/aws/infra/stack/stack-checking-aspect.mts +0 -233
- package/src/aws/infra/stack/stack.mts +0 -144
- package/src/aws/infra/stack/subscription.mts +0 -58
- package/src/aws/infra/stacks/db-dns-stack.mts +0 -77
- package/src/aws/infra/stacks/db-proxy-stack.mts +0 -134
- package/src/aws/infra/stacks/db-stack.mts +0 -292
- package/src/aws/infra/stacks/intra-stack-configuration.mts +0 -6
- package/src/aws/infra/stacks/network-stack.mts +0 -76
- package/src/aws/infra/usage-plans.mts +0 -50
- package/src/aws/runtime/apikey.mts +0 -9
- package/src/aws/runtime/digitraffic-integration-response.mts +0 -35
- package/src/aws/runtime/dt-logger-default.mts +0 -11
- package/src/aws/runtime/dt-logger.mts +0 -184
- package/src/aws/runtime/environment.mts +0 -22
- package/src/aws/runtime/messaging.mts +0 -26
- package/src/aws/runtime/s3.mts +0 -44
- package/src/aws/runtime/secrets/dbsecret.mts +0 -31
- package/src/aws/runtime/secrets/node-ttl.d.mts +0 -12
- package/src/aws/runtime/secrets/proxy-holder.mts +0 -34
- package/src/aws/runtime/secrets/rds-holder.mts +0 -34
- package/src/aws/runtime/secrets/secret-holder.mts +0 -106
- package/src/aws/runtime/secrets/secret.mts +0 -58
- package/src/aws/types/errors.mts +0 -14
- package/src/aws/types/lambda-response.mts +0 -100
- package/src/aws/types/mediatypes.mts +0 -12
- package/src/aws/types/model-with-reference.mts +0 -8
- package/src/aws/types/proxytypes.mts +0 -27
- package/src/aws/types/tags.mts +0 -3
- package/src/database/cached.mts +0 -64
- package/src/database/database.mts +0 -107
- package/src/database/last-updated.mts +0 -103
- package/src/database/models.mts +0 -7
- package/src/index.mts +0 -2
- package/src/marine/id_utils.mts +0 -30
- package/src/marine/rtz.mts +0 -57
- package/src/test/asserter.mts +0 -58
- package/src/test/db-testutils.mts +0 -52
- package/src/test/httpserver.mts +0 -111
- package/src/test/secrets-manager.mts +0 -37
- package/src/test/testutils.mts +0 -39
- package/src/types/async-timeout-error.mts +0 -5
- package/src/types/aws-env.mts +0 -3
- package/src/types/either.mts +0 -9
- package/src/types/http-error.mts +0 -8
- package/src/types/input-error.mts +0 -2
- package/src/types/language.mts +0 -3
- package/src/types/nullable.mts +0 -21
- package/src/types/traffictype.mts +0 -8
- package/src/types/urn.mts +0 -1
- package/src/types/util-types.mts +0 -10
- package/src/types/validator.mts +0 -10
- package/src/utils/api-model.mts +0 -133
- package/src/utils/base64.mts +0 -16
- package/src/utils/date-utils.mts +0 -53
- package/src/utils/geojson-types.mts +0 -22
- package/src/utils/geometry.mts +0 -171
- package/src/utils/logging.mts +0 -75
- package/src/utils/retry.mts +0 -200
- package/src/utils/slack.mts +0 -26
- package/src/utils/utils.mts +0 -184
@@ -1,58 +0,0 @@
|
|
1
|
-
import { CfnSubscriptionFilter } from "aws-cdk-lib/aws-logs";
|
2
|
-
import { Function as AWSFunction } from "aws-cdk-lib/aws-lambda";
|
3
|
-
import { DigitrafficStack } from "./stack.mjs";
|
4
|
-
import { Construct } from "constructs";
|
5
|
-
import { MonitoredFunction } from "./monitoredfunction.mjs";
|
6
|
-
|
7
|
-
/**
|
8
|
-
* Creates a subscription filter that subscribes to a Lambda Log Group and delivers the logs to another destination.
|
9
|
-
* https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-logs-subscriptionfilter.html
|
10
|
-
* @param lambda The Lambda function, needed to create a dependency
|
11
|
-
* @param lambdaName The Lambda name from which the Log Group name is derived
|
12
|
-
* @param logDestinationArn Destination for streamed logs
|
13
|
-
* @param stack CloudFormation stack
|
14
|
-
*/
|
15
|
-
export function createSubscription(
|
16
|
-
lambda: AWSFunction,
|
17
|
-
lambdaName: string,
|
18
|
-
logDestinationArn: string | undefined,
|
19
|
-
stack: Construct
|
20
|
-
): CfnSubscriptionFilter | undefined {
|
21
|
-
if (logDestinationArn == undefined) {
|
22
|
-
return undefined;
|
23
|
-
}
|
24
|
-
const filter = new CfnSubscriptionFilter(
|
25
|
-
stack,
|
26
|
-
`${lambdaName}LogsSubscription`,
|
27
|
-
{
|
28
|
-
logGroupName: `/aws/lambda/${lambdaName}`,
|
29
|
-
filterPattern: "",
|
30
|
-
destinationArn: logDestinationArn,
|
31
|
-
}
|
32
|
-
);
|
33
|
-
|
34
|
-
filter.node.addDependency(lambda);
|
35
|
-
|
36
|
-
return filter;
|
37
|
-
}
|
38
|
-
|
39
|
-
export class DigitrafficLogSubscriptions {
|
40
|
-
constructor(stack: DigitrafficStack, ...lambdas: MonitoredFunction[]) {
|
41
|
-
const destinationArn = stack.configuration.logsDestinationArn;
|
42
|
-
if (destinationArn !== undefined) {
|
43
|
-
lambdas.forEach((lambda) => {
|
44
|
-
const filter = new CfnSubscriptionFilter(
|
45
|
-
stack,
|
46
|
-
`${lambda.givenName}LogsSubscription`,
|
47
|
-
{
|
48
|
-
logGroupName: `/aws/lambda/${lambda.givenName}`,
|
49
|
-
filterPattern: "",
|
50
|
-
destinationArn,
|
51
|
-
}
|
52
|
-
);
|
53
|
-
|
54
|
-
filter.node.addDependency(lambda);
|
55
|
-
});
|
56
|
-
}
|
57
|
-
}
|
58
|
-
}
|
@@ -1,77 +0,0 @@
|
|
1
|
-
import { Duration, RemovalPolicy, Stack } from "aws-cdk-lib";
|
2
|
-
import { type Construct } from "constructs";
|
3
|
-
import {
|
4
|
-
PrivateHostedZone,
|
5
|
-
RecordSet,
|
6
|
-
RecordTarget,
|
7
|
-
RecordType,
|
8
|
-
} from "aws-cdk-lib/aws-route53";
|
9
|
-
import { InfraStackConfiguration } from "./intra-stack-configuration.mjs";
|
10
|
-
import { importVpc } from "../import-util.mjs";
|
11
|
-
import { getParameterValue } from "../stack/parameters.mjs";
|
12
|
-
|
13
|
-
const DEFAULT_RECORD_TTL = Duration.seconds(30);
|
14
|
-
|
15
|
-
/**
|
16
|
-
* Creates a dns local zone and creates records for cluster endpoints and proxy endpoints.
|
17
|
-
*
|
18
|
-
* Please note, that created PrivateHostedZone has RETAIN removalPolicy, so if you want to delete this stack,
|
19
|
-
* you must remove the zone by hand after.
|
20
|
-
*/
|
21
|
-
export class DbDnsStack extends Stack {
|
22
|
-
constructor(scope: Construct, id: string, isc: InfraStackConfiguration) {
|
23
|
-
super(scope, id, {
|
24
|
-
env: isc.env,
|
25
|
-
});
|
26
|
-
|
27
|
-
this.createDnsRecords(isc);
|
28
|
-
}
|
29
|
-
|
30
|
-
createDnsRecords(isc: InfraStackConfiguration) {
|
31
|
-
const vpc = importVpc(this, isc.environmentName);
|
32
|
-
const zone = new PrivateHostedZone(this, "DNSHostedZone", {
|
33
|
-
zoneName: isc.environmentName + ".local",
|
34
|
-
vpc,
|
35
|
-
});
|
36
|
-
|
37
|
-
zone.applyRemovalPolicy(RemovalPolicy.RETAIN);
|
38
|
-
|
39
|
-
const clusterReaderEndpoint = getParameterValue(this, "cluster.reader");
|
40
|
-
const clusterWriterEndpoint = getParameterValue(this, "cluster.writer");
|
41
|
-
|
42
|
-
const proxyReaderEndpoint = getParameterValue(this, "proxy.reader");
|
43
|
-
const proxyWriterEndpoint = getParameterValue(this, "proxy.writer");
|
44
|
-
|
45
|
-
new RecordSet(this, "ReaderRecord", {
|
46
|
-
recordType: RecordType.CNAME,
|
47
|
-
recordName: `db-ro.${isc.environmentName}.local`,
|
48
|
-
target: RecordTarget.fromValues(clusterReaderEndpoint),
|
49
|
-
ttl: DEFAULT_RECORD_TTL,
|
50
|
-
zone,
|
51
|
-
});
|
52
|
-
|
53
|
-
new RecordSet(this, "WriterRecord", {
|
54
|
-
recordType: RecordType.CNAME,
|
55
|
-
recordName: `db.${isc.environmentName}.local`,
|
56
|
-
target: RecordTarget.fromValues(clusterWriterEndpoint),
|
57
|
-
ttl: DEFAULT_RECORD_TTL,
|
58
|
-
zone,
|
59
|
-
});
|
60
|
-
|
61
|
-
new RecordSet(this, "ProxyReaderRecord", {
|
62
|
-
recordType: RecordType.CNAME,
|
63
|
-
recordName: `proxy-ro.${isc.environmentName}.local`,
|
64
|
-
target: RecordTarget.fromValues(proxyReaderEndpoint),
|
65
|
-
ttl: DEFAULT_RECORD_TTL,
|
66
|
-
zone,
|
67
|
-
});
|
68
|
-
|
69
|
-
new RecordSet(this, "ProxyWriterRecord", {
|
70
|
-
recordType: RecordType.CNAME,
|
71
|
-
recordName: `proxy.${isc.environmentName}.local`,
|
72
|
-
target: RecordTarget.fromValues(proxyWriterEndpoint),
|
73
|
-
ttl: DEFAULT_RECORD_TTL,
|
74
|
-
zone,
|
75
|
-
});
|
76
|
-
}
|
77
|
-
}
|
@@ -1,134 +0,0 @@
|
|
1
|
-
import {
|
2
|
-
CfnDBProxyEndpoint,
|
3
|
-
DatabaseCluster,
|
4
|
-
DatabaseClusterEngine,
|
5
|
-
DatabaseProxy,
|
6
|
-
ProxyTarget,
|
7
|
-
} from "aws-cdk-lib/aws-rds";
|
8
|
-
import { ISecret, Secret } from "aws-cdk-lib/aws-secretsmanager";
|
9
|
-
import { IVpc, SecurityGroup } from "aws-cdk-lib/aws-ec2";
|
10
|
-
import { InfraStackConfiguration } from "./intra-stack-configuration.mjs";
|
11
|
-
import { DbStack } from "./db-stack.mjs";
|
12
|
-
import { exportValue, importVpc } from "../import-util.mjs";
|
13
|
-
import { createParameter } from "../stack/parameters.mjs";
|
14
|
-
import { Stack, Duration } from "aws-cdk-lib/core";
|
15
|
-
import { Construct } from "constructs/lib/construct.js";
|
16
|
-
|
17
|
-
export interface ProxyConfiguration {
|
18
|
-
readonly secretArn: string;
|
19
|
-
readonly name?: string;
|
20
|
-
readonly securityGroupId: string;
|
21
|
-
readonly clusterIdentifier: string;
|
22
|
-
}
|
23
|
-
|
24
|
-
/**
|
25
|
-
* A stack that creates a Database proxy.
|
26
|
-
*/
|
27
|
-
export class DbProxyStack extends Stack {
|
28
|
-
readonly isc: InfraStackConfiguration;
|
29
|
-
|
30
|
-
public static PROXY_READER_EXPORT_NAME = "db-reader-endpoint";
|
31
|
-
public static PROXY_WRITER_EXPORT_NAME = "db-writer-endpoint";
|
32
|
-
|
33
|
-
constructor(
|
34
|
-
scope: Construct,
|
35
|
-
id: string,
|
36
|
-
isc: InfraStackConfiguration,
|
37
|
-
configuration: ProxyConfiguration
|
38
|
-
) {
|
39
|
-
super(scope, id, {
|
40
|
-
env: isc.env,
|
41
|
-
});
|
42
|
-
|
43
|
-
this.isc = isc;
|
44
|
-
|
45
|
-
if (configuration.clusterIdentifier === "") {
|
46
|
-
throw new Error("Empty cluster identifier!");
|
47
|
-
}
|
48
|
-
|
49
|
-
const vpc = importVpc(this, isc.environmentName);
|
50
|
-
const secret = Secret.fromSecretAttributes(this, "proxy-secret", {
|
51
|
-
secretCompleteArn: configuration.secretArn,
|
52
|
-
});
|
53
|
-
|
54
|
-
const proxy = this.createProxy(vpc, secret, configuration);
|
55
|
-
const readerEndpoint = this.createProxyEndpoints(
|
56
|
-
vpc,
|
57
|
-
proxy,
|
58
|
-
configuration.securityGroupId
|
59
|
-
);
|
60
|
-
|
61
|
-
createParameter(this, "proxy.reader", readerEndpoint.attrEndpoint);
|
62
|
-
createParameter(this, "proxy.writer", proxy.endpoint);
|
63
|
-
|
64
|
-
this.setOutputs(proxy);
|
65
|
-
}
|
66
|
-
|
67
|
-
setOutputs(proxy: DatabaseProxy) {
|
68
|
-
// if only one instance, then there is no reader-endpoint
|
69
|
-
exportValue(
|
70
|
-
this,
|
71
|
-
this.isc.environmentName,
|
72
|
-
DbProxyStack.PROXY_READER_EXPORT_NAME,
|
73
|
-
proxy.endpoint
|
74
|
-
);
|
75
|
-
exportValue(
|
76
|
-
this,
|
77
|
-
this.isc.environmentName,
|
78
|
-
DbProxyStack.PROXY_WRITER_EXPORT_NAME,
|
79
|
-
proxy.endpoint
|
80
|
-
);
|
81
|
-
}
|
82
|
-
|
83
|
-
createProxy(vpc: IVpc, secret: ISecret, configuration: ProxyConfiguration) {
|
84
|
-
const proxyId = `${this.isc.environmentName}-proxy`;
|
85
|
-
const securityGroup = SecurityGroup.fromSecurityGroupId(
|
86
|
-
this,
|
87
|
-
"securitygroup",
|
88
|
-
configuration.securityGroupId
|
89
|
-
);
|
90
|
-
|
91
|
-
const cluster = DatabaseCluster.fromDatabaseClusterAttributes(
|
92
|
-
this,
|
93
|
-
"db-cluster",
|
94
|
-
{
|
95
|
-
clusterIdentifier: configuration.clusterIdentifier,
|
96
|
-
engine: DatabaseClusterEngine.AURORA_POSTGRESQL,
|
97
|
-
port: DbStack.CLUSTER_PORT,
|
98
|
-
}
|
99
|
-
);
|
100
|
-
|
101
|
-
// CDK tries to allow connections between proxy and cluster
|
102
|
-
// this does not work on cluster references
|
103
|
-
cluster.connections.allowDefaultPortFrom = () => {
|
104
|
-
/* nothing */
|
105
|
-
};
|
106
|
-
|
107
|
-
return new DatabaseProxy(this, proxyId, {
|
108
|
-
dbProxyName: configuration.name ?? "AuroraProxy",
|
109
|
-
securityGroups: [securityGroup],
|
110
|
-
proxyTarget: ProxyTarget.fromCluster(cluster),
|
111
|
-
idleClientTimeout: Duration.seconds(1800),
|
112
|
-
maxConnectionsPercent: 50,
|
113
|
-
maxIdleConnectionsPercent: 25,
|
114
|
-
borrowTimeout: Duration.seconds(120),
|
115
|
-
requireTLS: false,
|
116
|
-
secrets: [secret],
|
117
|
-
vpc: vpc,
|
118
|
-
});
|
119
|
-
}
|
120
|
-
|
121
|
-
createProxyEndpoints(
|
122
|
-
vpc: IVpc,
|
123
|
-
proxy: DatabaseProxy,
|
124
|
-
securityGroupId: string
|
125
|
-
) {
|
126
|
-
return new CfnDBProxyEndpoint(this, "ReaderEndpoint", {
|
127
|
-
dbProxyEndpointName: "ReaderEndpoint",
|
128
|
-
dbProxyName: proxy.dbProxyName,
|
129
|
-
vpcSubnetIds: vpc.privateSubnets.map((sub) => sub.subnetId),
|
130
|
-
vpcSecurityGroupIds: [securityGroupId],
|
131
|
-
targetRole: "READ_ONLY",
|
132
|
-
});
|
133
|
-
}
|
134
|
-
}
|
@@ -1,292 +0,0 @@
|
|
1
|
-
import {
|
2
|
-
InstanceType,
|
3
|
-
IVpc,
|
4
|
-
SecurityGroup,
|
5
|
-
SubnetType,
|
6
|
-
type ISecurityGroup,
|
7
|
-
} from "aws-cdk-lib/aws-ec2";
|
8
|
-
import {
|
9
|
-
AuroraPostgresEngineVersion,
|
10
|
-
CfnDBInstance,
|
11
|
-
Credentials,
|
12
|
-
DatabaseCluster,
|
13
|
-
DatabaseClusterEngine,
|
14
|
-
DatabaseClusterFromSnapshot,
|
15
|
-
DatabaseClusterProps,
|
16
|
-
InstanceUpdateBehaviour,
|
17
|
-
IParameterGroup,
|
18
|
-
ParameterGroup,
|
19
|
-
} from "aws-cdk-lib/aws-rds";
|
20
|
-
import { Construct } from "constructs/lib/construct.js";
|
21
|
-
import { Secret } from "aws-cdk-lib/aws-secretsmanager";
|
22
|
-
import { InfraStackConfiguration } from "./intra-stack-configuration.mjs";
|
23
|
-
import { exportValue, importVpc } from "../import-util.mjs";
|
24
|
-
import { Duration, RemovalPolicy, Stack } from "aws-cdk-lib/core";
|
25
|
-
import { createParameter } from "../stack/parameters.mjs";
|
26
|
-
|
27
|
-
export interface DbConfiguration {
|
28
|
-
readonly cluster?: ClusterConfiguration;
|
29
|
-
readonly clusterImport?: ClusterImportConfiguration;
|
30
|
-
|
31
|
-
readonly customParameterGroups: AuroraPostgresEngineVersion[];
|
32
|
-
readonly workmem?: number; // default 524288, 512MiB
|
33
|
-
|
34
|
-
/** superuser username and password are fetched from this secret, using keys
|
35
|
-
* db.superuser and db.superuser.password
|
36
|
-
*/
|
37
|
-
readonly secretArn: string;
|
38
|
-
|
39
|
-
/** If this is not specified, import default vpc */
|
40
|
-
readonly vpc?: IVpc;
|
41
|
-
}
|
42
|
-
|
43
|
-
export interface ClusterConfiguration {
|
44
|
-
readonly securityGroupId: string;
|
45
|
-
readonly dbInstanceType: InstanceType;
|
46
|
-
readonly snapshotIdentifier?: string;
|
47
|
-
readonly instances: number;
|
48
|
-
readonly dbVersion: AuroraPostgresEngineVersion;
|
49
|
-
readonly storageEncrypted?: boolean; /// default true
|
50
|
-
}
|
51
|
-
|
52
|
-
export interface ClusterImportConfiguration {
|
53
|
-
readonly clusterReadEndpoint: string;
|
54
|
-
readonly clusterWriteEndpoint: string;
|
55
|
-
}
|
56
|
-
|
57
|
-
/**
|
58
|
-
* Stack that creates DatabaseCluster.
|
59
|
-
*
|
60
|
-
* Please not, that created Cluster has RETAIL removalPolicy, so if you want to delete the stack,
|
61
|
-
* you must first deploy without parameter group, then delete stack and manually delete cluster.
|
62
|
-
*
|
63
|
-
* You should deploy once with cluster and then without. This way you can create the cluster with this
|
64
|
-
* stack, but cluster is not part of the stack after that.
|
65
|
-
*/
|
66
|
-
|
67
|
-
export class DbStack extends Stack {
|
68
|
-
public static CLUSTER_PORT = 5432;
|
69
|
-
|
70
|
-
public static CLUSTER_IDENTIFIER_EXPORT_NAME = "db-cluster";
|
71
|
-
public static CLUSTER_READ_ENDPOINT_EXPORT_NAME =
|
72
|
-
"db-cluster-reader-endpoint";
|
73
|
-
public static CLUSTER_WRITE_ENDPOINT_EXPORT_NAME =
|
74
|
-
"db-cluster-writer-endpoint";
|
75
|
-
|
76
|
-
public clusterIdentifier = "";
|
77
|
-
|
78
|
-
constructor(
|
79
|
-
scope: Construct,
|
80
|
-
id: string,
|
81
|
-
isc: InfraStackConfiguration,
|
82
|
-
configuration: DbConfiguration
|
83
|
-
) {
|
84
|
-
super(scope, id, {
|
85
|
-
env: isc.env,
|
86
|
-
});
|
87
|
-
|
88
|
-
const parameterGroups = this.createParameterGroups(
|
89
|
-
configuration.customParameterGroups,
|
90
|
-
configuration.workmem ?? 524288
|
91
|
-
);
|
92
|
-
|
93
|
-
if (
|
94
|
-
(configuration.cluster && configuration.clusterImport) ||
|
95
|
-
(!configuration.cluster && !configuration.clusterImport)
|
96
|
-
) {
|
97
|
-
throw new Error("Configure either cluster or clusterImport");
|
98
|
-
}
|
99
|
-
|
100
|
-
// create cluster if this is wanted, should do it only once
|
101
|
-
if (configuration.cluster) {
|
102
|
-
const cluster = this.createAuroraCluster(
|
103
|
-
isc,
|
104
|
-
configuration,
|
105
|
-
configuration.cluster,
|
106
|
-
parameterGroups
|
107
|
-
);
|
108
|
-
|
109
|
-
exportValue(
|
110
|
-
this,
|
111
|
-
isc.environmentName,
|
112
|
-
DbStack.CLUSTER_IDENTIFIER_EXPORT_NAME,
|
113
|
-
cluster.clusterIdentifier
|
114
|
-
);
|
115
|
-
|
116
|
-
exportValue(
|
117
|
-
this,
|
118
|
-
isc.environmentName,
|
119
|
-
DbStack.CLUSTER_WRITE_ENDPOINT_EXPORT_NAME,
|
120
|
-
cluster.clusterEndpoint.hostname
|
121
|
-
);
|
122
|
-
|
123
|
-
exportValue(
|
124
|
-
this,
|
125
|
-
isc.environmentName,
|
126
|
-
DbStack.CLUSTER_READ_ENDPOINT_EXPORT_NAME,
|
127
|
-
cluster.clusterReadEndpoint.hostname
|
128
|
-
);
|
129
|
-
|
130
|
-
createParameter(
|
131
|
-
this,
|
132
|
-
"cluster.reader",
|
133
|
-
cluster.clusterReadEndpoint.hostname
|
134
|
-
);
|
135
|
-
createParameter(
|
136
|
-
this,
|
137
|
-
"cluster.writer",
|
138
|
-
cluster.clusterEndpoint.hostname
|
139
|
-
);
|
140
|
-
createParameter(
|
141
|
-
this,
|
142
|
-
"cluster.identifier",
|
143
|
-
cluster.clusterIdentifier
|
144
|
-
);
|
145
|
-
|
146
|
-
this.clusterIdentifier = cluster.clusterIdentifier;
|
147
|
-
}
|
148
|
-
|
149
|
-
if (configuration.clusterImport) {
|
150
|
-
createParameter(
|
151
|
-
this,
|
152
|
-
"cluster.reader",
|
153
|
-
configuration.clusterImport.clusterReadEndpoint
|
154
|
-
);
|
155
|
-
createParameter(
|
156
|
-
this,
|
157
|
-
"cluster.writer",
|
158
|
-
configuration.clusterImport.clusterWriteEndpoint
|
159
|
-
);
|
160
|
-
}
|
161
|
-
}
|
162
|
-
|
163
|
-
createParameterGroups(
|
164
|
-
customVersions: AuroraPostgresEngineVersion[],
|
165
|
-
workmem: number
|
166
|
-
): IParameterGroup[] {
|
167
|
-
return customVersions.map((version: AuroraPostgresEngineVersion) => {
|
168
|
-
const pg = new ParameterGroup(
|
169
|
-
this,
|
170
|
-
`parameter-group-${version.auroraPostgresMajorVersion}`,
|
171
|
-
{
|
172
|
-
engine: DatabaseClusterEngine.auroraPostgres({
|
173
|
-
version,
|
174
|
-
}),
|
175
|
-
parameters: {
|
176
|
-
"pg_stat_statements.track": "ALL",
|
177
|
-
random_page_cost: "1",
|
178
|
-
work_mem: workmem.toString(),
|
179
|
-
},
|
180
|
-
}
|
181
|
-
);
|
182
|
-
|
183
|
-
// create both cluster parameter group and instance parameter group
|
184
|
-
pg.bindToCluster({});
|
185
|
-
pg.bindToInstance({});
|
186
|
-
|
187
|
-
return pg;
|
188
|
-
});
|
189
|
-
}
|
190
|
-
|
191
|
-
createClusterParameters(
|
192
|
-
secretArn: string,
|
193
|
-
clusterConfiguration: ClusterConfiguration,
|
194
|
-
instanceName: string,
|
195
|
-
vpc: IVpc,
|
196
|
-
securityGroup: ISecurityGroup,
|
197
|
-
parameterGroup: IParameterGroup
|
198
|
-
): DatabaseClusterProps {
|
199
|
-
const secret = Secret.fromSecretCompleteArn(
|
200
|
-
this,
|
201
|
-
"DBSecret",
|
202
|
-
secretArn
|
203
|
-
);
|
204
|
-
|
205
|
-
return {
|
206
|
-
engine: DatabaseClusterEngine.auroraPostgres({
|
207
|
-
version: clusterConfiguration.dbVersion,
|
208
|
-
}),
|
209
|
-
instances: clusterConfiguration.instances,
|
210
|
-
instanceUpdateBehaviour: InstanceUpdateBehaviour.ROLLING,
|
211
|
-
instanceIdentifierBase: instanceName + "-",
|
212
|
-
cloudwatchLogsExports: ["postgresql"],
|
213
|
-
backup: {
|
214
|
-
retention: Duration.days(35),
|
215
|
-
preferredWindow: "01:00-02:00",
|
216
|
-
},
|
217
|
-
preferredMaintenanceWindow: "mon:03:00-mon:04:00",
|
218
|
-
deletionProtection: true,
|
219
|
-
removalPolicy: RemovalPolicy.RETAIN,
|
220
|
-
port: DbStack.CLUSTER_PORT,
|
221
|
-
instanceProps: {
|
222
|
-
autoMinorVersionUpgrade: true,
|
223
|
-
allowMajorVersionUpgrade: false,
|
224
|
-
enablePerformanceInsights: true,
|
225
|
-
vpc,
|
226
|
-
securityGroups: [securityGroup],
|
227
|
-
vpcSubnets: {
|
228
|
-
subnetType: SubnetType.PRIVATE_WITH_EGRESS,
|
229
|
-
},
|
230
|
-
instanceType: clusterConfiguration.dbInstanceType,
|
231
|
-
parameterGroup,
|
232
|
-
},
|
233
|
-
credentials: Credentials.fromPassword(
|
234
|
-
secret.secretValueFromJson("db.superuser").unsafeUnwrap(),
|
235
|
-
secret.secretValueFromJson("db.superuser.password")
|
236
|
-
),
|
237
|
-
parameterGroup,
|
238
|
-
// storageEncrypted: clusterConfiguration.storageEncrypted ?? true,
|
239
|
-
monitoringInterval: Duration.seconds(30),
|
240
|
-
};
|
241
|
-
}
|
242
|
-
|
243
|
-
createAuroraCluster(
|
244
|
-
isc: InfraStackConfiguration,
|
245
|
-
configuration: DbConfiguration,
|
246
|
-
clusterConfiguration: ClusterConfiguration,
|
247
|
-
parameterGroups: IParameterGroup[]
|
248
|
-
): DatabaseCluster {
|
249
|
-
const instanceName = isc.environmentName + "-db";
|
250
|
-
const securityGroup = SecurityGroup.fromSecurityGroupId(
|
251
|
-
this,
|
252
|
-
"securitygroup",
|
253
|
-
clusterConfiguration.securityGroupId
|
254
|
-
);
|
255
|
-
const vpc = configuration.vpc
|
256
|
-
? configuration.vpc
|
257
|
-
: importVpc(this, isc.environmentName);
|
258
|
-
|
259
|
-
const parameters = this.createClusterParameters(
|
260
|
-
configuration.secretArn,
|
261
|
-
clusterConfiguration,
|
262
|
-
instanceName,
|
263
|
-
vpc,
|
264
|
-
securityGroup,
|
265
|
-
parameterGroups[0]
|
266
|
-
);
|
267
|
-
|
268
|
-
// create cluster from the snapshot or from the scratch
|
269
|
-
const cluster = clusterConfiguration.snapshotIdentifier
|
270
|
-
? new DatabaseClusterFromSnapshot(this, instanceName, {
|
271
|
-
...parameters,
|
272
|
-
...{
|
273
|
-
snapshotIdentifier:
|
274
|
-
clusterConfiguration.snapshotIdentifier,
|
275
|
-
},
|
276
|
-
})
|
277
|
-
: new DatabaseCluster(this, instanceName, parameters);
|
278
|
-
|
279
|
-
// this workaround should prevent stack failing on version upgrade
|
280
|
-
const cfnInstances = cluster.node.children.filter(
|
281
|
-
(child): child is CfnDBInstance => child instanceof CfnDBInstance
|
282
|
-
);
|
283
|
-
if (cfnInstances.length === 0) {
|
284
|
-
throw new Error(
|
285
|
-
"Couldn't pull CfnDBInstances from the L1 constructs!"
|
286
|
-
);
|
287
|
-
}
|
288
|
-
cfnInstances.forEach((cfnInstance) => delete cfnInstance.engineVersion);
|
289
|
-
|
290
|
-
return cluster;
|
291
|
-
}
|
292
|
-
}
|
@@ -1,76 +0,0 @@
|
|
1
|
-
import { IpAddresses, IVpc, SubnetType, Vpc } from "aws-cdk-lib/aws-ec2";
|
2
|
-
import { InfraStackConfiguration } from "./intra-stack-configuration.mjs";
|
3
|
-
import { exportValue } from "../import-util.mjs";
|
4
|
-
import { Stack } from "aws-cdk-lib/core";
|
5
|
-
import { Construct } from "constructs/lib/construct.js";
|
6
|
-
|
7
|
-
export interface NetworkConfiguration {
|
8
|
-
readonly vpcName: string;
|
9
|
-
readonly cidr: string;
|
10
|
-
}
|
11
|
-
|
12
|
-
export class NetworkStack extends Stack {
|
13
|
-
readonly vpc: IVpc;
|
14
|
-
|
15
|
-
constructor(
|
16
|
-
scope: Construct,
|
17
|
-
id: string,
|
18
|
-
isc: InfraStackConfiguration,
|
19
|
-
configuration: NetworkConfiguration
|
20
|
-
) {
|
21
|
-
super(scope, id, {
|
22
|
-
env: isc.env,
|
23
|
-
});
|
24
|
-
|
25
|
-
this.vpc = this.createVpc(configuration);
|
26
|
-
exportValue(this, isc.environmentName, "VPCID", this.vpc.vpcId);
|
27
|
-
exportValue(
|
28
|
-
this,
|
29
|
-
isc.environmentName,
|
30
|
-
"digitrafficpublicASubnet",
|
31
|
-
this.vpc.publicSubnets[0].subnetId
|
32
|
-
);
|
33
|
-
exportValue(
|
34
|
-
this,
|
35
|
-
isc.environmentName,
|
36
|
-
"digitrafficpublicBSubnet",
|
37
|
-
this.vpc.publicSubnets[1].subnetId
|
38
|
-
);
|
39
|
-
exportValue(
|
40
|
-
this,
|
41
|
-
isc.environmentName,
|
42
|
-
"digitrafficprivateASubnet",
|
43
|
-
this.vpc.privateSubnets[0].subnetId
|
44
|
-
);
|
45
|
-
exportValue(
|
46
|
-
this,
|
47
|
-
isc.environmentName,
|
48
|
-
"digitrafficprivateBSubnet",
|
49
|
-
this.vpc.privateSubnets[1].subnetId
|
50
|
-
);
|
51
|
-
}
|
52
|
-
|
53
|
-
createVpc(configuration: NetworkConfiguration): Vpc {
|
54
|
-
return new Vpc(this, "DigitrafficVPC", {
|
55
|
-
vpcName: configuration.vpcName,
|
56
|
-
availabilityZones: Stack.of(this)
|
57
|
-
.availabilityZones.sort()
|
58
|
-
.slice(0, 2), // take two first azs
|
59
|
-
enableDnsHostnames: true,
|
60
|
-
enableDnsSupport: true,
|
61
|
-
ipAddresses: IpAddresses.cidr(configuration.cidr),
|
62
|
-
subnetConfiguration: [
|
63
|
-
{
|
64
|
-
name: "public",
|
65
|
-
cidrMask: 24,
|
66
|
-
subnetType: SubnetType.PUBLIC,
|
67
|
-
},
|
68
|
-
{
|
69
|
-
name: "private",
|
70
|
-
cidrMask: 24,
|
71
|
-
subnetType: SubnetType.PRIVATE_WITH_EGRESS,
|
72
|
-
},
|
73
|
-
],
|
74
|
-
});
|
75
|
-
}
|
76
|
-
}
|
@@ -1,50 +0,0 @@
|
|
1
|
-
import { IApiKey, RestApi } from "aws-cdk-lib/aws-apigateway";
|
2
|
-
|
3
|
-
/**
|
4
|
-
* Creates an usage plan for a REST API with a single API key
|
5
|
-
* @param api The REST API
|
6
|
-
* @param apiKeyId Id for the API key, this is a surrogate id for CDK, not displayed anywhere
|
7
|
-
* @param apiKeyName Name for the API key, this is displayed in the AWS Console
|
8
|
-
* @deprecated Creates randomized API key names, use createDefaultUsagePlan instead
|
9
|
-
*/
|
10
|
-
export function createUsagePlan(
|
11
|
-
api: RestApi,
|
12
|
-
apiKeyId: string,
|
13
|
-
apiKeyName: string
|
14
|
-
): IApiKey {
|
15
|
-
const apiKey = api.addApiKey(apiKeyId);
|
16
|
-
const plan = api.addUsagePlan(apiKeyName, {
|
17
|
-
name: apiKeyName,
|
18
|
-
});
|
19
|
-
plan.addApiStage({
|
20
|
-
stage: api.deploymentStage,
|
21
|
-
});
|
22
|
-
plan.addApiKey(apiKey);
|
23
|
-
|
24
|
-
return apiKey;
|
25
|
-
}
|
26
|
-
|
27
|
-
/**
|
28
|
-
* Creates a default usage plan for a REST API with a single API key
|
29
|
-
* @param api The REST API
|
30
|
-
* @param apiName Name of the api. Will generate key: apiName + ' API Key' and plan: apiName + ' API Usage Plan'
|
31
|
-
* @param value Optional value for the API key
|
32
|
-
*/
|
33
|
-
export function createDefaultUsagePlan(
|
34
|
-
api: RestApi,
|
35
|
-
apiName: string,
|
36
|
-
value?: string
|
37
|
-
): IApiKey {
|
38
|
-
const apiKeyName = apiName + " API Key";
|
39
|
-
const usagePlanName = apiName + " API Usage Plan";
|
40
|
-
const apiKey = api.addApiKey(apiKeyName, { apiKeyName: apiKeyName, value });
|
41
|
-
const plan = api.addUsagePlan(usagePlanName, {
|
42
|
-
name: usagePlanName,
|
43
|
-
});
|
44
|
-
plan.addApiStage({
|
45
|
-
stage: api.deploymentStage,
|
46
|
-
});
|
47
|
-
plan.addApiKey(apiKey);
|
48
|
-
|
49
|
-
return apiKey;
|
50
|
-
}
|