@digitraffic/common 2025.9.4-1 → 2025.9.9-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/sqs-queue.js +4 -3
- package/dist/aws/infra/stack/lambda-configs.d.ts +4 -2
- package/dist/aws/infra/stack/lambda-configs.js +5 -6
- package/dist/aws/infra/stack/lambda-log-group.d.ts +3 -0
- package/dist/aws/infra/stack/lambda-log-group.js +8 -0
- package/dist/aws/infra/stack/monitoredfunction.js +5 -2
- package/dist/aws/infra/stack/subscription.js +2 -2
- package/package.json +20 -19
|
@@ -3,13 +3,13 @@ import { Duration } from "aws-cdk-lib";
|
|
|
3
3
|
import { BlockPublicAccess, Bucket } from "aws-cdk-lib/aws-s3";
|
|
4
4
|
import { PolicyStatement } from "aws-cdk-lib/aws-iam";
|
|
5
5
|
import { InlineCode, Runtime } from "aws-cdk-lib/aws-lambda";
|
|
6
|
-
import { RetentionDays } from "aws-cdk-lib/aws-logs";
|
|
7
6
|
import { SqsEventSource } from "aws-cdk-lib/aws-lambda-event-sources";
|
|
8
7
|
import { ComparisonOperator, TreatMissingData, } from "aws-cdk-lib/aws-cloudwatch";
|
|
9
8
|
import { SnsAction } from "aws-cdk-lib/aws-cloudwatch-actions";
|
|
10
9
|
import { MonitoredFunction } from "./stack/monitoredfunction.js";
|
|
11
10
|
import { PutObjectCommand, S3Client, } from "@aws-sdk/client-s3";
|
|
12
11
|
import { logger } from "../runtime/dt-logger-default.js";
|
|
12
|
+
import { createLambdaLogGroup } from "./stack/lambda-log-group.js";
|
|
13
13
|
const DLQ_LAMBDA_CODE = `
|
|
14
14
|
import type { ObjectCannedACL } from "@aws-sdk/client-s3";
|
|
15
15
|
import { PutObjectCommand, S3Client } from "@aws-sdk/client-s3";
|
|
@@ -60,6 +60,7 @@ export class DigitrafficSqsQueue extends Queue {
|
|
|
60
60
|
export class DigitrafficDLQueue {
|
|
61
61
|
static create(stack, name) {
|
|
62
62
|
const dlqName = `${stack.configuration.shortName}-${name}-DLQ`;
|
|
63
|
+
const dlqFunctionName = `${dlqName}-Function`;
|
|
63
64
|
const dlq = new DigitrafficSqsQueue(stack, dlqName, {
|
|
64
65
|
queueName: dlqName,
|
|
65
66
|
visibilityTimeout: Duration.seconds(60),
|
|
@@ -68,10 +69,10 @@ export class DigitrafficDLQueue {
|
|
|
68
69
|
const dlqBucket = new Bucket(stack, `${dlqName}-Bucket`, {
|
|
69
70
|
blockPublicAccess: BlockPublicAccess.BLOCK_ALL,
|
|
70
71
|
});
|
|
71
|
-
const
|
|
72
|
+
const dlqLogGroup = createLambdaLogGroup(stack, dlqFunctionName);
|
|
72
73
|
const lambda = MonitoredFunction.create(stack, dlqFunctionName, {
|
|
73
74
|
runtime: Runtime.NODEJS_22_X,
|
|
74
|
-
|
|
75
|
+
logGroup: dlqLogGroup,
|
|
75
76
|
functionName: dlqFunctionName,
|
|
76
77
|
code: getDlqCode(dlqBucket.bucketName),
|
|
77
78
|
timeout: Duration.seconds(10),
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Architecture, type Code, type FunctionProps, Runtime } from "aws-cdk-lib/aws-lambda";
|
|
2
2
|
import type { IVpc, SubnetSelection } from "aws-cdk-lib/aws-ec2";
|
|
3
|
+
import type { ILogGroup } from "aws-cdk-lib/aws-logs";
|
|
3
4
|
import type { Role } from "aws-cdk-lib/aws-iam";
|
|
4
5
|
import type { DigitrafficStack } from "./stack.js";
|
|
5
6
|
import type { MonitoredFunctionAlarmProps } from "./monitoredfunction.js";
|
|
@@ -8,8 +9,8 @@ export type DBLambdaEnvironment = LambdaEnvironment & {
|
|
|
8
9
|
SECRET_ID?: string;
|
|
9
10
|
DB_APPLICATION: string;
|
|
10
11
|
};
|
|
11
|
-
export declare function databaseFunctionProps(stack: DigitrafficStack, environment: LambdaEnvironment, lambdaName: string, simpleLambdaName: string, config?: Partial<FunctionParameters>): FunctionProps;
|
|
12
|
-
export declare function lambdaFunctionProps(_: DigitrafficStack, environment: LambdaEnvironment, lambdaName: string, simpleLambdaName: string, config?: Partial<FunctionParameters>): FunctionProps;
|
|
12
|
+
export declare function databaseFunctionProps(stack: DigitrafficStack, environment: LambdaEnvironment, lambdaName: string, simpleLambdaName: string, logGroup: ILogGroup, config?: Partial<FunctionParameters>): FunctionProps;
|
|
13
|
+
export declare function lambdaFunctionProps(_: DigitrafficStack, environment: LambdaEnvironment, lambdaName: string, simpleLambdaName: string, logGroup: ILogGroup, config?: Partial<FunctionParameters>): FunctionProps;
|
|
13
14
|
export declare function defaultLambdaConfiguration(config: FunctionParameters): FunctionProps;
|
|
14
15
|
export interface FunctionParameters {
|
|
15
16
|
memorySize?: number;
|
|
@@ -17,6 +18,7 @@ export interface FunctionParameters {
|
|
|
17
18
|
functionName?: string;
|
|
18
19
|
code: Code;
|
|
19
20
|
handler: string;
|
|
21
|
+
logGroup: ILogGroup;
|
|
20
22
|
readOnly?: boolean;
|
|
21
23
|
environment?: Record<string, string>;
|
|
22
24
|
reservedConcurrentExecutions?: number;
|
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
import { Architecture, AssetCode, Runtime, } from "aws-cdk-lib/aws-lambda";
|
|
2
2
|
import { Duration } from "aws-cdk-lib";
|
|
3
|
-
|
|
4
|
-
export function databaseFunctionProps(stack, environment, lambdaName, simpleLambdaName, config) {
|
|
3
|
+
export function databaseFunctionProps(stack, environment, lambdaName, simpleLambdaName, logGroup, config) {
|
|
5
4
|
const vpcSubnets = stack.vpc
|
|
6
5
|
? {
|
|
7
6
|
subnets: stack.vpc.privateSubnets,
|
|
8
7
|
}
|
|
9
8
|
: undefined;
|
|
10
9
|
return {
|
|
11
|
-
...lambdaFunctionProps(stack, environment, lambdaName, simpleLambdaName, config),
|
|
10
|
+
...lambdaFunctionProps(stack, environment, lambdaName, simpleLambdaName, logGroup, config),
|
|
12
11
|
...{
|
|
13
12
|
vpc: stack.vpc ?? undefined,
|
|
14
13
|
vpcSubnets,
|
|
@@ -16,7 +15,7 @@ export function databaseFunctionProps(stack, environment, lambdaName, simpleLamb
|
|
|
16
15
|
},
|
|
17
16
|
};
|
|
18
17
|
}
|
|
19
|
-
export function lambdaFunctionProps(_, environment, lambdaName, simpleLambdaName, config) {
|
|
18
|
+
export function lambdaFunctionProps(_, environment, lambdaName, simpleLambdaName, logGroup, config) {
|
|
20
19
|
return {
|
|
21
20
|
runtime: config?.runtime ?? Runtime.NODEJS_22_X,
|
|
22
21
|
architecture: config?.architecture ?? Architecture.ARM_64,
|
|
@@ -24,7 +23,7 @@ export function lambdaFunctionProps(_, environment, lambdaName, simpleLambdaName
|
|
|
24
23
|
functionName: lambdaName,
|
|
25
24
|
role: config?.role,
|
|
26
25
|
timeout: Duration.seconds(config?.timeout ?? 60),
|
|
27
|
-
|
|
26
|
+
logGroup: logGroup,
|
|
28
27
|
reservedConcurrentExecutions: config?.reservedConcurrentExecutions ?? 2,
|
|
29
28
|
code: getAssetCode(simpleLambdaName, config?.singleLambda ?? false),
|
|
30
29
|
handler: `${simpleLambdaName}.handler`,
|
|
@@ -44,7 +43,7 @@ export function defaultLambdaConfiguration(config) {
|
|
|
44
43
|
functionName: config.functionName,
|
|
45
44
|
handler: config.handler,
|
|
46
45
|
environment: config.environment ?? {},
|
|
47
|
-
|
|
46
|
+
logGroup: config.logGroup,
|
|
48
47
|
reservedConcurrentExecutions: config.reservedConcurrentExecutions,
|
|
49
48
|
code: config.code,
|
|
50
49
|
role: config.role,
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { LogGroup, RetentionDays } from "aws-cdk-lib/aws-logs";
|
|
2
|
+
export function createLambdaLogGroup(stack, functionName, retention = RetentionDays.ONE_YEAR) {
|
|
3
|
+
return new LogGroup(stack, `${functionName}-LogGroup`, {
|
|
4
|
+
logGroupName: `/${stack.configuration.shortName}/lambda/${functionName}`,
|
|
5
|
+
retention,
|
|
6
|
+
});
|
|
7
|
+
}
|
|
8
|
+
//# sourceMappingURL=lambda-log-group.js.map
|
|
@@ -3,6 +3,7 @@ import { SnsAction } from "aws-cdk-lib/aws-cloudwatch-actions";
|
|
|
3
3
|
import { ComparisonOperator } from "aws-cdk-lib/aws-cloudwatch";
|
|
4
4
|
import { databaseFunctionProps, } from "./lambda-configs.js";
|
|
5
5
|
import { chain } from "lodash-es";
|
|
6
|
+
import { createLambdaLogGroup } from "./lambda-log-group.js";
|
|
6
7
|
/**
|
|
7
8
|
* Creates a Lambda function that monitors default CloudWatch Lambda metrics with CloudWatch Alarms.
|
|
8
9
|
*/
|
|
@@ -105,7 +106,8 @@ export class MonitoredFunction extends Function {
|
|
|
105
106
|
.startCase()
|
|
106
107
|
.replace(/\s/g, "")
|
|
107
108
|
.value()}`;
|
|
108
|
-
const
|
|
109
|
+
const logGroup = createLambdaLogGroup(stack, functionName);
|
|
110
|
+
const functionProps = databaseFunctionProps(stack, environment, functionName, name, logGroup, functionParameters);
|
|
109
111
|
return MonitoredFunction.create(stack, functionName, functionProps, functionParameters);
|
|
110
112
|
}
|
|
111
113
|
createAlarm(stack, metric, alarmId, alarmName, alarmDescription, trafficType, alarmSnsAction, threshold, evaluationPeriods, datapointsToAlarm, comparisonOperator, alarmProps) {
|
|
@@ -147,8 +149,9 @@ export class MonitoredDBFunction {
|
|
|
147
149
|
.startCase()
|
|
148
150
|
.replace(/\s/g, "")
|
|
149
151
|
.value()}`;
|
|
152
|
+
const logGroup = createLambdaLogGroup(stack, functionName);
|
|
150
153
|
const env = environment ? environment : stack.createLambdaEnvironment();
|
|
151
|
-
const functionProps = databaseFunctionProps(stack, env, functionName, name, functionParameters);
|
|
154
|
+
const functionProps = databaseFunctionProps(stack, env, functionName, name, logGroup, functionParameters);
|
|
152
155
|
const mf = MonitoredFunction.create(stack, functionName, functionProps, functionParameters);
|
|
153
156
|
stack.grantSecret(mf);
|
|
154
157
|
return mf;
|
|
@@ -12,7 +12,7 @@ export function createSubscription(lambda, lambdaName, logDestinationArn, stack)
|
|
|
12
12
|
return undefined;
|
|
13
13
|
}
|
|
14
14
|
const filter = new CfnSubscriptionFilter(stack, `${lambdaName}LogsSubscription`, {
|
|
15
|
-
logGroupName:
|
|
15
|
+
logGroupName: lambda.logGroup.logGroupName,
|
|
16
16
|
filterPattern: "",
|
|
17
17
|
destinationArn: logDestinationArn,
|
|
18
18
|
});
|
|
@@ -25,7 +25,7 @@ export class DigitrafficLogSubscriptions {
|
|
|
25
25
|
if (destinationArn !== undefined) {
|
|
26
26
|
lambdas.forEach((lambda) => {
|
|
27
27
|
const filter = new CfnSubscriptionFilter(stack, `${lambda.givenName}LogsSubscription`, {
|
|
28
|
-
logGroupName:
|
|
28
|
+
logGroupName: lambda.logGroup.logGroupName,
|
|
29
29
|
filterPattern: "",
|
|
30
30
|
destinationArn,
|
|
31
31
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@digitraffic/common",
|
|
3
|
-
"version": "2025.9.
|
|
3
|
+
"version": "2025.9.9-1",
|
|
4
4
|
"description": "",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"repository": {
|
|
@@ -72,6 +72,7 @@
|
|
|
72
72
|
"./dist/aws/infra/stack/stack-checking-aspect": "./dist/aws/infra/stack/stack-checking-aspect.js",
|
|
73
73
|
"./dist/aws/infra/stack/rest_apis": "./dist/aws/infra/stack/rest_apis.js",
|
|
74
74
|
"./dist/aws/infra/stack/lambda-configs": "./dist/aws/infra/stack/lambda-configs.js",
|
|
75
|
+
"./dist/aws/infra/stack/lambda-log-group": "./dist/aws/infra/stack/lambda-log-group.js",
|
|
75
76
|
"./dist/aws/infra/stack/monitoredfunction": "./dist/aws/infra/stack/monitoredfunction.js",
|
|
76
77
|
"./dist/aws/infra/stack/subscription": "./dist/aws/infra/stack/subscription.js",
|
|
77
78
|
"./dist/aws/infra/stack/parameters": "./dist/aws/infra/stack/parameters.js",
|
|
@@ -111,8 +112,8 @@
|
|
|
111
112
|
"@aws-sdk/client-sns": "^3.864.0",
|
|
112
113
|
"@aws-sdk/lib-storage": "^3.864.0",
|
|
113
114
|
"@date-fns/tz": "^1.4.1",
|
|
114
|
-
"@smithy/node-http-handler": "^4.1.1",
|
|
115
115
|
"@smithy/fetch-http-handler": "^5.1.1",
|
|
116
|
+
"@smithy/node-http-handler": "^4.1.1",
|
|
116
117
|
"aws-cdk-lib": "^2.211.0",
|
|
117
118
|
"change-case": "^5.4.4",
|
|
118
119
|
"constructs": "^10.4.2",
|
|
@@ -126,21 +127,21 @@
|
|
|
126
127
|
"zod": "^3.25.76"
|
|
127
128
|
},
|
|
128
129
|
"devDependencies": {
|
|
129
|
-
"@aws-sdk/client-api-gateway": "^3.
|
|
130
|
-
"@aws-sdk/client-s3": "^3.
|
|
131
|
-
"@aws-sdk/client-secrets-manager": "^3.
|
|
132
|
-
"@aws-sdk/client-sns": "^3.
|
|
133
|
-
"@aws-sdk/lib-storage": "^3.
|
|
130
|
+
"@aws-sdk/client-api-gateway": "^3.882.0",
|
|
131
|
+
"@aws-sdk/client-s3": "^3.882.0",
|
|
132
|
+
"@aws-sdk/client-secrets-manager": "^3.882.0",
|
|
133
|
+
"@aws-sdk/client-sns": "^3.882.0",
|
|
134
|
+
"@aws-sdk/lib-storage": "^3.882.0",
|
|
134
135
|
"@date-fns/tz": "^1.4.1",
|
|
135
136
|
"@digitraffic/eslint-config": "^3.1.1",
|
|
136
|
-
"@jest/globals": "^30.
|
|
137
|
+
"@jest/globals": "^30.1.2",
|
|
137
138
|
"@rushstack/eslint-config": "^3.7.1",
|
|
138
|
-
"@rushstack/heft": "^0.74.
|
|
139
|
-
"@rushstack/heft-jest-plugin": "^0.16.
|
|
140
|
-
"@rushstack/heft-lint-plugin": "^0.5.
|
|
141
|
-
"@rushstack/heft-typescript-plugin": "^0.9.
|
|
139
|
+
"@rushstack/heft": "^0.74.3",
|
|
140
|
+
"@rushstack/heft-jest-plugin": "^0.16.12",
|
|
141
|
+
"@rushstack/heft-lint-plugin": "^0.5.38",
|
|
142
|
+
"@rushstack/heft-typescript-plugin": "^0.9.12",
|
|
142
143
|
"@smithy/fetch-http-handler": "5.1.1",
|
|
143
|
-
"@smithy/types": "^4.
|
|
144
|
+
"@smithy/types": "^4.4.0",
|
|
144
145
|
"@types/aws-lambda": "8.10.152",
|
|
145
146
|
"@types/etag": "^1.8.4",
|
|
146
147
|
"@types/geojson": "7946.0.16",
|
|
@@ -149,21 +150,21 @@
|
|
|
149
150
|
"@types/lodash-es": "4.17.12",
|
|
150
151
|
"@types/madge": "5.0.3",
|
|
151
152
|
"@types/node": "22.15.23",
|
|
152
|
-
"@typescript-eslint/eslint-plugin": "^7.
|
|
153
|
+
"@typescript-eslint/eslint-plugin": "^7.18.0",
|
|
153
154
|
"@typescript-eslint/parser": "^7.18.0",
|
|
154
|
-
"aws-cdk-lib": "^2.
|
|
155
|
+
"aws-cdk-lib": "^2.214.0",
|
|
155
156
|
"aws-sdk": "^2.1692.0",
|
|
156
157
|
"change-case": "^5.4.4",
|
|
157
158
|
"constructs": "^10.4.2",
|
|
158
159
|
"date-fns": "^4.1.0",
|
|
159
160
|
"eslint": "^8.57.1",
|
|
160
|
-
"eslint-config-prettier": "^9.1.
|
|
161
|
+
"eslint-config-prettier": "^9.1.2",
|
|
161
162
|
"eslint-plugin-deprecation": "^3.0.0",
|
|
162
163
|
"etag": "^1.8.1",
|
|
163
164
|
"geojson-validation": "^1.0.2",
|
|
164
|
-
"jest": "^30.
|
|
165
|
+
"jest": "^30.1.3",
|
|
165
166
|
"jest-junit": "^16.0.0",
|
|
166
|
-
"ky": "^1.
|
|
167
|
+
"ky": "^1.10.0",
|
|
167
168
|
"lefthook": "^1.12.3",
|
|
168
169
|
"lodash": "^4.17.21",
|
|
169
170
|
"lodash-es": "^4.17.21",
|
|
@@ -172,7 +173,7 @@
|
|
|
172
173
|
"pg-promise": "^11.15.0",
|
|
173
174
|
"rimraf": "^6.0.1",
|
|
174
175
|
"ts-jest": "^29.4.1",
|
|
175
|
-
"typescript": "^5.
|
|
176
|
+
"typescript": "^5.9.2",
|
|
176
177
|
"velocityjs": "^2.1.5",
|
|
177
178
|
"zod": "^3.25.76"
|
|
178
179
|
},
|