@digitraffic/common 2023.12.15-1 → 2024.1.19-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/aws/infra/api/handler-factory.d.ts +2 -2
- package/dist/aws/infra/api/handler-factory.js +4 -9
- package/dist/aws/infra/api/integration.d.ts +1 -1
- package/dist/aws/infra/api/integration.js +9 -13
- package/dist/aws/infra/api/response.d.ts +2 -3
- package/dist/aws/infra/api/response.js +25 -30
- package/dist/aws/infra/api/responses.d.ts +2 -3
- package/dist/aws/infra/api/responses.js +25 -31
- package/dist/aws/infra/api/static-integration.d.ts +1 -1
- package/dist/aws/infra/api/static-integration.js +7 -11
- package/dist/aws/infra/canaries/canary-alarm.d.ts +1 -1
- package/dist/aws/infra/canaries/canary-alarm.js +7 -11
- package/dist/aws/infra/canaries/canary-keys.js +3 -6
- package/dist/aws/infra/canaries/canary-parameters.js +1 -2
- package/dist/aws/infra/canaries/canary-role.js +8 -12
- package/dist/aws/infra/canaries/canary.d.ts +2 -2
- package/dist/aws/infra/canaries/canary.js +9 -13
- package/dist/aws/infra/canaries/database-canary.d.ts +3 -3
- package/dist/aws/infra/canaries/database-canary.js +8 -12
- package/dist/aws/infra/canaries/database-checker.d.ts +1 -1
- package/dist/aws/infra/canaries/database-checker.js +10 -14
- package/dist/aws/infra/canaries/url-canary.d.ts +4 -4
- package/dist/aws/infra/canaries/url-canary.js +8 -12
- package/dist/aws/infra/canaries/url-checker.d.ts +2 -2
- package/dist/aws/infra/canaries/url-checker.js +33 -40
- package/dist/aws/infra/documentation.js +8 -16
- package/dist/aws/infra/import-util.js +10 -18
- package/dist/aws/infra/scheduler.js +10 -14
- package/dist/aws/infra/security-rule.js +4 -8
- package/dist/aws/infra/sqs-integration.d.ts +1 -2
- package/dist/aws/infra/sqs-integration.js +11 -15
- package/dist/aws/infra/sqs-queue.d.ts +1 -1
- package/dist/aws/infra/sqs-queue.js +51 -50
- package/dist/aws/infra/stack/lambda-configs.d.ts +2 -2
- package/dist/aws/infra/stack/lambda-configs.js +14 -20
- package/dist/aws/infra/stack/monitoredfunction.d.ts +3 -3
- package/dist/aws/infra/stack/monitoredfunction.js +19 -27
- package/dist/aws/infra/stack/parameters.d.ts +1 -1
- package/dist/aws/infra/stack/parameters.js +5 -10
- package/dist/aws/infra/stack/rest_apis.d.ts +3 -3
- package/dist/aws/infra/stack/rest_apis.js +41 -54
- package/dist/aws/infra/stack/stack-checking-aspect.d.ts +1 -1
- package/dist/aws/infra/stack/stack-checking-aspect.js +28 -39
- package/dist/aws/infra/stack/stack.d.ts +5 -6
- package/dist/aws/infra/stack/stack.js +16 -20
- package/dist/aws/infra/stack/subscription.d.ts +2 -2
- package/dist/aws/infra/stack/subscription.js +5 -10
- package/dist/aws/infra/stacks/db-dns-stack.d.ts +2 -2
- package/dist/aws/infra/stacks/db-dns-stack.js +25 -29
- package/dist/aws/infra/stacks/db-proxy-stack.d.ts +2 -2
- package/dist/aws/infra/stacks/db-proxy-stack.js +23 -27
- package/dist/aws/infra/stacks/db-stack.d.ts +3 -4
- package/dist/aws/infra/stacks/db-stack.js +30 -34
- package/dist/aws/infra/stacks/intra-stack-configuration.js +1 -2
- package/dist/aws/infra/stacks/network-stack.d.ts +2 -2
- package/dist/aws/infra/stacks/network-stack.js +15 -19
- package/dist/aws/infra/usage-plans.js +2 -7
- package/dist/aws/runtime/apikey.js +3 -7
- package/dist/aws/runtime/digitraffic-integration-response.d.ts +1 -1
- package/dist/aws/runtime/digitraffic-integration-response.js +7 -11
- package/dist/aws/runtime/dt-logger-default.d.ts +2 -2
- package/dist/aws/runtime/dt-logger-default.js +2 -5
- package/dist/aws/runtime/dt-logger.d.ts +1 -1
- package/dist/aws/runtime/dt-logger.js +3 -10
- package/dist/aws/runtime/environment.js +3 -7
- package/dist/aws/runtime/messaging.js +1 -5
- package/dist/aws/runtime/s3.js +3 -7
- package/dist/aws/runtime/secrets/dbsecret.d.ts +1 -1
- package/dist/aws/runtime/secrets/dbsecret.js +5 -9
- package/dist/aws/runtime/secrets/proxy-holder.js +12 -16
- package/dist/aws/runtime/secrets/rds-holder.js +12 -16
- package/dist/aws/runtime/secrets/secret-holder.d.ts +1 -1
- package/dist/aws/runtime/secrets/secret-holder.js +9 -13
- package/dist/aws/runtime/secrets/secret.js +7 -11
- package/dist/aws/types/errors.js +5 -9
- package/dist/aws/types/lambda-response.js +3 -10
- package/dist/aws/types/mediatypes.js +2 -5
- package/dist/aws/types/model-with-reference.js +1 -2
- package/dist/aws/types/proxytypes.js +1 -2
- package/dist/aws/types/tags.js +2 -5
- package/dist/database/cached.d.ts +1 -1
- package/dist/database/cached.js +8 -14
- package/dist/database/database.js +14 -21
- package/dist/database/last-updated.d.ts +1 -1
- package/dist/database/last-updated.js +8 -17
- package/dist/database/models.js +1 -2
- package/dist/index.d.ts +1 -0
- package/dist/index.js +2 -0
- package/dist/marine/id_utils.js +3 -9
- package/dist/marine/rtz.js +1 -2
- package/dist/test/asserter.js +1 -5
- package/dist/test/db-testutils.d.ts +1 -1
- package/dist/test/db-testutils.js +8 -13
- package/dist/test/httpserver.d.ts +1 -1
- package/dist/test/httpserver.js +19 -18
- package/dist/test/secrets-manager.js +9 -35
- package/dist/test/testutils.js +8 -19
- package/dist/types/async-timeout-error.js +1 -5
- package/dist/types/aws-env.js +1 -2
- package/dist/types/either.js +1 -2
- package/dist/types/http-error.js +1 -5
- package/dist/types/input-error.js +1 -5
- package/dist/types/language.js +2 -5
- package/dist/types/nullable.d.ts +1 -1
- package/dist/types/nullable.js +1 -2
- package/dist/types/traffictype.js +2 -5
- package/dist/types/urn.js +1 -2
- package/dist/types/util-types.js +1 -2
- package/dist/types/validator.js +4 -9
- package/dist/utils/api-model.d.ts +1 -1
- package/dist/utils/api-model.js +17 -27
- package/dist/utils/base64.d.ts +1 -1
- package/dist/utils/base64.js +2 -7
- package/dist/utils/date-utils.js +9 -16
- package/dist/utils/geojson-types.js +2 -7
- package/dist/utils/geometry.js +15 -48
- package/dist/utils/logging.d.ts +1 -1
- package/dist/utils/logging.js +8 -13
- package/dist/utils/retry.js +21 -26
- package/dist/utils/slack.js +7 -14
- package/dist/utils/utils.d.ts +2 -2
- package/dist/utils/utils.js +14 -29
- package/package.json +127 -41
- package/src/aws/infra/api/handler-factory.ts +3 -3
- package/src/aws/infra/api/integration.ts +2 -2
- package/src/aws/infra/api/response.ts +3 -3
- package/src/aws/infra/api/responses.ts +4 -4
- package/src/aws/infra/api/static-integration.ts +2 -2
- package/src/aws/infra/canaries/canary-alarm.ts +1 -1
- package/src/aws/infra/canaries/canary.ts +3 -3
- package/src/aws/infra/canaries/database-canary.ts +3 -3
- package/src/aws/infra/canaries/database-checker.ts +6 -6
- package/src/aws/infra/canaries/url-canary.ts +6 -6
- package/src/aws/infra/canaries/url-checker.ts +8 -8
- package/src/aws/infra/sqs-integration.ts +1 -1
- package/src/aws/infra/sqs-queue.ts +29 -44
- package/src/aws/infra/stack/lambda-configs.ts +9 -9
- package/src/aws/infra/stack/monitoredfunction.ts +4 -4
- package/src/aws/infra/stack/parameters.ts +1 -1
- package/src/aws/infra/stack/rest_apis.ts +6 -6
- package/src/aws/infra/stack/stack-checking-aspect.ts +20 -72
- package/src/aws/infra/stack/stack.ts +4 -5
- package/src/aws/infra/stack/subscription.ts +2 -2
- package/src/aws/infra/stacks/db-dns-stack.ts +4 -4
- package/src/aws/infra/stacks/db-proxy-stack.ts +5 -5
- package/src/aws/infra/stacks/db-stack.ts +5 -5
- package/src/aws/infra/stacks/network-stack.ts +3 -3
- package/src/aws/runtime/digitraffic-integration-response.ts +2 -2
- package/src/aws/runtime/dt-logger-default.ts +2 -2
- package/src/aws/runtime/secrets/dbsecret.ts +1 -1
- package/src/aws/runtime/secrets/proxy-holder.ts +4 -4
- package/src/aws/runtime/secrets/rds-holder.ts +4 -4
- package/src/aws/runtime/secrets/secret-holder.ts +4 -4
- package/src/aws/runtime/secrets/secret.ts +2 -2
- package/src/database/cached.ts +1 -1
- package/src/database/database.ts +3 -3
- package/src/database/last-updated.ts +1 -1
- package/src/index.ts +2 -0
- package/src/test/db-testutils.ts +2 -2
- package/src/test/httpserver.ts +13 -7
- package/src/test/secrets-manager.ts +2 -2
- package/src/types/nullable.ts +1 -1
- package/src/utils/api-model.ts +1 -1
- package/src/utils/geometry.ts +5 -3
- package/src/utils/logging.ts +2 -2
- package/src/utils/retry.ts +3 -3
- package/src/utils/slack.ts +2 -2
- package/src/utils/utils.ts +3 -3
@@ -1,29 +1,27 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
const aws_cloudwatch_actions_1 = require("aws-cdk-lib/aws-cloudwatch-actions");
|
13
|
-
const monitoredfunction_1 = require("./stack/monitoredfunction");
|
1
|
+
import { Queue, QueueEncryption } from "aws-cdk-lib/aws-sqs";
|
2
|
+
import { Duration } from "aws-cdk-lib";
|
3
|
+
import { BlockPublicAccess, Bucket } from "aws-cdk-lib/aws-s3";
|
4
|
+
import { PolicyStatement } from "aws-cdk-lib/aws-iam";
|
5
|
+
import { InlineCode, Runtime } from "aws-cdk-lib/aws-lambda";
|
6
|
+
import { RetentionDays } from "aws-cdk-lib/aws-logs";
|
7
|
+
import { SqsEventSource } from "aws-cdk-lib/aws-lambda-event-sources";
|
8
|
+
import { ComparisonOperator, TreatMissingData } from "aws-cdk-lib/aws-cloudwatch";
|
9
|
+
import { SnsAction } from "aws-cdk-lib/aws-cloudwatch-actions";
|
10
|
+
import { Upload } from "@aws-sdk/lib-storage";
|
11
|
+
import { MonitoredFunction } from "./stack/monitoredfunction.js";
|
14
12
|
/**
|
15
13
|
* Construct for creating SQS-queues.
|
16
14
|
*
|
17
15
|
* If you don't config your own deadLetterQueue, this will create a dlq for you, also a lambda function, a s3 bucket
|
18
16
|
* and an alarm for the queue. Anything that goes to the dlq will be written into the bucket and the alarm is activated.
|
19
17
|
*/
|
20
|
-
class DigitrafficSqsQueue extends
|
18
|
+
export class DigitrafficSqsQueue extends Queue {
|
21
19
|
static create(stack, name, props) {
|
22
20
|
const queueName = `${stack.configuration.shortName}-${name}-Queue`;
|
23
21
|
const queueProps = {
|
24
22
|
...props,
|
25
23
|
...{
|
26
|
-
encryption:
|
24
|
+
encryption: QueueEncryption.KMS_MANAGED,
|
27
25
|
queueName,
|
28
26
|
deadLetterQueue: props.deadLetterQueue ?? {
|
29
27
|
maxReceiveCount: 2,
|
@@ -34,85 +32,86 @@ class DigitrafficSqsQueue extends aws_sqs_1.Queue {
|
|
34
32
|
return new DigitrafficSqsQueue(stack, queueName, queueProps);
|
35
33
|
}
|
36
34
|
}
|
37
|
-
|
38
|
-
class DigitrafficDLQueue {
|
35
|
+
export class DigitrafficDLQueue {
|
39
36
|
static create(stack, name) {
|
40
37
|
const dlqName = `${stack.configuration.shortName}-${name}-DLQ`;
|
41
38
|
const dlq = new DigitrafficSqsQueue(stack, dlqName, {
|
42
39
|
queueName: dlqName,
|
43
|
-
visibilityTimeout:
|
44
|
-
encryption:
|
40
|
+
visibilityTimeout: Duration.seconds(60),
|
41
|
+
encryption: QueueEncryption.KMS_MANAGED,
|
45
42
|
});
|
46
|
-
const dlqBucket = new
|
47
|
-
blockPublicAccess:
|
43
|
+
const dlqBucket = new Bucket(stack, `${dlqName}-Bucket`, {
|
44
|
+
blockPublicAccess: BlockPublicAccess.BLOCK_ALL,
|
48
45
|
});
|
49
46
|
const dlqFunctionName = `${dlqName}-Function`;
|
50
|
-
const lambda =
|
51
|
-
runtime:
|
52
|
-
logRetention:
|
47
|
+
const lambda = MonitoredFunction.create(stack, dlqFunctionName, {
|
48
|
+
runtime: Runtime.NODEJS_20_X,
|
49
|
+
logRetention: RetentionDays.ONE_YEAR,
|
53
50
|
functionName: dlqFunctionName,
|
54
51
|
code: getDlqCode(dlqBucket.bucketName),
|
55
|
-
timeout:
|
52
|
+
timeout: Duration.seconds(10),
|
56
53
|
handler: "index.handler",
|
57
54
|
memorySize: 128,
|
58
55
|
reservedConcurrentExecutions: 1,
|
59
56
|
});
|
60
|
-
const statement = new
|
57
|
+
const statement = new PolicyStatement();
|
61
58
|
statement.addActions("s3:PutObject");
|
62
59
|
statement.addActions("s3:PutObjectAcl");
|
63
60
|
statement.addResources(dlqBucket.bucketArn + "/*");
|
64
61
|
lambda.addToRolePolicy(statement);
|
65
|
-
lambda.addEventSource(new
|
62
|
+
lambda.addEventSource(new SqsEventSource(dlq));
|
66
63
|
addDLQAlarm(stack, dlqName, dlq);
|
67
64
|
return dlq;
|
68
65
|
}
|
69
66
|
}
|
70
|
-
exports.DigitrafficDLQueue = DigitrafficDLQueue;
|
71
67
|
function addDLQAlarm(stack, dlqName, dlq) {
|
72
68
|
const alarmName = `${dlqName}-Alarm`;
|
73
69
|
dlq.metricNumberOfMessagesReceived({
|
74
|
-
period:
|
70
|
+
period: Duration.minutes(5),
|
75
71
|
})
|
76
72
|
.createAlarm(stack, alarmName, {
|
77
73
|
alarmName,
|
78
74
|
threshold: 0,
|
79
75
|
evaluationPeriods: 1,
|
80
|
-
treatMissingData:
|
81
|
-
comparisonOperator:
|
76
|
+
treatMissingData: TreatMissingData.NOT_BREACHING,
|
77
|
+
comparisonOperator: ComparisonOperator.GREATER_THAN_THRESHOLD,
|
82
78
|
})
|
83
|
-
.addAlarmAction(new
|
79
|
+
.addAlarmAction(new SnsAction(stack.warningTopic));
|
84
80
|
}
|
85
|
-
function getDlqCode(
|
86
|
-
const functionBody = DLQ_LAMBDA_CODE.replace("__bucketName__",
|
81
|
+
function getDlqCode(Bucket) {
|
82
|
+
const functionBody = DLQ_LAMBDA_CODE.replace("__bucketName__", Bucket)
|
87
83
|
.replace("__upload__", uploadToS3.toString())
|
88
84
|
.replace("__doUpload__", doUpload.toString())
|
89
85
|
.replace("__handler__", createHandler().toString().substring(23)); // remove function handler() from signature
|
90
|
-
return new
|
86
|
+
return new InlineCode(functionBody);
|
91
87
|
}
|
92
|
-
async function uploadToS3(s3,
|
88
|
+
async function uploadToS3(s3, Bucket, Body, Key) {
|
93
89
|
try {
|
94
|
-
console.info("writing %s to %s",
|
95
|
-
await doUpload(s3,
|
90
|
+
console.info("writing %s to %s", Key, Bucket);
|
91
|
+
await doUpload(s3, Bucket, Body, Key);
|
96
92
|
}
|
97
93
|
catch (error) {
|
98
94
|
console.warn(error);
|
99
|
-
console.warn("method=uploadToS3 retrying upload to bucket %s",
|
95
|
+
console.warn("method=uploadToS3 retrying upload to bucket %s", Bucket);
|
100
96
|
try {
|
101
|
-
await doUpload(s3,
|
97
|
+
await doUpload(s3, Bucket, Body, Key);
|
102
98
|
}
|
103
99
|
catch (e2) {
|
104
|
-
console.error("method=uploadToS3 failed retrying upload to bucket %s",
|
100
|
+
console.error("method=uploadToS3 failed retrying upload to bucket %s", Bucket);
|
105
101
|
}
|
106
102
|
}
|
107
103
|
}
|
108
|
-
function doUpload(s3,
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
104
|
+
async function doUpload(s3, Bucket, Body, Key) {
|
105
|
+
try {
|
106
|
+
const upload = new Upload({
|
107
|
+
client: s3,
|
108
|
+
params: { Bucket, Key, Body },
|
109
|
+
});
|
110
|
+
await upload.done();
|
111
|
+
}
|
112
|
+
catch (error) {
|
113
|
+
console.error(error);
|
114
|
+
}
|
116
115
|
}
|
117
116
|
// bucketName is unused, will be overridden in the actual lambda code below
|
118
117
|
const bucketName = "";
|
@@ -126,7 +125,9 @@ function createHandler() {
|
|
126
125
|
new AWS.S3(), bucketName, e.body, `dlq-${millis}-${idx}.json`)));
|
127
126
|
};
|
128
127
|
}
|
129
|
-
const DLQ_LAMBDA_CODE = `
|
128
|
+
const DLQ_LAMBDA_CODE = `
|
129
|
+
import { S3, S3Client } from "@aws-sdk/client-s3";
|
130
|
+
import { Upload } from "@aws-sdk/lib-storage";
|
130
131
|
const bucketName = "__bucketName__";
|
131
132
|
|
132
133
|
__upload__
|
@@ -1,8 +1,8 @@
|
|
1
1
|
import { Architecture, Code, FunctionProps, Runtime } from "aws-cdk-lib/aws-lambda";
|
2
2
|
import { IVpc, SubnetSelection } from "aws-cdk-lib/aws-ec2";
|
3
3
|
import { Role } from "aws-cdk-lib/aws-iam";
|
4
|
-
import { DigitrafficStack } from "./stack";
|
5
|
-
import { MonitoredFunctionAlarmProps } from "./monitoredfunction";
|
4
|
+
import { DigitrafficStack } from "./stack.js";
|
5
|
+
import { MonitoredFunctionAlarmProps } from "./monitoredfunction.js";
|
6
6
|
export type LambdaEnvironment = Record<string, string>;
|
7
7
|
export type DBLambdaEnvironment = LambdaEnvironment & {
|
8
8
|
SECRET_ID?: string;
|
@@ -1,10 +1,7 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
const aws_cdk_lib_1 = require("aws-cdk-lib");
|
6
|
-
const aws_logs_1 = require("aws-cdk-lib/aws-logs");
|
7
|
-
function databaseFunctionProps(stack, environment, lambdaName, simpleLambdaName, config) {
|
1
|
+
import { Architecture, AssetCode, Runtime, } from "aws-cdk-lib/aws-lambda";
|
2
|
+
import { Duration } from "aws-cdk-lib";
|
3
|
+
import { RetentionDays } from "aws-cdk-lib/aws-logs";
|
4
|
+
export function databaseFunctionProps(stack, environment, lambdaName, simpleLambdaName, config) {
|
8
5
|
const vpcSubnets = stack.vpc
|
9
6
|
? {
|
10
7
|
subnets: stack.vpc.privateSubnets,
|
@@ -19,41 +16,39 @@ function databaseFunctionProps(stack, environment, lambdaName, simpleLambdaName,
|
|
19
16
|
},
|
20
17
|
};
|
21
18
|
}
|
22
|
-
|
23
|
-
function lambdaFunctionProps(stack, environment, lambdaName, simpleLambdaName, config) {
|
19
|
+
export function lambdaFunctionProps(stack, environment, lambdaName, simpleLambdaName, config) {
|
24
20
|
return {
|
25
|
-
runtime: config?.runtime ??
|
26
|
-
architecture: config?.architecture ??
|
21
|
+
runtime: config?.runtime ?? Runtime.NODEJS_20_X,
|
22
|
+
architecture: config?.architecture ?? Architecture.ARM_64,
|
27
23
|
memorySize: config?.memorySize ?? 128,
|
28
24
|
functionName: lambdaName,
|
29
25
|
role: config?.role,
|
30
|
-
timeout:
|
31
|
-
logRetention:
|
26
|
+
timeout: Duration.seconds(config?.timeout ?? 60),
|
27
|
+
logRetention: RetentionDays.ONE_YEAR,
|
32
28
|
reservedConcurrentExecutions: config?.reservedConcurrentExecutions ?? 2,
|
33
29
|
code: getAssetCode(simpleLambdaName, config?.singleLambda ?? false),
|
34
30
|
handler: `${simpleLambdaName}.handler`,
|
35
31
|
environment,
|
36
32
|
};
|
37
33
|
}
|
38
|
-
exports.lambdaFunctionProps = lambdaFunctionProps;
|
39
34
|
function getAssetCode(simpleLambdaName, isSingleLambda) {
|
40
35
|
const lambdaPath = isSingleLambda
|
41
36
|
? `dist/lambda/`
|
42
37
|
: `dist/lambda/${simpleLambdaName}`;
|
43
|
-
return new
|
38
|
+
return new AssetCode(lambdaPath);
|
44
39
|
}
|
45
|
-
function defaultLambdaConfiguration(config) {
|
40
|
+
export function defaultLambdaConfiguration(config) {
|
46
41
|
const props = {
|
47
|
-
runtime:
|
42
|
+
runtime: Runtime.NODEJS_20_X,
|
48
43
|
memorySize: config.memorySize ?? 128,
|
49
44
|
functionName: config.functionName,
|
50
45
|
handler: config.handler,
|
51
46
|
environment: config.environment ?? {},
|
52
|
-
logRetention:
|
47
|
+
logRetention: RetentionDays.ONE_YEAR,
|
53
48
|
reservedConcurrentExecutions: config.reservedConcurrentExecutions,
|
54
49
|
code: config.code,
|
55
50
|
role: config.role,
|
56
|
-
timeout:
|
51
|
+
timeout: Duration.seconds(config.timeout ?? 10),
|
57
52
|
};
|
58
53
|
if (config.vpc) {
|
59
54
|
return {
|
@@ -68,5 +63,4 @@ function defaultLambdaConfiguration(config) {
|
|
68
63
|
}
|
69
64
|
return props;
|
70
65
|
}
|
71
|
-
exports.defaultLambdaConfiguration = defaultLambdaConfiguration;
|
72
66
|
//# sourceMappingURL=lambda-configs.js.map
|
@@ -1,10 +1,10 @@
|
|
1
1
|
import { Function, FunctionProps } from "aws-cdk-lib/aws-lambda";
|
2
2
|
import { Stack } from "aws-cdk-lib";
|
3
3
|
import { ComparisonOperator } from "aws-cdk-lib/aws-cloudwatch";
|
4
|
-
import { DigitrafficStack } from "
|
4
|
+
import { DigitrafficStack } from "./stack.js";
|
5
5
|
import { ITopic } from "aws-cdk-lib/aws-sns";
|
6
|
-
import { LambdaEnvironment, MonitoredFunctionParameters } from "
|
7
|
-
import { TrafficType } from "../../../types/traffictype";
|
6
|
+
import { LambdaEnvironment, MonitoredFunctionParameters } from "./lambda-configs.js";
|
7
|
+
import { TrafficType } from "../../../types/traffictype.js";
|
8
8
|
/**
|
9
9
|
* Allows customization of CloudWatch Alarm properties
|
10
10
|
*/
|
@@ -1,19 +1,13 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
};
|
5
|
-
|
6
|
-
|
7
|
-
const aws_lambda_1 = require("aws-cdk-lib/aws-lambda");
|
8
|
-
const aws_cloudwatch_actions_1 = require("aws-cdk-lib/aws-cloudwatch-actions");
|
9
|
-
const aws_cloudwatch_1 = require("aws-cdk-lib/aws-cloudwatch");
|
10
|
-
const lambda_configs_1 = require("../stack/lambda-configs");
|
11
|
-
const subscription_1 = require("../stack/subscription");
|
12
|
-
const lodash_1 = __importDefault(require("lodash"));
|
1
|
+
import { Function } from "aws-cdk-lib/aws-lambda";
|
2
|
+
import { SnsAction } from "aws-cdk-lib/aws-cloudwatch-actions";
|
3
|
+
import { ComparisonOperator } from "aws-cdk-lib/aws-cloudwatch";
|
4
|
+
import { databaseFunctionProps, } from "./lambda-configs.js";
|
5
|
+
import { DigitrafficLogSubscriptions } from "./subscription.js";
|
6
|
+
import _ from "lodash";
|
13
7
|
/**
|
14
8
|
* Creates a Lambda function that monitors default CloudWatch Lambda metrics with CloudWatch Alarms.
|
15
9
|
*/
|
16
|
-
class MonitoredFunction extends
|
10
|
+
export class MonitoredFunction extends Function {
|
17
11
|
/**
|
18
12
|
* Create new MonitoredFunction. Use topics from given DigitrafficStack.
|
19
13
|
*
|
@@ -43,12 +37,12 @@ class MonitoredFunction extends aws_lambda_1.Function {
|
|
43
37
|
*/
|
44
38
|
static createV2(stack, name, environment, functionParameters) {
|
45
39
|
const functionName = functionParameters?.functionName ??
|
46
|
-
`${stack.configuration.shortName}-${
|
40
|
+
`${stack.configuration.shortName}-${_.chain(name)
|
47
41
|
.camelCase()
|
48
42
|
.startCase()
|
49
43
|
.replace(/\s/g, "")
|
50
44
|
.value()}`;
|
51
|
-
const functionProps =
|
45
|
+
const functionProps = databaseFunctionProps(stack, environment, functionName, name, functionParameters);
|
52
46
|
return MonitoredFunction.create(stack, functionName, functionProps, functionParameters);
|
53
47
|
}
|
54
48
|
/**
|
@@ -67,25 +61,25 @@ class MonitoredFunction extends aws_lambda_1.Function {
|
|
67
61
|
throw new Error("Function name not provided");
|
68
62
|
}
|
69
63
|
this.givenName = functionProps.functionName;
|
70
|
-
const alarmSnsAction = new
|
71
|
-
const warningSnsAction = new
|
64
|
+
const alarmSnsAction = new SnsAction(alarmSnsTopic);
|
65
|
+
const warningSnsAction = new SnsAction(warningSnsTopic);
|
72
66
|
if (props?.durationAlarmProps?.create !== false) {
|
73
67
|
if (!functionProps.timeout) {
|
74
68
|
throw new Error("Timeout needs to be explicitly set");
|
75
69
|
}
|
76
|
-
this.createAlarm(scope, this.metricDuration().with({ statistic: "max" }), "Duration", "Duration alarm", `Duration has exceeded ${functionProps.timeout.toSeconds()} seconds`, trafficType, this.getAlarmActionForEnv(alarmSnsAction, warningSnsAction, production), functionProps.timeout.toMilliseconds(), 1, 1,
|
70
|
+
this.createAlarm(scope, this.metricDuration().with({ statistic: "max" }), "Duration", "Duration alarm", `Duration has exceeded ${functionProps.timeout.toSeconds()} seconds`, trafficType, this.getAlarmActionForEnv(alarmSnsAction, warningSnsAction, production), functionProps.timeout.toMilliseconds(), 1, 1, ComparisonOperator.GREATER_THAN_OR_EQUAL_TO_THRESHOLD, props?.durationAlarmProps);
|
77
71
|
}
|
78
72
|
if (props?.durationWarningProps?.create !== false) {
|
79
73
|
if (!functionProps.timeout) {
|
80
74
|
throw new Error("Timeout needs to be explicitly set");
|
81
75
|
}
|
82
|
-
this.createAlarm(scope, this.metricDuration().with({ statistic: "max" }), "Duration-Warning", "Duration warning", `Duration is 85 % of max ${functionProps.timeout.toSeconds()} seconds`, trafficType, warningSnsAction, functionProps.timeout.toMilliseconds() * 0.85, 1, 1,
|
76
|
+
this.createAlarm(scope, this.metricDuration().with({ statistic: "max" }), "Duration-Warning", "Duration warning", `Duration is 85 % of max ${functionProps.timeout.toSeconds()} seconds`, trafficType, warningSnsAction, functionProps.timeout.toMilliseconds() * 0.85, 1, 1, ComparisonOperator.GREATER_THAN_OR_EQUAL_TO_THRESHOLD, props?.durationWarningProps);
|
83
77
|
}
|
84
78
|
if (props?.errorAlarmProps?.create !== false) {
|
85
|
-
this.createAlarm(scope, this.metricErrors(), "Errors", "Errors alarm", "Invocations did not succeed", trafficType, this.getAlarmActionForEnv(alarmSnsAction, warningSnsAction, production), 1, 1, 1,
|
79
|
+
this.createAlarm(scope, this.metricErrors(), "Errors", "Errors alarm", "Invocations did not succeed", trafficType, this.getAlarmActionForEnv(alarmSnsAction, warningSnsAction, production), 1, 1, 1, ComparisonOperator.GREATER_THAN_OR_EQUAL_TO_THRESHOLD, props?.errorAlarmProps);
|
86
80
|
}
|
87
81
|
if (props?.throttleAlarmProps?.create !== false) {
|
88
|
-
this.createAlarm(scope, this.metricThrottles(), "Throttles", "Throttles alarm", "Has throttled", trafficType, this.getAlarmActionForEnv(alarmSnsAction, warningSnsAction, production), 0, 1, 1,
|
82
|
+
this.createAlarm(scope, this.metricThrottles(), "Throttles", "Throttles alarm", "Has throttled", trafficType, this.getAlarmActionForEnv(alarmSnsAction, warningSnsAction, production), 0, 1, 1, ComparisonOperator.GREATER_THAN_THRESHOLD, props?.throttleAlarmProps);
|
89
83
|
}
|
90
84
|
}
|
91
85
|
createAlarm(stack, metric, alarmId, alarmName, alarmDescription, trafficType, alarmSnsAction, threshold, evaluationPeriods, datapointsToAlarm, comparisonOperator, alarmProps) {
|
@@ -104,7 +98,6 @@ class MonitoredFunction extends aws_lambda_1.Function {
|
|
104
98
|
return production ? alarmAction : warningAction;
|
105
99
|
}
|
106
100
|
}
|
107
|
-
exports.MonitoredFunction = MonitoredFunction;
|
108
101
|
/** disable all alarms */
|
109
102
|
MonitoredFunction.DISABLE_ALARMS = {
|
110
103
|
durationAlarmProps: {
|
@@ -120,7 +113,7 @@ MonitoredFunction.DISABLE_ALARMS = {
|
|
120
113
|
create: false,
|
121
114
|
},
|
122
115
|
};
|
123
|
-
class MonitoredDBFunction {
|
116
|
+
export class MonitoredDBFunction {
|
124
117
|
/**
|
125
118
|
* Create new MonitoredDBFunction. Use topics from given DigitrafficStack. Generate names from given name and configuration shortName.
|
126
119
|
* Grant secret and create log subscription.
|
@@ -137,20 +130,19 @@ class MonitoredDBFunction {
|
|
137
130
|
*/
|
138
131
|
static create(stack, name, environment, functionParameters) {
|
139
132
|
const functionName = functionParameters?.functionName ??
|
140
|
-
`${stack.configuration.shortName}-${
|
133
|
+
`${stack.configuration.shortName}-${_.chain(name)
|
141
134
|
.camelCase()
|
142
135
|
.startCase()
|
143
136
|
.replace(/\s/g, "")
|
144
137
|
.value()}`;
|
145
138
|
const env = environment ? environment : stack.createLambdaEnvironment();
|
146
|
-
const functionProps =
|
139
|
+
const functionProps = databaseFunctionProps(stack, env, functionName, name, functionParameters);
|
147
140
|
const mf = MonitoredFunction.create(stack, functionName, functionProps, functionParameters);
|
148
141
|
stack.grantSecret(mf);
|
149
142
|
if (stack.configuration.logsDestinationArn) {
|
150
|
-
new
|
143
|
+
new DigitrafficLogSubscriptions(stack, mf);
|
151
144
|
}
|
152
145
|
return mf;
|
153
146
|
}
|
154
147
|
}
|
155
|
-
exports.MonitoredDBFunction = MonitoredDBFunction;
|
156
148
|
//# sourceMappingURL=monitoredfunction.js.map
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import { StringParameter } from "aws-cdk-lib/aws-ssm";
|
2
|
-
import { Construct } from "constructs
|
2
|
+
import { type Construct } from "constructs";
|
3
3
|
declare const PARAMETERS: {
|
4
4
|
readonly "topic.alarm": {
|
5
5
|
readonly parameterName: "/digitraffic/monitoring/alarm-topic";
|
@@ -1,7 +1,4 @@
|
|
1
|
-
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.createParameter = exports.getParameterValue = void 0;
|
4
|
-
const aws_ssm_1 = require("aws-cdk-lib/aws-ssm");
|
1
|
+
import { StringParameter } from "aws-cdk-lib/aws-ssm";
|
5
2
|
const SSM_ROOT = "/digitraffic";
|
6
3
|
const MONITORING_ROOT = "/monitoring";
|
7
4
|
const DB_ROOT = "/db";
|
@@ -38,18 +35,16 @@ const PARAMETERS = {
|
|
38
35
|
description: "Proxy writer endpoint",
|
39
36
|
},
|
40
37
|
};
|
41
|
-
function getParameterValue(scope, parameterType) {
|
38
|
+
export function getParameterValue(scope, parameterType) {
|
42
39
|
const parameterName = PARAMETERS[parameterType].parameterName;
|
43
|
-
return
|
40
|
+
return StringParameter.valueForStringParameter(scope, parameterName);
|
44
41
|
}
|
45
|
-
|
46
|
-
function createParameter(scope, parameterType, stringValue) {
|
42
|
+
export function createParameter(scope, parameterType, stringValue) {
|
47
43
|
const { id, parameterName, description } = PARAMETERS[parameterType];
|
48
|
-
return new
|
44
|
+
return new StringParameter(scope, id, {
|
49
45
|
parameterName,
|
50
46
|
description,
|
51
47
|
stringValue,
|
52
48
|
});
|
53
49
|
}
|
54
|
-
exports.createParameter = createParameter;
|
55
50
|
//# sourceMappingURL=parameters.js.map
|
@@ -1,9 +1,9 @@
|
|
1
1
|
import { IResource, JsonSchema, Resource, RestApi, RestApiProps } from "aws-cdk-lib/aws-apigateway";
|
2
2
|
import { PolicyDocument } from "aws-cdk-lib/aws-iam";
|
3
3
|
import { Construct } from "constructs";
|
4
|
-
import { ModelWithReference } from "../../types/model-with-reference";
|
5
|
-
import { DocumentationPart } from "../documentation";
|
6
|
-
import { DigitrafficStack } from "./stack";
|
4
|
+
import { ModelWithReference } from "../../types/model-with-reference.js";
|
5
|
+
import { DocumentationPart } from "../documentation.js";
|
6
|
+
import { DigitrafficStack } from "./stack.js";
|
7
7
|
export declare class DigitrafficRestApi extends RestApi {
|
8
8
|
readonly apiKeyIds: string[];
|
9
9
|
readonly enableDocumentation: boolean;
|