@digitraffic/common 2024.1.10-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 +30 -35
- 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 +24 -31
- package/dist/aws/infra/stack/stack.d.ts +3 -4
- 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 +14 -18
- 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.js +10 -14
- 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 +107 -18
- 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 +2 -2
- package/src/aws/infra/stack/lambda-configs.ts +2 -2
- 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 +1 -1
- 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/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,30 +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 lib_storage_1 = require("@aws-sdk/lib-storage");
|
14
|
-
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";
|
15
12
|
/**
|
16
13
|
* Construct for creating SQS-queues.
|
17
14
|
*
|
18
15
|
* If you don't config your own deadLetterQueue, this will create a dlq for you, also a lambda function, a s3 bucket
|
19
16
|
* and an alarm for the queue. Anything that goes to the dlq will be written into the bucket and the alarm is activated.
|
20
17
|
*/
|
21
|
-
class DigitrafficSqsQueue extends
|
18
|
+
export class DigitrafficSqsQueue extends Queue {
|
22
19
|
static create(stack, name, props) {
|
23
20
|
const queueName = `${stack.configuration.shortName}-${name}-Queue`;
|
24
21
|
const queueProps = {
|
25
22
|
...props,
|
26
23
|
...{
|
27
|
-
encryption:
|
24
|
+
encryption: QueueEncryption.KMS_MANAGED,
|
28
25
|
queueName,
|
29
26
|
deadLetterQueue: props.deadLetterQueue ?? {
|
30
27
|
maxReceiveCount: 2,
|
@@ -35,60 +32,58 @@ class DigitrafficSqsQueue extends aws_sqs_1.Queue {
|
|
35
32
|
return new DigitrafficSqsQueue(stack, queueName, queueProps);
|
36
33
|
}
|
37
34
|
}
|
38
|
-
|
39
|
-
class DigitrafficDLQueue {
|
35
|
+
export class DigitrafficDLQueue {
|
40
36
|
static create(stack, name) {
|
41
37
|
const dlqName = `${stack.configuration.shortName}-${name}-DLQ`;
|
42
38
|
const dlq = new DigitrafficSqsQueue(stack, dlqName, {
|
43
39
|
queueName: dlqName,
|
44
|
-
visibilityTimeout:
|
45
|
-
encryption:
|
40
|
+
visibilityTimeout: Duration.seconds(60),
|
41
|
+
encryption: QueueEncryption.KMS_MANAGED,
|
46
42
|
});
|
47
|
-
const dlqBucket = new
|
48
|
-
blockPublicAccess:
|
43
|
+
const dlqBucket = new Bucket(stack, `${dlqName}-Bucket`, {
|
44
|
+
blockPublicAccess: BlockPublicAccess.BLOCK_ALL,
|
49
45
|
});
|
50
46
|
const dlqFunctionName = `${dlqName}-Function`;
|
51
|
-
const lambda =
|
52
|
-
runtime:
|
53
|
-
logRetention:
|
47
|
+
const lambda = MonitoredFunction.create(stack, dlqFunctionName, {
|
48
|
+
runtime: Runtime.NODEJS_20_X,
|
49
|
+
logRetention: RetentionDays.ONE_YEAR,
|
54
50
|
functionName: dlqFunctionName,
|
55
51
|
code: getDlqCode(dlqBucket.bucketName),
|
56
|
-
timeout:
|
52
|
+
timeout: Duration.seconds(10),
|
57
53
|
handler: "index.handler",
|
58
54
|
memorySize: 128,
|
59
55
|
reservedConcurrentExecutions: 1,
|
60
56
|
});
|
61
|
-
const statement = new
|
57
|
+
const statement = new PolicyStatement();
|
62
58
|
statement.addActions("s3:PutObject");
|
63
59
|
statement.addActions("s3:PutObjectAcl");
|
64
60
|
statement.addResources(dlqBucket.bucketArn + "/*");
|
65
61
|
lambda.addToRolePolicy(statement);
|
66
|
-
lambda.addEventSource(new
|
62
|
+
lambda.addEventSource(new SqsEventSource(dlq));
|
67
63
|
addDLQAlarm(stack, dlqName, dlq);
|
68
64
|
return dlq;
|
69
65
|
}
|
70
66
|
}
|
71
|
-
exports.DigitrafficDLQueue = DigitrafficDLQueue;
|
72
67
|
function addDLQAlarm(stack, dlqName, dlq) {
|
73
68
|
const alarmName = `${dlqName}-Alarm`;
|
74
69
|
dlq.metricNumberOfMessagesReceived({
|
75
|
-
period:
|
70
|
+
period: Duration.minutes(5),
|
76
71
|
})
|
77
72
|
.createAlarm(stack, alarmName, {
|
78
73
|
alarmName,
|
79
74
|
threshold: 0,
|
80
75
|
evaluationPeriods: 1,
|
81
|
-
treatMissingData:
|
82
|
-
comparisonOperator:
|
76
|
+
treatMissingData: TreatMissingData.NOT_BREACHING,
|
77
|
+
comparisonOperator: ComparisonOperator.GREATER_THAN_THRESHOLD,
|
83
78
|
})
|
84
|
-
.addAlarmAction(new
|
79
|
+
.addAlarmAction(new SnsAction(stack.warningTopic));
|
85
80
|
}
|
86
81
|
function getDlqCode(Bucket) {
|
87
82
|
const functionBody = DLQ_LAMBDA_CODE.replace("__bucketName__", Bucket)
|
88
83
|
.replace("__upload__", uploadToS3.toString())
|
89
84
|
.replace("__doUpload__", doUpload.toString())
|
90
85
|
.replace("__handler__", createHandler().toString().substring(23)); // remove function handler() from signature
|
91
|
-
return new
|
86
|
+
return new InlineCode(functionBody);
|
92
87
|
}
|
93
88
|
async function uploadToS3(s3, Bucket, Body, Key) {
|
94
89
|
try {
|
@@ -108,7 +103,7 @@ async function uploadToS3(s3, Bucket, Body, Key) {
|
|
108
103
|
}
|
109
104
|
async function doUpload(s3, Bucket, Body, Key) {
|
110
105
|
try {
|
111
|
-
const upload = new
|
106
|
+
const upload = new Upload({
|
112
107
|
client: s3,
|
113
108
|
params: { Bucket, Key, Body },
|
114
109
|
});
|
@@ -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;
|
@@ -1,16 +1,10 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
};
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
const aws_iam_1 = require("aws-cdk-lib/aws-iam");
|
9
|
-
const api_model_1 = require("../../../utils/api-model");
|
10
|
-
const mediatypes_1 = require("../../types/mediatypes");
|
11
|
-
const usage_plans_1 = require("../usage-plans");
|
12
|
-
const lodash_1 = __importDefault(require("lodash"));
|
13
|
-
class DigitrafficRestApi extends aws_apigateway_1.RestApi {
|
1
|
+
import { CfnDocumentationPart, EndpointType, GatewayResponse, MethodLoggingLevel, MockIntegration, ResponseType, RestApi, } from "aws-cdk-lib/aws-apigateway";
|
2
|
+
import { AnyPrincipal, Effect, PolicyDocument, PolicyStatement, } from "aws-cdk-lib/aws-iam";
|
3
|
+
import { getModelReference } from "../../../utils/api-model.js";
|
4
|
+
import { MediaType } from "../../types/mediatypes.js";
|
5
|
+
import { createDefaultUsagePlan, createUsagePlan } from "../usage-plans.js";
|
6
|
+
import _ from "lodash";
|
7
|
+
export class DigitrafficRestApi extends RestApi {
|
14
8
|
constructor(stack, apiId, apiName, allowFromIpAddresses, config) {
|
15
9
|
const policyDocument = allowFromIpAddresses == null
|
16
10
|
? createDefaultPolicyDocument()
|
@@ -19,10 +13,10 @@ class DigitrafficRestApi extends aws_apigateway_1.RestApi {
|
|
19
13
|
const apiConfig = {
|
20
14
|
...{
|
21
15
|
deployOptions: {
|
22
|
-
loggingLevel:
|
16
|
+
loggingLevel: MethodLoggingLevel.ERROR,
|
23
17
|
},
|
24
18
|
restApiName: apiName,
|
25
|
-
endpointTypes: [
|
19
|
+
endpointTypes: [EndpointType.REGIONAL],
|
26
20
|
policy: policyDocument,
|
27
21
|
},
|
28
22
|
...config,
|
@@ -37,31 +31,31 @@ class DigitrafficRestApi extends aws_apigateway_1.RestApi {
|
|
37
31
|
return `${this.restApiId}.execute-api.${this.stack.region}.amazonaws.com`;
|
38
32
|
}
|
39
33
|
createUsagePlan(apiKeyId, apiKeyName) {
|
40
|
-
const newKeyId =
|
34
|
+
const newKeyId = createUsagePlan(this, apiKeyId, apiKeyName).keyId;
|
41
35
|
this.apiKeyIds.push(newKeyId);
|
42
36
|
return newKeyId;
|
43
37
|
}
|
44
38
|
createUsagePlanV2(apiName, apiKey) {
|
45
|
-
const newKeyId =
|
39
|
+
const newKeyId = createDefaultUsagePlan(this, apiName, apiKey).keyId;
|
46
40
|
this.apiKeyIds.push(newKeyId);
|
47
41
|
return newKeyId;
|
48
42
|
}
|
49
43
|
addJsonModel(modelName, schema) {
|
50
44
|
return this.getModelWithReference(this.addModel(modelName, {
|
51
|
-
contentType:
|
45
|
+
contentType: MediaType.APPLICATION_JSON,
|
52
46
|
modelName,
|
53
47
|
schema,
|
54
48
|
}));
|
55
49
|
}
|
56
50
|
addCSVModel(modelName) {
|
57
51
|
return this.getModelWithReference(this.addModel(modelName, {
|
58
|
-
contentType:
|
52
|
+
contentType: MediaType.TEXT_CSV,
|
59
53
|
modelName,
|
60
54
|
schema: {},
|
61
55
|
}));
|
62
56
|
}
|
63
57
|
getModelWithReference(model) {
|
64
|
-
return
|
58
|
+
return _.set(model, "modelReference", getModelReference(model.modelId, this.restApiId));
|
65
59
|
}
|
66
60
|
addDocumentationPart(resource, parameterName, resourceName, type, properties) {
|
67
61
|
const location = {
|
@@ -69,7 +63,7 @@ class DigitrafficRestApi extends aws_apigateway_1.RestApi {
|
|
69
63
|
path: resource.path,
|
70
64
|
name: type !== "METHOD" ? parameterName : undefined,
|
71
65
|
};
|
72
|
-
new
|
66
|
+
new CfnDocumentationPart(this.stack, resourceName, {
|
73
67
|
restApiId: resource.api.restApiId,
|
74
68
|
location,
|
75
69
|
properties: JSON.stringify(properties),
|
@@ -89,7 +83,7 @@ class DigitrafficRestApi extends aws_apigateway_1.RestApi {
|
|
89
83
|
* @param apiResource
|
90
84
|
*/
|
91
85
|
addCorsOptions(apiResource) {
|
92
|
-
apiResource.addMethod("OPTIONS", new
|
86
|
+
apiResource.addMethod("OPTIONS", new MockIntegration({
|
93
87
|
integrationResponses: [
|
94
88
|
{
|
95
89
|
statusCode: "200",
|
@@ -117,7 +111,6 @@ class DigitrafficRestApi extends aws_apigateway_1.RestApi {
|
|
117
111
|
});
|
118
112
|
}
|
119
113
|
}
|
120
|
-
exports.DigitrafficRestApi = DigitrafficRestApi;
|
121
114
|
/**
|
122
115
|
* Due to AWS API design API Gateway will always return 403 'Missing Authentication Token' for requests
|
123
116
|
* with a non-existent endpoint. This function translates this response to a 404.
|
@@ -125,28 +118,26 @@ exports.DigitrafficRestApi = DigitrafficRestApi;
|
|
125
118
|
* @param restApi RestApi
|
126
119
|
* @param stack Construct
|
127
120
|
*/
|
128
|
-
function add404Support(restApi, stack) {
|
129
|
-
new
|
121
|
+
export function add404Support(restApi, stack) {
|
122
|
+
new GatewayResponse(stack, `MissingAuthenticationTokenResponse-${restApi.restApiName}`, {
|
130
123
|
restApi,
|
131
|
-
type:
|
124
|
+
type: ResponseType.MISSING_AUTHENTICATION_TOKEN,
|
132
125
|
statusCode: "404",
|
133
126
|
templates: {
|
134
|
-
[
|
127
|
+
[MediaType.APPLICATION_JSON]: '{"message": "Not found"}',
|
135
128
|
},
|
136
129
|
});
|
137
130
|
}
|
138
|
-
|
139
|
-
|
140
|
-
new aws_apigateway_1.GatewayResponse(stack, `AuthenticationFailedResponse-${restApi.restApiName}`, {
|
131
|
+
export function add401Support(restApi, stack) {
|
132
|
+
new GatewayResponse(stack, `AuthenticationFailedResponse-${restApi.restApiName}`, {
|
141
133
|
restApi,
|
142
|
-
type:
|
134
|
+
type: ResponseType.UNAUTHORIZED,
|
143
135
|
statusCode: "401",
|
144
136
|
responseHeaders: {
|
145
137
|
"WWW-Authenticate": "'Basic'",
|
146
138
|
},
|
147
139
|
});
|
148
140
|
}
|
149
|
-
exports.add401Support = add401Support;
|
150
141
|
/**
|
151
142
|
* Due to AWS API design API Gateway will always return 403 'Missing Authentication Token' for requests
|
152
143
|
* with a non-existent endpoint. This function converts this response to a custom one.
|
@@ -156,51 +147,48 @@ exports.add401Support = add401Support;
|
|
156
147
|
* @param restApi RestApi
|
157
148
|
* @param stack Construct
|
158
149
|
*/
|
159
|
-
function setReturnCodeForMissingAuthenticationToken(returnCode, message, restApi, stack) {
|
160
|
-
new
|
150
|
+
export function setReturnCodeForMissingAuthenticationToken(returnCode, message, restApi, stack) {
|
151
|
+
new GatewayResponse(stack, `MissingAuthenticationTokenResponse-${restApi.restApiName}`, {
|
161
152
|
restApi,
|
162
|
-
type:
|
153
|
+
type: ResponseType.MISSING_AUTHENTICATION_TOKEN,
|
163
154
|
statusCode: `${returnCode}`,
|
164
155
|
templates: {
|
165
|
-
[
|
156
|
+
[MediaType.APPLICATION_JSON]: `{"message": ${message}}`,
|
166
157
|
},
|
167
158
|
});
|
168
159
|
}
|
169
|
-
|
170
|
-
function createRestApi(stack, apiId, apiName, allowFromIpAddresses) {
|
160
|
+
export function createRestApi(stack, apiId, apiName, allowFromIpAddresses) {
|
171
161
|
const policyDocument = allowFromIpAddresses == null
|
172
162
|
? createDefaultPolicyDocument()
|
173
163
|
: createIpRestrictionPolicyDocument(allowFromIpAddresses);
|
174
|
-
const restApi = new
|
164
|
+
const restApi = new RestApi(stack, apiId, {
|
175
165
|
deployOptions: {
|
176
|
-
loggingLevel:
|
166
|
+
loggingLevel: MethodLoggingLevel.ERROR,
|
177
167
|
},
|
178
168
|
restApiName: apiName,
|
179
|
-
endpointTypes: [
|
169
|
+
endpointTypes: [EndpointType.REGIONAL],
|
180
170
|
policy: policyDocument,
|
181
171
|
});
|
182
172
|
add404Support(restApi, stack);
|
183
173
|
return restApi;
|
184
174
|
}
|
185
|
-
|
186
|
-
|
187
|
-
return new aws_iam_1.PolicyDocument({
|
175
|
+
export function createDefaultPolicyDocument() {
|
176
|
+
return new PolicyDocument({
|
188
177
|
statements: [
|
189
|
-
new
|
190
|
-
effect:
|
178
|
+
new PolicyStatement({
|
179
|
+
effect: Effect.ALLOW,
|
191
180
|
actions: ["execute-api:Invoke"],
|
192
181
|
resources: ["*"],
|
193
|
-
principals: [new
|
182
|
+
principals: [new AnyPrincipal()],
|
194
183
|
}),
|
195
184
|
],
|
196
185
|
});
|
197
186
|
}
|
198
|
-
|
199
|
-
|
200
|
-
return new aws_iam_1.PolicyDocument({
|
187
|
+
export function createIpRestrictionPolicyDocument(allowFromIpAddresses) {
|
188
|
+
return new PolicyDocument({
|
201
189
|
statements: [
|
202
|
-
new
|
203
|
-
effect:
|
190
|
+
new PolicyStatement({
|
191
|
+
effect: Effect.ALLOW,
|
204
192
|
conditions: {
|
205
193
|
IpAddress: {
|
206
194
|
"aws:SourceIp": allowFromIpAddresses,
|
@@ -208,10 +196,9 @@ function createIpRestrictionPolicyDocument(allowFromIpAddresses) {
|
|
208
196
|
},
|
209
197
|
actions: ["execute-api:Invoke"],
|
210
198
|
resources: ["*"],
|
211
|
-
principals: [new
|
199
|
+
principals: [new AnyPrincipal()],
|
212
200
|
}),
|
213
201
|
],
|
214
202
|
});
|
215
203
|
}
|
216
|
-
exports.createIpRestrictionPolicyDocument = createIpRestrictionPolicyDocument;
|
217
204
|
//# sourceMappingURL=rest_apis.js.map
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import { IAspect } from "aws-cdk-lib";
|
2
|
-
import { DigitrafficStack } from "./stack";
|
2
|
+
import { DigitrafficStack } from "./stack.js";
|
3
3
|
import { IConstruct } from "constructs";
|
4
4
|
export declare class StackCheckingAspect implements IAspect {
|
5
5
|
private readonly stackShortName?;
|