quidproquo-deploy-awscdk 0.0.93 → 0.0.95
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/lib/constants/logging.d.ts +1 -0
- package/lib/constants/logging.js +2 -1
- package/lib/constructs/basic/Function.js +17 -0
- package/lib/constructs/basic/LogStorage.js +16 -0
- package/lib/lambdas/lambda-utils/getRuntimeCorrelation.d.ts +2 -0
- package/lib/lambdas/lambda-utils/getRuntimeCorrelation.js +10 -0
- package/lib/lambdas/lambda-utils/index.d.ts +2 -0
- package/lib/lambdas/lambda-utils/index.js +18 -0
- package/lib/lambdas/{logger → lambda-utils}/logger.js +17 -9
- package/lib/lambdas/lambdaAPIGatewayEvent.js +6 -2
- package/lib/lambdas/lambdaEventBridgeEvent.js +5 -4
- package/lib/lambdas/lambdaEventOriginRequest.js +5 -4
- package/lib/lambdas/lambdaS3FileWriteEvent_log.d.ts +2 -0
- package/lib/lambdas/lambdaS3FileWriteEvent_log.js +26 -1
- package/lib/lambdas/lambdaSQSEvent.d.ts +2 -1
- package/lib/lambdas/lambdaSQSEvent.js +11 -5
- package/lib/lambdas/lambdaServiceFunctionExecute.d.ts +7 -2
- package/lib/lambdas/lambdaServiceFunctionExecute.js +8 -5
- package/lib/lambdas/storyResultToMetadata/genericTextExtractors/index.d.ts +2 -0
- package/lib/lambdas/storyResultToMetadata/genericTextExtractors/index.js +2 -0
- package/lib/lambdas/storyResultToMetadata/genericTextExtractors/queueEventGenericTextExtractor.d.ts +2 -0
- package/lib/lambdas/storyResultToMetadata/genericTextExtractors/queueEventGenericTextExtractor.js +11 -0
- package/lib/lambdas/storyResultToMetadata/genericTextExtractors/serviceFunctionExeGenericTextExtractor.d.ts +2 -0
- package/lib/lambdas/storyResultToMetadata/genericTextExtractors/serviceFunctionExeGenericTextExtractor.js +11 -0
- package/lib/lambdas/storyResultToMetadata/storyResultToMetadata.js +3 -3
- package/lib/stacks/InfQpqServiceStack.js +4 -4
- package/package.json +1 -1
- package/src/constants/logging.ts +1 -0
- package/src/constructs/basic/Function.ts +24 -0
- package/src/constructs/basic/LogStorage.ts +19 -1
- package/src/lambdas/lambda-utils/getRuntimeCorrelation.ts +7 -0
- package/src/lambdas/lambda-utils/index.ts +2 -0
- package/src/lambdas/{logger → lambda-utils}/logger.ts +4 -0
- package/src/lambdas/lambdaAPIGatewayEvent.ts +7 -3
- package/src/lambdas/lambdaEventBridgeEvent.ts +11 -7
- package/src/lambdas/lambdaEventOriginRequest.ts +10 -6
- package/src/lambdas/lambdaS3FileWriteEvent_log.ts +35 -0
- package/src/lambdas/lambdaSQSEvent.ts +27 -5
- package/src/lambdas/lambdaServiceFunctionExecute.ts +21 -9
- package/src/lambdas/storyResultToMetadata/genericTextExtractors/index.ts +2 -0
- package/src/lambdas/storyResultToMetadata/genericTextExtractors/queueEventGenericTextExtractor.ts +9 -0
- package/src/lambdas/storyResultToMetadata/genericTextExtractors/serviceFunctionExeGenericTextExtractor.ts +9 -0
- package/src/lambdas/storyResultToMetadata/storyResultToMetadata.ts +10 -4
- package/src/stacks/InfQpqServiceStack.ts +4 -4
- /package/lib/lambdas/{logger → lambda-utils}/logger.d.ts +0 -0
package/lib/constants/logging.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.QPQ_LOG_BUCKET_NAME = void 0;
|
|
3
|
+
exports.QPQ_FROM_LOG_BUCKET_NAME = exports.QPQ_LOG_BUCKET_NAME = void 0;
|
|
4
4
|
exports.QPQ_LOG_BUCKET_NAME = 'logs';
|
|
5
|
+
exports.QPQ_FROM_LOG_BUCKET_NAME = 'flogs';
|
|
@@ -71,6 +71,23 @@ class Function extends QpqConstructBlock_1.QpqConstructBlock {
|
|
|
71
71
|
actions: ['lambda:InvokeFunction'],
|
|
72
72
|
resources: ['arn:aws:lambda:*:*:function:*sfunc*'],
|
|
73
73
|
}));
|
|
74
|
+
// Let lambdas write to dynamo logs
|
|
75
|
+
this.lambdaFunction.addToRolePolicy(new aws_cdk_lib_1.aws_iam.PolicyStatement({
|
|
76
|
+
actions: ['lambda:InvokeFunction'],
|
|
77
|
+
resources: ['arn:aws:lambda:*:*:function:*sfunc*'],
|
|
78
|
+
}));
|
|
79
|
+
// We need access to dynamo log tables
|
|
80
|
+
this.lambdaFunction.addToRolePolicy(new aws_cdk_lib_1.aws_iam.PolicyStatement({
|
|
81
|
+
actions: ['dynamodb:GetItem', 'dynamodb:Scan', 'dynamodb:Query', 'dynamodb:PutItem'],
|
|
82
|
+
// TODO: Revisit this, the user can make logs tables them selves... ~ Slight security risk here
|
|
83
|
+
// Consider making tags to identify logs tables, all qpq resourses
|
|
84
|
+
// conditions: {
|
|
85
|
+
// 'ForAllValues:StringLike': {
|
|
86
|
+
// 'aws:ResourceTag/Name': '*qpqlog',
|
|
87
|
+
// },
|
|
88
|
+
// },
|
|
89
|
+
resources: ['arn:aws:dynamodb:*:*:table/logs-*', 'arn:aws:dynamodb:*:*:table/flogs-*'],
|
|
90
|
+
}));
|
|
74
91
|
}
|
|
75
92
|
}
|
|
76
93
|
exports.Function = Function;
|
|
@@ -70,6 +70,7 @@ class LogStorage extends QpqConstructBlock_1.QpqConstructBlock {
|
|
|
70
70
|
removalPolicy: cdk.RemovalPolicy.DESTROY,
|
|
71
71
|
autoDeleteObjects: true,
|
|
72
72
|
});
|
|
73
|
+
// Time based query over all logs for a given runtimeType
|
|
73
74
|
const storyResultsTable = new aws_cdk_lib_1.aws_dynamodb.Table(this, 'table', {
|
|
74
75
|
tableName: this.qpqResourceName(constants_1.QPQ_LOG_BUCKET_NAME, 'log'),
|
|
75
76
|
partitionKey: { name: 'runtimeType', type: aws_cdk_lib_1.aws_dynamodb.AttributeType.STRING },
|
|
@@ -77,6 +78,21 @@ class LogStorage extends QpqConstructBlock_1.QpqConstructBlock {
|
|
|
77
78
|
billingMode: aws_cdk_lib_1.aws_dynamodb.BillingMode.PAY_PER_REQUEST,
|
|
78
79
|
removalPolicy: cdk.RemovalPolicy.DESTROY,
|
|
79
80
|
});
|
|
81
|
+
// Query by correlation
|
|
82
|
+
storyResultsTable.addGlobalSecondaryIndex({
|
|
83
|
+
indexName: 'CorrelationIndex',
|
|
84
|
+
partitionKey: { name: 'correlation', type: aws_cdk_lib_1.aws_dynamodb.AttributeType.STRING },
|
|
85
|
+
});
|
|
86
|
+
// Second table for the from logs ~ Second table because a GSI will dupe the data more then needed
|
|
87
|
+
// Also, we cant have a GSI on keys that can be undefined, this table will only contain
|
|
88
|
+
// logs with a fromCorrelation
|
|
89
|
+
const fromStoryResultsTable = new aws_cdk_lib_1.aws_dynamodb.Table(this, 'from-table', {
|
|
90
|
+
tableName: this.qpqResourceName(constants_1.QPQ_FROM_LOG_BUCKET_NAME, 'flog'),
|
|
91
|
+
partitionKey: { name: 'fromCorrelation', type: aws_cdk_lib_1.aws_dynamodb.AttributeType.STRING },
|
|
92
|
+
sortKey: { name: 'startedAtWithCorrelation', type: aws_cdk_lib_1.aws_dynamodb.AttributeType.STRING },
|
|
93
|
+
billingMode: aws_cdk_lib_1.aws_dynamodb.BillingMode.PAY_PER_REQUEST,
|
|
94
|
+
removalPolicy: cdk.RemovalPolicy.DESTROY,
|
|
95
|
+
});
|
|
80
96
|
this.table = storyResultsTable;
|
|
81
97
|
// Create a lambda that is trigged when files are written to the bucket
|
|
82
98
|
const func = new Function_1.Function(this, 'function', {
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getRuntimeCorrelation = void 0;
|
|
4
|
+
const quidproquo_core_1 = require("quidproquo-core");
|
|
5
|
+
const quidproquo_actionprocessor_awslambda_1 = require("quidproquo-actionprocessor-awslambda");
|
|
6
|
+
const getRuntimeCorrelation = (qpqConfig) => {
|
|
7
|
+
const moduleName = quidproquo_core_1.qpqCoreUtils.getApplicationModuleName(qpqConfig);
|
|
8
|
+
return `${moduleName}-${quidproquo_actionprocessor_awslambda_1.awsLambdaUtils.randomGuid()}`;
|
|
9
|
+
};
|
|
10
|
+
exports.getRuntimeCorrelation = getRuntimeCorrelation;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./getRuntimeCorrelation"), exports);
|
|
18
|
+
__exportStar(require("./logger"), exports);
|
|
@@ -10,19 +10,27 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.getLogger = exports.storyLogger = void 0;
|
|
13
|
-
const client_s3_1 = require("@aws-sdk/client-s3");
|
|
14
|
-
const quidproquo_actionprocessor_awslambda_1 = require("quidproquo-actionprocessor-awslambda");
|
|
15
|
-
const quidproquo_core_1 = require("quidproquo-core");
|
|
16
|
-
const constants_1 = require("../../constants");
|
|
17
13
|
const storyLogger = (result, qpqConfig) => __awaiter(void 0, void 0, void 0, function* () {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
const
|
|
21
|
-
|
|
14
|
+
/*
|
|
15
|
+
|
|
16
|
+
const bucketName = awsNamingUtils.getQpqRuntimeResourceNameFromConfig(
|
|
17
|
+
QPQ_LOG_BUCKET_NAME,
|
|
18
|
+
qpqConfig,
|
|
19
|
+
'log',
|
|
20
|
+
);
|
|
21
|
+
const region = qpqCoreUtils.getApplicationModuleDeployRegion(qpqConfig);
|
|
22
|
+
|
|
23
|
+
const s3Client = new S3Client({ region });
|
|
24
|
+
|
|
25
|
+
await s3Client.send(
|
|
26
|
+
new PutObjectCommand({
|
|
22
27
|
Key: `${result.correlation}.json`,
|
|
23
28
|
Bucket: bucketName,
|
|
24
29
|
Body: JSON.stringify(result),
|
|
25
|
-
|
|
30
|
+
}),
|
|
31
|
+
);
|
|
32
|
+
|
|
33
|
+
*/
|
|
26
34
|
});
|
|
27
35
|
exports.storyLogger = storyLogger;
|
|
28
36
|
const getLogger = (qpqConfig) => (result) => __awaiter(void 0, void 0, void 0, function* () {
|
|
@@ -18,7 +18,7 @@ const quidproquo_actionprocessor_awslambda_1 = require("quidproquo-actionprocess
|
|
|
18
18
|
const quidproquo_webserver_1 = require("quidproquo-webserver");
|
|
19
19
|
const quidproquo_core_1 = require("quidproquo-core");
|
|
20
20
|
const lambdaConfig_1 = require("./lambdaConfig");
|
|
21
|
-
const
|
|
21
|
+
const lambda_utils_1 = require("./lambda-utils");
|
|
22
22
|
const dynamicModuleLoader_1 = require("./dynamicModuleLoader");
|
|
23
23
|
// @ts-ignore - Special webpack loader
|
|
24
24
|
const qpq_custom_action_processors_loader_1 = __importDefault(require("qpq-custom-action-processors-loader!"));
|
|
@@ -42,10 +42,14 @@ const ErrorTypeHttpResponseMap = {
|
|
|
42
42
|
const getAPIGatewayEventExecutor = (getCustomActionProcessors = () => ({})) => {
|
|
43
43
|
return (event, context) => __awaiter(void 0, void 0, void 0, function* () {
|
|
44
44
|
const cdkConfig = yield (0, lambdaConfig_1.getLambdaConfigs)();
|
|
45
|
+
const accessToken = quidproquo_webserver_1.qpqWebServerUtils.getAccessTokenFromHeaders(event.headers);
|
|
45
46
|
// Build a processor for the session and stuff
|
|
46
47
|
// Remove the non route ones ~ let the story execute action add them
|
|
47
48
|
const storyActionProcessor = Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, quidproquo_actionprocessor_node_1.coreActionProcessor), quidproquo_actionprocessor_node_1.webserverActionProcessor), (0, quidproquo_actionprocessor_awslambda_1.getAPIGatewayEventActionProcessor)(cdkConfig.qpqConfig)), (0, quidproquo_actionprocessor_awslambda_1.getConfigGetSecretActionProcessor)(cdkConfig.qpqConfig)), (0, quidproquo_actionprocessor_awslambda_1.getConfigGetParameterActionProcessor)(cdkConfig.qpqConfig)), (0, quidproquo_actionprocessor_awslambda_1.getConfigGetParametersActionProcessor)(cdkConfig.qpqConfig)), (0, quidproquo_actionprocessor_awslambda_1.getSystemActionProcessor)(cdkConfig.qpqConfig, dynamicModuleLoader_1.dynamicModuleLoader)), (0, quidproquo_actionprocessor_awslambda_1.getFileActionProcessor)(cdkConfig.qpqConfig)), (0, quidproquo_actionprocessor_node_1.getConfigActionProcessor)(cdkConfig.qpqConfig)), (0, quidproquo_actionprocessor_awslambda_1.getQueueActionProcessor)(cdkConfig.qpqConfig)), (0, quidproquo_actionprocessor_awslambda_1.getEventBusActionProcessor)(cdkConfig.qpqConfig)), (0, quidproquo_actionprocessor_awslambda_1.getUserDirectoryActionProcessor)(cdkConfig.qpqConfig)), (0, quidproquo_actionprocessor_awslambda_1.getWebEntryActionProcessor)(cdkConfig.qpqConfig)), (0, quidproquo_actionprocessor_awslambda_1.getServiceFunctionActionProcessor)(cdkConfig.qpqConfig)), (0, quidproquo_actionprocessor_awslambda_1.getAdminActionProcessor)(cdkConfig.qpqConfig)), getCustomActionProcessors(cdkConfig.qpqConfig)), (0, qpq_custom_action_processors_loader_1.default)());
|
|
48
|
-
const resolveStory = (0, quidproquo_core_1.createRuntime)(cdkConfig.qpqConfig, {
|
|
49
|
+
const resolveStory = (0, quidproquo_core_1.createRuntime)(cdkConfig.qpqConfig, {
|
|
50
|
+
depth: 0,
|
|
51
|
+
accessToken: accessToken,
|
|
52
|
+
}, storyActionProcessor, getDateNow, (0, lambda_utils_1.getLogger)(cdkConfig.qpqConfig), (0, lambda_utils_1.getRuntimeCorrelation)(cdkConfig.qpqConfig), quidproquo_core_1.QpqRuntimeType.API);
|
|
49
53
|
const result = yield resolveStory(quidproquo_core_1.askProcessEvent, [event, context]);
|
|
50
54
|
// Run the callback
|
|
51
55
|
if (!result.error) {
|
|
@@ -15,10 +15,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
15
15
|
exports.executeEventBridgeEvent = exports.getEventBridgeEventExecutor = void 0;
|
|
16
16
|
const quidproquo_actionprocessor_node_1 = require("quidproquo-actionprocessor-node");
|
|
17
17
|
const quidproquo_actionprocessor_awslambda_1 = require("quidproquo-actionprocessor-awslambda");
|
|
18
|
-
const quidproquo_actionprocessor_node_2 = require("quidproquo-actionprocessor-node");
|
|
19
18
|
const quidproquo_core_1 = require("quidproquo-core");
|
|
20
19
|
const lambdaConfig_1 = require("./lambdaConfig");
|
|
21
|
-
const
|
|
20
|
+
const lambda_utils_1 = require("./lambda-utils");
|
|
22
21
|
const dynamicModuleLoader_1 = require("./dynamicModuleLoader");
|
|
23
22
|
// @ts-ignore - Special webpack loader
|
|
24
23
|
const qpq_custom_action_processors_loader_1 = __importDefault(require("qpq-custom-action-processors-loader!"));
|
|
@@ -30,8 +29,10 @@ const getEventBridgeEventExecutor = (dynamicModuleLoader, getCustomActionProcess
|
|
|
30
29
|
const lambdaRuntimeConfig = JSON.parse(process.env.lambdaRuntimeConfig || '{}');
|
|
31
30
|
// Build a processor for the session and stuff
|
|
32
31
|
// Remove the non event ones
|
|
33
|
-
const storyActionProcessor = Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, quidproquo_actionprocessor_node_1.coreActionProcessor), quidproquo_actionprocessor_node_1.webserverActionProcessor), (0, quidproquo_actionprocessor_awslambda_1.getEventBridgeEventActionProcessor)(lambdaRuntimeConfig)), (0, quidproquo_actionprocessor_awslambda_1.getSystemActionProcessor)(cdkConfig.qpqConfig, dynamicModuleLoader)), (0, quidproquo_actionprocessor_awslambda_1.getFileActionProcessor)(cdkConfig.qpqConfig)), (0, quidproquo_actionprocessor_awslambda_1.getConfigGetSecretActionProcessor)(cdkConfig.qpqConfig)), (0, quidproquo_actionprocessor_awslambda_1.getConfigGetParameterActionProcessor)(cdkConfig.qpqConfig)), (0, quidproquo_actionprocessor_awslambda_1.getConfigGetParametersActionProcessor)(cdkConfig.qpqConfig)), (0,
|
|
34
|
-
const resolveStory = (0, quidproquo_core_1.createRuntime)(cdkConfig.qpqConfig, {
|
|
32
|
+
const storyActionProcessor = Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, quidproquo_actionprocessor_node_1.coreActionProcessor), quidproquo_actionprocessor_node_1.webserverActionProcessor), (0, quidproquo_actionprocessor_awslambda_1.getEventBridgeEventActionProcessor)(lambdaRuntimeConfig)), (0, quidproquo_actionprocessor_awslambda_1.getSystemActionProcessor)(cdkConfig.qpqConfig, dynamicModuleLoader)), (0, quidproquo_actionprocessor_awslambda_1.getFileActionProcessor)(cdkConfig.qpqConfig)), (0, quidproquo_actionprocessor_awslambda_1.getConfigGetSecretActionProcessor)(cdkConfig.qpqConfig)), (0, quidproquo_actionprocessor_awslambda_1.getConfigGetParameterActionProcessor)(cdkConfig.qpqConfig)), (0, quidproquo_actionprocessor_awslambda_1.getConfigGetParametersActionProcessor)(cdkConfig.qpqConfig)), (0, quidproquo_actionprocessor_node_1.getConfigActionProcessor)(cdkConfig.qpqConfig)), (0, quidproquo_actionprocessor_awslambda_1.getQueueActionProcessor)(cdkConfig.qpqConfig)), (0, quidproquo_actionprocessor_awslambda_1.getEventBusActionProcessor)(cdkConfig.qpqConfig)), (0, quidproquo_actionprocessor_awslambda_1.getWebEntryActionProcessor)(cdkConfig.qpqConfig)), (0, quidproquo_actionprocessor_awslambda_1.getServiceFunctionActionProcessor)(cdkConfig.qpqConfig)), (0, quidproquo_actionprocessor_awslambda_1.getAdminActionProcessor)(cdkConfig.qpqConfig)), (0, quidproquo_actionprocessor_awslambda_1.getUserDirectoryActionProcessor)(cdkConfig.qpqConfig)), getCustomActionProcessors(cdkConfig.qpqConfig)), (0, qpq_custom_action_processors_loader_1.default)());
|
|
33
|
+
const resolveStory = (0, quidproquo_core_1.createRuntime)(cdkConfig.qpqConfig, {
|
|
34
|
+
depth: 0,
|
|
35
|
+
}, storyActionProcessor, getDateNow, (0, lambda_utils_1.getLogger)(cdkConfig.qpqConfig), (0, lambda_utils_1.getRuntimeCorrelation)(cdkConfig.qpqConfig), quidproquo_core_1.QpqRuntimeType.RECURRING_SCHEDULE);
|
|
35
36
|
yield resolveStory(quidproquo_core_1.askProcessEvent, [event, context]);
|
|
36
37
|
});
|
|
37
38
|
};
|
|
@@ -15,10 +15,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
15
15
|
exports.executeEventOriginRequest = exports.getOriginRequestEventExecutor = void 0;
|
|
16
16
|
const quidproquo_actionprocessor_node_1 = require("quidproquo-actionprocessor-node");
|
|
17
17
|
const quidproquo_actionprocessor_awslambda_1 = require("quidproquo-actionprocessor-awslambda");
|
|
18
|
-
const quidproquo_actionprocessor_node_2 = require("quidproquo-actionprocessor-node");
|
|
19
18
|
const lambdaConfig_1 = require("./lambdaConfig");
|
|
20
19
|
const quidproquo_core_1 = require("quidproquo-core");
|
|
21
|
-
const
|
|
20
|
+
const lambda_utils_1 = require("./lambda-utils");
|
|
22
21
|
const dynamicModuleLoader_1 = require("./dynamicModuleLoader");
|
|
23
22
|
// @ts-ignore - Special webpack loader
|
|
24
23
|
const qpq_custom_action_processors_loader_1 = __importDefault(require("qpq-custom-action-processors-loader!"));
|
|
@@ -30,8 +29,10 @@ const getOriginRequestEventExecutor = (dynamicModuleLoader, getCustomActionProce
|
|
|
30
29
|
const cdkConfig = yield (0, lambdaConfig_1.getLambdaConfigs)();
|
|
31
30
|
// Build a processor for the session and stuff
|
|
32
31
|
// Remove the non route ones ~ let the story execute action add them
|
|
33
|
-
const storyActionProcessor = Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, quidproquo_actionprocessor_node_1.coreActionProcessor), quidproquo_actionprocessor_node_1.webserverActionProcessor), (0, quidproquo_actionprocessor_awslambda_1.getCloudFrontOriginRequestEventActionProcessor)(cdkConfig.qpqConfig)), (0, quidproquo_actionprocessor_awslambda_1.getConfigGetSecretActionProcessor)(cdkConfig.qpqConfig)), (0, quidproquo_actionprocessor_awslambda_1.getConfigGetParameterActionProcessor)(cdkConfig.qpqConfig)), (0, quidproquo_actionprocessor_awslambda_1.getConfigGetParametersActionProcessor)(cdkConfig.qpqConfig)), (0, quidproquo_actionprocessor_awslambda_1.getSystemActionProcessor)(cdkConfig.qpqConfig, dynamicModuleLoader)), (0, quidproquo_actionprocessor_awslambda_1.getFileActionProcessor)(cdkConfig.qpqConfig)), (0,
|
|
34
|
-
const resolveStory = (0, quidproquo_core_1.createRuntime)(cdkConfig.qpqConfig, {
|
|
32
|
+
const storyActionProcessor = Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, quidproquo_actionprocessor_node_1.coreActionProcessor), quidproquo_actionprocessor_node_1.webserverActionProcessor), (0, quidproquo_actionprocessor_awslambda_1.getCloudFrontOriginRequestEventActionProcessor)(cdkConfig.qpqConfig)), (0, quidproquo_actionprocessor_awslambda_1.getConfigGetSecretActionProcessor)(cdkConfig.qpqConfig)), (0, quidproquo_actionprocessor_awslambda_1.getConfigGetParameterActionProcessor)(cdkConfig.qpqConfig)), (0, quidproquo_actionprocessor_awslambda_1.getConfigGetParametersActionProcessor)(cdkConfig.qpqConfig)), (0, quidproquo_actionprocessor_awslambda_1.getSystemActionProcessor)(cdkConfig.qpqConfig, dynamicModuleLoader)), (0, quidproquo_actionprocessor_awslambda_1.getFileActionProcessor)(cdkConfig.qpqConfig)), (0, quidproquo_actionprocessor_node_1.getConfigActionProcessor)(cdkConfig.qpqConfig)), (0, quidproquo_actionprocessor_awslambda_1.getWebEntryActionProcessor)(cdkConfig.qpqConfig)), (0, quidproquo_actionprocessor_awslambda_1.getServiceFunctionActionProcessor)(cdkConfig.qpqConfig)), (0, quidproquo_actionprocessor_awslambda_1.getAdminActionProcessor)(cdkConfig.qpqConfig)), (0, quidproquo_actionprocessor_awslambda_1.getUserDirectoryActionProcessor)(cdkConfig.qpqConfig)), getCustomActionProcessors(cdkConfig.qpqConfig)), (0, qpq_custom_action_processors_loader_1.default)());
|
|
33
|
+
const resolveStory = (0, quidproquo_core_1.createRuntime)(cdkConfig.qpqConfig, {
|
|
34
|
+
depth: 0,
|
|
35
|
+
}, storyActionProcessor, getDateNow, (0, lambda_utils_1.getLogger)(cdkConfig.qpqConfig), (0, lambda_utils_1.getRuntimeCorrelation)(cdkConfig.qpqConfig), quidproquo_core_1.QpqRuntimeType.EVENT_SEO_OR);
|
|
35
36
|
const result = yield resolveStory(quidproquo_core_1.askProcessEvent, [event, context]);
|
|
36
37
|
// Run the callback
|
|
37
38
|
if (!result.error) {
|
|
@@ -1,2 +1,4 @@
|
|
|
1
1
|
import { S3Handler } from 'aws-lambda';
|
|
2
|
+
import { StoryResultMetadata } from 'quidproquo-core';
|
|
3
|
+
export declare const getFromCorrelationBucketNameFromLog: (storyResultMetadata: StoryResultMetadata, localBucketName: string) => string;
|
|
2
4
|
export declare const executeS3FileWriteEvent: S3Handler;
|
|
@@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.executeS3FileWriteEvent = void 0;
|
|
12
|
+
exports.executeS3FileWriteEvent = exports.getFromCorrelationBucketNameFromLog = void 0;
|
|
13
13
|
const client_s3_1 = require("@aws-sdk/client-s3");
|
|
14
14
|
const client_dynamodb_1 = require("@aws-sdk/client-dynamodb");
|
|
15
15
|
const storyResultToMetadata_1 = require("./storyResultToMetadata");
|
|
@@ -51,13 +51,38 @@ const writeStoryResultMetadataToDynamo = (tableName, storyResultMetadata, region
|
|
|
51
51
|
console.error(`Failed to insert storyResultMetadata into DynamoDB: ${err}`);
|
|
52
52
|
}
|
|
53
53
|
});
|
|
54
|
+
const getFromCorrelationBucketNameFromLog = (storyResultMetadata, localBucketName) => {
|
|
55
|
+
if (!storyResultMetadata.fromCorrelation) {
|
|
56
|
+
return '';
|
|
57
|
+
}
|
|
58
|
+
// Get the module name of the service that wants the log
|
|
59
|
+
const fromModuleName = storyResultMetadata.fromCorrelation.split('::')[0];
|
|
60
|
+
// Get the name of the current module where we are executing this code
|
|
61
|
+
const currentModuleName = storyResultMetadata.moduleName;
|
|
62
|
+
// Split up the bucket / module names into parts
|
|
63
|
+
const bucketParts = localBucketName.split('-');
|
|
64
|
+
const moduleParts = fromModuleName.split('-');
|
|
65
|
+
const currentModuleNameParts = currentModuleName.split('-');
|
|
66
|
+
// Replace the current module name with the module name of the service that wants the log
|
|
67
|
+
bucketParts.splice(2, currentModuleNameParts.length, ...moduleParts);
|
|
68
|
+
// rebuild the new bucket name
|
|
69
|
+
const newBucketName = bucketParts.join('-');
|
|
70
|
+
return newBucketName;
|
|
71
|
+
};
|
|
72
|
+
exports.getFromCorrelationBucketNameFromLog = getFromCorrelationBucketNameFromLog;
|
|
54
73
|
const executeS3FileWriteEvent = (event) => __awaiter(void 0, void 0, void 0, function* () {
|
|
55
74
|
for (const record of event.Records) {
|
|
56
75
|
const bucketName = record.s3.bucket.name;
|
|
57
76
|
const awsRegion = record.awsRegion;
|
|
58
77
|
const key = record.s3.object.key;
|
|
59
78
|
const storyResultMetadata = yield readLogFromBucket(bucketName, awsRegion, key);
|
|
79
|
+
// Write the main log to the service table
|
|
60
80
|
yield writeStoryResultMetadataToDynamo(bucketName, storyResultMetadata, awsRegion);
|
|
81
|
+
// Write the same log to the table of the from service, so it can query links on the fromGuid GSI
|
|
82
|
+
const fromBucketName = (0, exports.getFromCorrelationBucketNameFromLog)(storyResultMetadata, bucketName);
|
|
83
|
+
if (fromBucketName) {
|
|
84
|
+
yield writeStoryResultMetadataToDynamo(fromBucketName, storyResultMetadata, awsRegion);
|
|
85
|
+
}
|
|
61
86
|
}
|
|
62
87
|
});
|
|
63
88
|
exports.executeS3FileWriteEvent = executeS3FileWriteEvent;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { SQSEvent, SQSBatchResponse, Context } from 'aws-lambda';
|
|
2
2
|
import { DynamicModuleLoader } from 'quidproquo-actionprocessor-awslambda';
|
|
3
|
+
import { StorySession } from 'quidproquo-core';
|
|
3
4
|
import { ActionProcessorListResolver } from './actionProcessorListResolver';
|
|
4
|
-
export declare const getStoryActionRuntime: (dynamicModuleLoader: DynamicModuleLoader, getCustomActionProcessors
|
|
5
|
+
export declare const getStoryActionRuntime: (dynamicModuleLoader: DynamicModuleLoader, getCustomActionProcessors: ActionProcessorListResolver | undefined, callerStorySession: StorySession) => Promise<(<TArgs extends any[]>(story: (...args: TArgs) => Generator<any, any, import("quidproquo-core").Action<any>>, args: TArgs) => Promise<import("quidproquo-core").StoryResult<any, any>>)>;
|
|
5
6
|
export declare const getSQSEventExecutor: (dynamicModuleLoader: DynamicModuleLoader, getCustomActionProcessors?: ActionProcessorListResolver) => (event: SQSEvent, context: Context) => Promise<SQSBatchResponse>;
|
|
6
7
|
export declare const executeSQSEvent: (event: SQSEvent, context: Context) => Promise<SQSBatchResponse>;
|
|
@@ -18,21 +18,22 @@ const quidproquo_actionprocessor_awslambda_1 = require("quidproquo-actionprocess
|
|
|
18
18
|
const quidproquo_actionprocessor_node_2 = require("quidproquo-actionprocessor-node");
|
|
19
19
|
const lambdaConfig_1 = require("./lambdaConfig");
|
|
20
20
|
const quidproquo_core_1 = require("quidproquo-core");
|
|
21
|
-
const
|
|
21
|
+
const lambda_utils_1 = require("./lambda-utils");
|
|
22
22
|
const dynamicModuleLoader_1 = require("./dynamicModuleLoader");
|
|
23
23
|
// @ts-ignore - Special webpack loader
|
|
24
24
|
const qpq_custom_action_processors_loader_1 = __importDefault(require("qpq-custom-action-processors-loader!"));
|
|
25
25
|
// TODO: Make this a util or something based on server time or something..
|
|
26
26
|
const getDateNow = () => new Date().toISOString();
|
|
27
|
-
const getStoryActionRuntime = (dynamicModuleLoader, getCustomActionProcessors = () => ({})) => __awaiter(void 0, void 0, void 0, function* () {
|
|
27
|
+
const getStoryActionRuntime = (dynamicModuleLoader, getCustomActionProcessors = () => ({}), callerStorySession) => __awaiter(void 0, void 0, void 0, function* () {
|
|
28
28
|
const cdkConfig = yield (0, lambdaConfig_1.getLambdaConfigs)();
|
|
29
29
|
// Build a processor for the session and stuff
|
|
30
30
|
// Remove the non route ones ~ let the story execute action add them
|
|
31
31
|
const storyActionProcessor = Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, quidproquo_actionprocessor_node_1.coreActionProcessor), quidproquo_actionprocessor_node_1.webserverActionProcessor), (0, quidproquo_actionprocessor_awslambda_1.getSQSEventRecordActionProcessor)(cdkConfig.qpqConfig)), (0, quidproquo_actionprocessor_awslambda_1.getConfigGetSecretActionProcessor)(cdkConfig.qpqConfig)), (0, quidproquo_actionprocessor_awslambda_1.getConfigGetParameterActionProcessor)(cdkConfig.qpqConfig)), (0, quidproquo_actionprocessor_awslambda_1.getConfigGetParametersActionProcessor)(cdkConfig.qpqConfig)), (0, quidproquo_actionprocessor_awslambda_1.getSystemActionProcessor)(cdkConfig.qpqConfig, dynamicModuleLoader)), (0, quidproquo_actionprocessor_awslambda_1.getFileActionProcessor)(cdkConfig.qpqConfig)), (0, quidproquo_actionprocessor_node_2.getConfigActionProcessor)(cdkConfig.qpqConfig)), (0, quidproquo_actionprocessor_awslambda_1.getQueueActionProcessor)(cdkConfig.qpqConfig)), (0, quidproquo_actionprocessor_awslambda_1.getEventBusActionProcessor)(cdkConfig.qpqConfig)), (0, quidproquo_actionprocessor_awslambda_1.getUserDirectoryActionProcessor)(cdkConfig.qpqConfig)), (0, quidproquo_actionprocessor_awslambda_1.getWebEntryActionProcessor)(cdkConfig.qpqConfig)), (0, quidproquo_actionprocessor_awslambda_1.getServiceFunctionActionProcessor)(cdkConfig.qpqConfig)), (0, quidproquo_actionprocessor_awslambda_1.getAdminActionProcessor)(cdkConfig.qpqConfig)), getCustomActionProcessors(cdkConfig.qpqConfig)), (0, qpq_custom_action_processors_loader_1.default)());
|
|
32
|
-
const resolveStory = (0, quidproquo_core_1.createRuntime)(cdkConfig.qpqConfig,
|
|
32
|
+
const resolveStory = (0, quidproquo_core_1.createRuntime)(cdkConfig.qpqConfig, callerStorySession, storyActionProcessor, getDateNow, (0, lambda_utils_1.getLogger)(cdkConfig.qpqConfig), (0, lambda_utils_1.getRuntimeCorrelation)(cdkConfig.qpqConfig), quidproquo_core_1.QpqRuntimeType.QUEUE_EVENT);
|
|
33
33
|
return resolveStory;
|
|
34
34
|
});
|
|
35
35
|
exports.getStoryActionRuntime = getStoryActionRuntime;
|
|
36
|
+
// TODO: We could make this entire function a story, that spawns an execute story for each record
|
|
36
37
|
const getSQSEventExecutor = (dynamicModuleLoader, getCustomActionProcessors = () => ({})) => {
|
|
37
38
|
return (event, context) => __awaiter(void 0, void 0, void 0, function* () {
|
|
38
39
|
// const queueQPQConfigSetting = getQueueConfigSetting();
|
|
@@ -40,10 +41,15 @@ const getSQSEventExecutor = (dynamicModuleLoader, getCustomActionProcessors = ()
|
|
|
40
41
|
// in parallel
|
|
41
42
|
console.log('num batch: ', event.Records.length);
|
|
42
43
|
const results = event.Records.map((record) => __awaiter(void 0, void 0, void 0, function* () {
|
|
43
|
-
const
|
|
44
|
+
const runtimeData = JSON.parse(record.body);
|
|
45
|
+
const resolveStory = yield (0, exports.getStoryActionRuntime)(dynamicModuleLoader, getCustomActionProcessors, runtimeData.storySession);
|
|
46
|
+
const queueMessage = {
|
|
47
|
+
type: runtimeData.type,
|
|
48
|
+
payload: runtimeData.payload,
|
|
49
|
+
};
|
|
44
50
|
return {
|
|
45
51
|
id: record.messageId,
|
|
46
|
-
result: yield resolveStory(quidproquo_core_1.askProcessEvent, [
|
|
52
|
+
result: yield resolveStory(quidproquo_core_1.askProcessEvent, [queueMessage, context]),
|
|
47
53
|
};
|
|
48
54
|
}));
|
|
49
55
|
const allResults = yield Promise.all(results);
|
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
import { ExecuteServiceFunctionEvent } from 'quidproquo-webserver';
|
|
2
2
|
import { DynamicModuleLoader } from 'quidproquo-actionprocessor-awslambda';
|
|
3
|
+
import { StorySession } from 'quidproquo-core';
|
|
3
4
|
import { Context } from 'aws-lambda';
|
|
4
5
|
import { ActionProcessorListResolver } from './actionProcessorListResolver';
|
|
5
|
-
|
|
6
|
-
|
|
6
|
+
type AnyExecuteServiceFunctionEventWithSession = ExecuteServiceFunctionEvent<any[]> & {
|
|
7
|
+
storySession: StorySession;
|
|
8
|
+
};
|
|
9
|
+
export declare const getServiceFunctionExecuteEventExecutor: (dynamicModuleLoader: DynamicModuleLoader, getCustomActionProcessors?: ActionProcessorListResolver) => (event: AnyExecuteServiceFunctionEventWithSession, context: Context) => Promise<import("quidproquo-core").StoryResult<any, any>>;
|
|
10
|
+
export declare const executeServiceFunctionExecuteEvent: (event: AnyExecuteServiceFunctionEventWithSession, context: Context) => Promise<import("quidproquo-core").StoryResult<any, any>>;
|
|
11
|
+
export {};
|
|
@@ -15,10 +15,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
15
15
|
exports.executeServiceFunctionExecuteEvent = exports.getServiceFunctionExecuteEventExecutor = void 0;
|
|
16
16
|
const quidproquo_actionprocessor_node_1 = require("quidproquo-actionprocessor-node");
|
|
17
17
|
const quidproquo_actionprocessor_awslambda_1 = require("quidproquo-actionprocessor-awslambda");
|
|
18
|
-
const quidproquo_actionprocessor_node_2 = require("quidproquo-actionprocessor-node");
|
|
19
18
|
const quidproquo_core_1 = require("quidproquo-core");
|
|
20
19
|
const lambdaConfig_1 = require("./lambdaConfig");
|
|
21
|
-
const
|
|
20
|
+
const lambda_utils_1 = require("./lambda-utils");
|
|
22
21
|
// @ts-ignore - Special webpack loader
|
|
23
22
|
const dynamicModuleLoader_1 = require("./dynamicModuleLoader");
|
|
24
23
|
// @ts-ignore - Special webpack loader
|
|
@@ -30,9 +29,13 @@ const getServiceFunctionExecuteEventExecutor = (dynamicModuleLoader, getCustomAc
|
|
|
30
29
|
const cdkConfig = yield (0, lambdaConfig_1.getLambdaConfigs)();
|
|
31
30
|
// Build a processor for the session and stuff
|
|
32
31
|
// Remove the non route ones ~ let the story execute action add them
|
|
33
|
-
const storyActionProcessor = Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, quidproquo_actionprocessor_node_1.coreActionProcessor), quidproquo_actionprocessor_node_1.webserverActionProcessor), (0, quidproquo_actionprocessor_awslambda_1.getServiceFunctionExecuteEventActionProcessor)(cdkConfig.qpqConfig)), (0, quidproquo_actionprocessor_awslambda_1.getConfigGetSecretActionProcessor)(cdkConfig.qpqConfig)), (0, quidproquo_actionprocessor_awslambda_1.getConfigGetParameterActionProcessor)(cdkConfig.qpqConfig)), (0, quidproquo_actionprocessor_awslambda_1.getConfigGetParametersActionProcessor)(cdkConfig.qpqConfig)), (0, quidproquo_actionprocessor_awslambda_1.getSystemActionProcessor)(cdkConfig.qpqConfig, dynamicModuleLoader)), (0, quidproquo_actionprocessor_awslambda_1.getFileActionProcessor)(cdkConfig.qpqConfig)), (0,
|
|
34
|
-
const resolveStory = (0, quidproquo_core_1.createRuntime)(cdkConfig.qpqConfig,
|
|
35
|
-
const
|
|
32
|
+
const storyActionProcessor = Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, quidproquo_actionprocessor_node_1.coreActionProcessor), quidproquo_actionprocessor_node_1.webserverActionProcessor), (0, quidproquo_actionprocessor_awslambda_1.getServiceFunctionExecuteEventActionProcessor)(cdkConfig.qpqConfig)), (0, quidproquo_actionprocessor_awslambda_1.getConfigGetSecretActionProcessor)(cdkConfig.qpqConfig)), (0, quidproquo_actionprocessor_awslambda_1.getConfigGetParameterActionProcessor)(cdkConfig.qpqConfig)), (0, quidproquo_actionprocessor_awslambda_1.getConfigGetParametersActionProcessor)(cdkConfig.qpqConfig)), (0, quidproquo_actionprocessor_awslambda_1.getSystemActionProcessor)(cdkConfig.qpqConfig, dynamicModuleLoader)), (0, quidproquo_actionprocessor_awslambda_1.getFileActionProcessor)(cdkConfig.qpqConfig)), (0, quidproquo_actionprocessor_node_1.getConfigActionProcessor)(cdkConfig.qpqConfig)), (0, quidproquo_actionprocessor_awslambda_1.getQueueActionProcessor)(cdkConfig.qpqConfig)), (0, quidproquo_actionprocessor_awslambda_1.getEventBusActionProcessor)(cdkConfig.qpqConfig)), (0, quidproquo_actionprocessor_awslambda_1.getUserDirectoryActionProcessor)(cdkConfig.qpqConfig)), (0, quidproquo_actionprocessor_awslambda_1.getWebEntryActionProcessor)(cdkConfig.qpqConfig)), (0, quidproquo_actionprocessor_awslambda_1.getServiceFunctionActionProcessor)(cdkConfig.qpqConfig)), (0, quidproquo_actionprocessor_awslambda_1.getAdminActionProcessor)(cdkConfig.qpqConfig)), getCustomActionProcessors(cdkConfig.qpqConfig)), (0, qpq_custom_action_processors_loader_1.default)());
|
|
33
|
+
const resolveStory = (0, quidproquo_core_1.createRuntime)(cdkConfig.qpqConfig, event.storySession, storyActionProcessor, getDateNow, (0, lambda_utils_1.getLogger)(cdkConfig.qpqConfig), (0, lambda_utils_1.getRuntimeCorrelation)(cdkConfig.qpqConfig), quidproquo_core_1.QpqRuntimeType.SERVICE_FUNCTION_EXE);
|
|
34
|
+
const eventWithNoSession = {
|
|
35
|
+
functionName: event.functionName,
|
|
36
|
+
payload: event.payload,
|
|
37
|
+
};
|
|
38
|
+
const result = yield resolveStory(quidproquo_core_1.askProcessEvent, [eventWithNoSession, context]);
|
|
36
39
|
// just return the story result
|
|
37
40
|
return result;
|
|
38
41
|
});
|
|
@@ -15,4 +15,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./apiGenericTextExtractor"), exports);
|
|
18
|
+
__exportStar(require("./queueEventGenericTextExtractor"), exports);
|
|
19
|
+
__exportStar(require("./serviceFunctionExeGenericTextExtractor"), exports);
|
|
18
20
|
__exportStar(require("./unknownGenericTextExtractor"), exports);
|
package/lib/lambdas/storyResultToMetadata/genericTextExtractors/queueEventGenericTextExtractor.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.queueEventGenericTextExtractor = void 0;
|
|
4
|
+
const queueEventGenericTextExtractor = (storyResult) => {
|
|
5
|
+
var _a;
|
|
6
|
+
if (storyResult.runtimeType === 'QUEUE_EVENT') {
|
|
7
|
+
return ((_a = storyResult.input[0]) === null || _a === void 0 ? void 0 : _a.type) || '';
|
|
8
|
+
}
|
|
9
|
+
return '';
|
|
10
|
+
};
|
|
11
|
+
exports.queueEventGenericTextExtractor = queueEventGenericTextExtractor;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.serviceFunctionExeGenericTextExtractor = void 0;
|
|
4
|
+
const serviceFunctionExeGenericTextExtractor = (storyResult) => {
|
|
5
|
+
var _a;
|
|
6
|
+
if (storyResult.runtimeType === 'SERVICE_FUNCTION_EXE') {
|
|
7
|
+
return ((_a = storyResult.input[0]) === null || _a === void 0 ? void 0 : _a.functionName) || '';
|
|
8
|
+
}
|
|
9
|
+
return '';
|
|
10
|
+
};
|
|
11
|
+
exports.serviceFunctionExeGenericTextExtractor = serviceFunctionExeGenericTextExtractor;
|
|
@@ -5,11 +5,11 @@ const genericTextExtractors_1 = require("./genericTextExtractors");
|
|
|
5
5
|
// These have to be strings and not enum due to how the lambda is packaged
|
|
6
6
|
const extractors = {
|
|
7
7
|
['API']: genericTextExtractors_1.apiGenericTextExtractor,
|
|
8
|
-
['
|
|
8
|
+
['QUEUE_EVENT']: genericTextExtractors_1.queueEventGenericTextExtractor,
|
|
9
|
+
['SERVICE_FUNCTION_EXE']: genericTextExtractors_1.serviceFunctionExeGenericTextExtractor,
|
|
10
|
+
['RECURRING_SCHEDULE']: genericTextExtractors_1.unknownGenericTextExtractor,
|
|
9
11
|
['EVENT_SEO_OR']: genericTextExtractors_1.unknownGenericTextExtractor,
|
|
10
12
|
['EXECUTE_STORY']: genericTextExtractors_1.unknownGenericTextExtractor,
|
|
11
|
-
['QUEUE_EVENT']: genericTextExtractors_1.unknownGenericTextExtractor,
|
|
12
|
-
['SERVICE_FUNCTION_EXE']: genericTextExtractors_1.unknownGenericTextExtractor,
|
|
13
13
|
};
|
|
14
14
|
const storyResultToMetadata = (storyResult, filepath) => {
|
|
15
15
|
var _a;
|
|
@@ -9,10 +9,10 @@ class InfQpqServiceStack extends QpqServiceStack_1.QpqServiceStack {
|
|
|
9
9
|
constructor(scope, id, props) {
|
|
10
10
|
super(scope, id, props);
|
|
11
11
|
// Build the log storage drive
|
|
12
|
-
const logBucket = new
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
}).bucket;
|
|
12
|
+
// const logBucket = new LogStorage(this, 'logStorage', {
|
|
13
|
+
// awsAccountId: props.awsAccountId,
|
|
14
|
+
// qpqConfig: props.qpqConfig,
|
|
15
|
+
// }).bucket;
|
|
16
16
|
// Build the storage drives
|
|
17
17
|
const storageDrives = quidproquo_core_1.qpqCoreUtils.getStorageDrives(props.qpqConfig).map((setting) => new constructs_1.QpqCoreStorageDriveConstruct(this, quidproquo_core_1.qpqCoreUtils.getUniqueKeyForSetting(setting), {
|
|
18
18
|
awsAccountId: props.awsAccountId,
|
package/package.json
CHANGED
package/src/constants/logging.ts
CHANGED
|
@@ -88,5 +88,29 @@ export class Function extends QpqConstructBlock {
|
|
|
88
88
|
resources: ['arn:aws:lambda:*:*:function:*sfunc*'],
|
|
89
89
|
}),
|
|
90
90
|
);
|
|
91
|
+
|
|
92
|
+
// Let lambdas write to dynamo logs
|
|
93
|
+
this.lambdaFunction.addToRolePolicy(
|
|
94
|
+
new aws_iam.PolicyStatement({
|
|
95
|
+
actions: ['lambda:InvokeFunction'],
|
|
96
|
+
resources: ['arn:aws:lambda:*:*:function:*sfunc*'],
|
|
97
|
+
}),
|
|
98
|
+
);
|
|
99
|
+
|
|
100
|
+
// We need access to dynamo log tables
|
|
101
|
+
this.lambdaFunction.addToRolePolicy(
|
|
102
|
+
new aws_iam.PolicyStatement({
|
|
103
|
+
actions: ['dynamodb:GetItem', 'dynamodb:Scan', 'dynamodb:Query', 'dynamodb:PutItem'],
|
|
104
|
+
|
|
105
|
+
// TODO: Revisit this, the user can make logs tables them selves... ~ Slight security risk here
|
|
106
|
+
// Consider making tags to identify logs tables, all qpq resourses
|
|
107
|
+
// conditions: {
|
|
108
|
+
// 'ForAllValues:StringLike': {
|
|
109
|
+
// 'aws:ResourceTag/Name': '*qpqlog',
|
|
110
|
+
// },
|
|
111
|
+
// },
|
|
112
|
+
resources: ['arn:aws:dynamodb:*:*:table/logs-*', 'arn:aws:dynamodb:*:*:table/flogs-*'],
|
|
113
|
+
}),
|
|
114
|
+
);
|
|
91
115
|
}
|
|
92
116
|
}
|
|
@@ -6,7 +6,7 @@ import { aws_s3, aws_iam, aws_dynamodb, aws_s3_notifications } from 'aws-cdk-lib
|
|
|
6
6
|
import * as cdk from 'aws-cdk-lib';
|
|
7
7
|
import { QpqResource } from '../base';
|
|
8
8
|
import { QPQConfig } from 'quidproquo-core/lib';
|
|
9
|
-
import { QPQ_LOG_BUCKET_NAME } from '../../constants';
|
|
9
|
+
import { QPQ_LOG_BUCKET_NAME, QPQ_FROM_LOG_BUCKET_NAME } from '../../constants';
|
|
10
10
|
import { Function } from './Function';
|
|
11
11
|
// import { qpqWebServerUtils } from '../../utils';
|
|
12
12
|
|
|
@@ -75,6 +75,7 @@ export class LogStorage extends QpqConstructBlock {
|
|
|
75
75
|
autoDeleteObjects: true,
|
|
76
76
|
});
|
|
77
77
|
|
|
78
|
+
// Time based query over all logs for a given runtimeType
|
|
78
79
|
const storyResultsTable = new aws_dynamodb.Table(this, 'table', {
|
|
79
80
|
tableName: this.qpqResourceName(QPQ_LOG_BUCKET_NAME, 'log'),
|
|
80
81
|
partitionKey: { name: 'runtimeType', type: aws_dynamodb.AttributeType.STRING },
|
|
@@ -83,6 +84,23 @@ export class LogStorage extends QpqConstructBlock {
|
|
|
83
84
|
removalPolicy: cdk.RemovalPolicy.DESTROY,
|
|
84
85
|
});
|
|
85
86
|
|
|
87
|
+
// Query by correlation
|
|
88
|
+
storyResultsTable.addGlobalSecondaryIndex({
|
|
89
|
+
indexName: 'CorrelationIndex',
|
|
90
|
+
partitionKey: { name: 'correlation', type: aws_dynamodb.AttributeType.STRING },
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
// Second table for the from logs ~ Second table because a GSI will dupe the data more then needed
|
|
94
|
+
// Also, we cant have a GSI on keys that can be undefined, this table will only contain
|
|
95
|
+
// logs with a fromCorrelation
|
|
96
|
+
const fromStoryResultsTable = new aws_dynamodb.Table(this, 'from-table', {
|
|
97
|
+
tableName: this.qpqResourceName(QPQ_FROM_LOG_BUCKET_NAME, 'flog'),
|
|
98
|
+
partitionKey: { name: 'fromCorrelation', type: aws_dynamodb.AttributeType.STRING },
|
|
99
|
+
sortKey: { name: 'startedAtWithCorrelation', type: aws_dynamodb.AttributeType.STRING },
|
|
100
|
+
billingMode: aws_dynamodb.BillingMode.PAY_PER_REQUEST,
|
|
101
|
+
removalPolicy: cdk.RemovalPolicy.DESTROY,
|
|
102
|
+
});
|
|
103
|
+
|
|
86
104
|
this.table = storyResultsTable;
|
|
87
105
|
|
|
88
106
|
// Create a lambda that is trigged when files are written to the bucket
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { QPQConfig, qpqCoreUtils } from 'quidproquo-core';
|
|
2
|
+
import { awsLambdaUtils } from 'quidproquo-actionprocessor-awslambda';
|
|
3
|
+
|
|
4
|
+
export const getRuntimeCorrelation = (qpqConfig: QPQConfig): string => {
|
|
5
|
+
const moduleName = qpqCoreUtils.getApplicationModuleName(qpqConfig);
|
|
6
|
+
return `${moduleName}-${awsLambdaUtils.randomGuid()}`;
|
|
7
|
+
};
|
|
@@ -10,6 +10,8 @@ export const storyLogger = async (
|
|
|
10
10
|
result: StoryResult<any>,
|
|
11
11
|
qpqConfig: QPQConfig,
|
|
12
12
|
): Promise<void> => {
|
|
13
|
+
/*
|
|
14
|
+
|
|
13
15
|
const bucketName = awsNamingUtils.getQpqRuntimeResourceNameFromConfig(
|
|
14
16
|
QPQ_LOG_BUCKET_NAME,
|
|
15
17
|
qpqConfig,
|
|
@@ -26,6 +28,8 @@ export const storyLogger = async (
|
|
|
26
28
|
Body: JSON.stringify(result),
|
|
27
29
|
}),
|
|
28
30
|
);
|
|
31
|
+
|
|
32
|
+
*/
|
|
29
33
|
};
|
|
30
34
|
|
|
31
35
|
export const getLogger = (qpqConfig: QPQConfig) => async (result: StoryResult<any>) => {
|
|
@@ -29,7 +29,7 @@ import { APIGatewayEvent, Context } from 'aws-lambda';
|
|
|
29
29
|
import { getLambdaConfigs } from './lambdaConfig';
|
|
30
30
|
import { ActionProcessorListResolver } from './actionProcessorListResolver';
|
|
31
31
|
|
|
32
|
-
import { getLogger } from './
|
|
32
|
+
import { getLogger, getRuntimeCorrelation } from './lambda-utils';
|
|
33
33
|
|
|
34
34
|
import { dynamicModuleLoader } from './dynamicModuleLoader';
|
|
35
35
|
|
|
@@ -60,6 +60,7 @@ export const getAPIGatewayEventExecutor = (
|
|
|
60
60
|
) => {
|
|
61
61
|
return async (event: APIGatewayEvent, context: Context) => {
|
|
62
62
|
const cdkConfig = await getLambdaConfigs();
|
|
63
|
+
const accessToken = qpqWebServerUtils.getAccessTokenFromHeaders(event.headers);
|
|
63
64
|
|
|
64
65
|
// Build a processor for the session and stuff
|
|
65
66
|
// Remove the non route ones ~ let the story execute action add them
|
|
@@ -87,11 +88,14 @@ export const getAPIGatewayEventExecutor = (
|
|
|
87
88
|
|
|
88
89
|
const resolveStory = createRuntime(
|
|
89
90
|
cdkConfig.qpqConfig,
|
|
90
|
-
{
|
|
91
|
+
{
|
|
92
|
+
depth: 0,
|
|
93
|
+
accessToken: accessToken,
|
|
94
|
+
},
|
|
91
95
|
storyActionProcessor,
|
|
92
96
|
getDateNow,
|
|
93
97
|
getLogger(cdkConfig.qpqConfig),
|
|
94
|
-
|
|
98
|
+
getRuntimeCorrelation(cdkConfig.qpqConfig),
|
|
95
99
|
QpqRuntimeType.API,
|
|
96
100
|
);
|
|
97
101
|
|
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
coreActionProcessor,
|
|
3
|
+
webserverActionProcessor,
|
|
4
|
+
getConfigActionProcessor,
|
|
5
|
+
} from 'quidproquo-actionprocessor-node';
|
|
2
6
|
|
|
3
7
|
import {
|
|
4
8
|
getEventBridgeEventActionProcessor,
|
|
@@ -18,15 +22,13 @@ import {
|
|
|
18
22
|
LambdaRuntimeConfig,
|
|
19
23
|
} from 'quidproquo-actionprocessor-awslambda';
|
|
20
24
|
|
|
21
|
-
import { getConfigActionProcessor } from 'quidproquo-actionprocessor-node';
|
|
22
|
-
|
|
23
25
|
import { createRuntime, askProcessEvent, QpqRuntimeType } from 'quidproquo-core';
|
|
24
26
|
|
|
25
27
|
import { EventBridgeEvent, Context } from 'aws-lambda';
|
|
26
28
|
|
|
27
29
|
import { getLambdaConfigs } from './lambdaConfig';
|
|
28
30
|
import { ActionProcessorListResolver } from './actionProcessorListResolver';
|
|
29
|
-
import { getLogger } from './
|
|
31
|
+
import { getLogger, getRuntimeCorrelation } from './lambda-utils';
|
|
30
32
|
|
|
31
33
|
import { dynamicModuleLoader } from './dynamicModuleLoader';
|
|
32
34
|
|
|
@@ -73,12 +75,14 @@ export const getEventBridgeEventExecutor = (
|
|
|
73
75
|
|
|
74
76
|
const resolveStory = createRuntime(
|
|
75
77
|
cdkConfig.qpqConfig,
|
|
76
|
-
{
|
|
78
|
+
{
|
|
79
|
+
depth: 0,
|
|
80
|
+
},
|
|
77
81
|
storyActionProcessor,
|
|
78
82
|
getDateNow,
|
|
79
83
|
getLogger(cdkConfig.qpqConfig),
|
|
80
|
-
|
|
81
|
-
QpqRuntimeType.
|
|
84
|
+
getRuntimeCorrelation(cdkConfig.qpqConfig),
|
|
85
|
+
QpqRuntimeType.RECURRING_SCHEDULE,
|
|
82
86
|
);
|
|
83
87
|
|
|
84
88
|
await resolveStory(askProcessEvent, [event, context]);
|
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
coreActionProcessor,
|
|
3
|
+
webserverActionProcessor,
|
|
4
|
+
getConfigActionProcessor,
|
|
5
|
+
} from 'quidproquo-actionprocessor-node';
|
|
2
6
|
|
|
3
7
|
import {
|
|
4
8
|
getCloudFrontOriginRequestEventActionProcessor,
|
|
@@ -15,8 +19,6 @@ import {
|
|
|
15
19
|
DynamicModuleLoader,
|
|
16
20
|
} from 'quidproquo-actionprocessor-awslambda';
|
|
17
21
|
|
|
18
|
-
import { getConfigActionProcessor } from 'quidproquo-actionprocessor-node';
|
|
19
|
-
|
|
20
22
|
import { getLambdaConfigs } from './lambdaConfig';
|
|
21
23
|
|
|
22
24
|
import { createRuntime, askProcessEvent, QpqRuntimeType } from 'quidproquo-core';
|
|
@@ -24,7 +26,7 @@ import { createRuntime, askProcessEvent, QpqRuntimeType } from 'quidproquo-core'
|
|
|
24
26
|
import { CloudFrontRequestEvent, CloudFrontRequestResult, Context } from 'aws-lambda';
|
|
25
27
|
|
|
26
28
|
import { ActionProcessorListResolver } from './actionProcessorListResolver';
|
|
27
|
-
import { getLogger } from './
|
|
29
|
+
import { getLogger, getRuntimeCorrelation } from './lambda-utils';
|
|
28
30
|
|
|
29
31
|
import { dynamicModuleLoader } from './dynamicModuleLoader';
|
|
30
32
|
|
|
@@ -69,11 +71,13 @@ export const getOriginRequestEventExecutor = (
|
|
|
69
71
|
|
|
70
72
|
const resolveStory = createRuntime(
|
|
71
73
|
cdkConfig.qpqConfig,
|
|
72
|
-
{
|
|
74
|
+
{
|
|
75
|
+
depth: 0,
|
|
76
|
+
},
|
|
73
77
|
storyActionProcessor,
|
|
74
78
|
getDateNow,
|
|
75
79
|
getLogger(cdkConfig.qpqConfig),
|
|
76
|
-
|
|
80
|
+
getRuntimeCorrelation(cdkConfig.qpqConfig),
|
|
77
81
|
QpqRuntimeType.EVENT_SEO_OR,
|
|
78
82
|
);
|
|
79
83
|
|
|
@@ -59,6 +59,34 @@ const writeStoryResultMetadataToDynamo = async (
|
|
|
59
59
|
}
|
|
60
60
|
};
|
|
61
61
|
|
|
62
|
+
export const getFromCorrelationBucketNameFromLog = (
|
|
63
|
+
storyResultMetadata: StoryResultMetadata,
|
|
64
|
+
localBucketName: string,
|
|
65
|
+
): string => {
|
|
66
|
+
if (!storyResultMetadata.fromCorrelation) {
|
|
67
|
+
return '';
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// Get the module name of the service that wants the log
|
|
71
|
+
const fromModuleName = storyResultMetadata.fromCorrelation.split('::')[0];
|
|
72
|
+
|
|
73
|
+
// Get the name of the current module where we are executing this code
|
|
74
|
+
const currentModuleName = storyResultMetadata.moduleName;
|
|
75
|
+
|
|
76
|
+
// Split up the bucket / module names into parts
|
|
77
|
+
const bucketParts = localBucketName.split('-');
|
|
78
|
+
const moduleParts = fromModuleName.split('-');
|
|
79
|
+
const currentModuleNameParts = currentModuleName.split('-');
|
|
80
|
+
|
|
81
|
+
// Replace the current module name with the module name of the service that wants the log
|
|
82
|
+
bucketParts.splice(2, currentModuleNameParts.length, ...moduleParts);
|
|
83
|
+
|
|
84
|
+
// rebuild the new bucket name
|
|
85
|
+
const newBucketName = bucketParts.join('-');
|
|
86
|
+
|
|
87
|
+
return newBucketName;
|
|
88
|
+
};
|
|
89
|
+
|
|
62
90
|
export const executeS3FileWriteEvent: S3Handler = async (event: S3Event) => {
|
|
63
91
|
for (const record of event.Records) {
|
|
64
92
|
const bucketName = record.s3.bucket.name;
|
|
@@ -67,6 +95,13 @@ export const executeS3FileWriteEvent: S3Handler = async (event: S3Event) => {
|
|
|
67
95
|
|
|
68
96
|
const storyResultMetadata = await readLogFromBucket(bucketName, awsRegion, key);
|
|
69
97
|
|
|
98
|
+
// Write the main log to the service table
|
|
70
99
|
await writeStoryResultMetadataToDynamo(bucketName, storyResultMetadata, awsRegion);
|
|
100
|
+
|
|
101
|
+
// Write the same log to the table of the from service, so it can query links on the fromGuid GSI
|
|
102
|
+
const fromBucketName = getFromCorrelationBucketNameFromLog(storyResultMetadata, bucketName);
|
|
103
|
+
if (fromBucketName) {
|
|
104
|
+
await writeStoryResultMetadataToDynamo(fromBucketName, storyResultMetadata, awsRegion);
|
|
105
|
+
}
|
|
71
106
|
}
|
|
72
107
|
};
|
|
@@ -23,10 +23,16 @@ import { getConfigActionProcessor } from 'quidproquo-actionprocessor-node';
|
|
|
23
23
|
|
|
24
24
|
import { getLambdaConfigs } from './lambdaConfig';
|
|
25
25
|
|
|
26
|
-
import {
|
|
26
|
+
import {
|
|
27
|
+
createRuntime,
|
|
28
|
+
askProcessEvent,
|
|
29
|
+
QpqRuntimeType,
|
|
30
|
+
StorySession,
|
|
31
|
+
QueueMessage,
|
|
32
|
+
} from 'quidproquo-core';
|
|
27
33
|
|
|
28
34
|
import { ActionProcessorListResolver } from './actionProcessorListResolver';
|
|
29
|
-
import { getLogger } from './
|
|
35
|
+
import { getLogger, getRuntimeCorrelation } from './lambda-utils';
|
|
30
36
|
|
|
31
37
|
import { dynamicModuleLoader } from './dynamicModuleLoader';
|
|
32
38
|
|
|
@@ -36,9 +42,15 @@ import qpqCustomActionProcessors from 'qpq-custom-action-processors-loader!';
|
|
|
36
42
|
// TODO: Make this a util or something based on server time or something..
|
|
37
43
|
const getDateNow = () => new Date().toISOString();
|
|
38
44
|
|
|
45
|
+
// TODO: Unify this once the lambda code moves from CDK to awslambda
|
|
46
|
+
type AnyQueueMessageWithSession = QueueMessage<any> & {
|
|
47
|
+
storySession: StorySession;
|
|
48
|
+
};
|
|
49
|
+
|
|
39
50
|
export const getStoryActionRuntime = async (
|
|
40
51
|
dynamicModuleLoader: DynamicModuleLoader,
|
|
41
52
|
getCustomActionProcessors: ActionProcessorListResolver = () => ({}),
|
|
53
|
+
callerStorySession: StorySession,
|
|
42
54
|
) => {
|
|
43
55
|
const cdkConfig = await getLambdaConfigs();
|
|
44
56
|
|
|
@@ -68,17 +80,18 @@ export const getStoryActionRuntime = async (
|
|
|
68
80
|
|
|
69
81
|
const resolveStory = createRuntime(
|
|
70
82
|
cdkConfig.qpqConfig,
|
|
71
|
-
|
|
83
|
+
callerStorySession,
|
|
72
84
|
storyActionProcessor,
|
|
73
85
|
getDateNow,
|
|
74
86
|
getLogger(cdkConfig.qpqConfig),
|
|
75
|
-
|
|
87
|
+
getRuntimeCorrelation(cdkConfig.qpqConfig),
|
|
76
88
|
QpqRuntimeType.QUEUE_EVENT,
|
|
77
89
|
);
|
|
78
90
|
|
|
79
91
|
return resolveStory;
|
|
80
92
|
};
|
|
81
93
|
|
|
94
|
+
// TODO: We could make this entire function a story, that spawns an execute story for each record
|
|
82
95
|
export const getSQSEventExecutor = (
|
|
83
96
|
dynamicModuleLoader: DynamicModuleLoader,
|
|
84
97
|
getCustomActionProcessors: ActionProcessorListResolver = () => ({}),
|
|
@@ -90,13 +103,22 @@ export const getSQSEventExecutor = (
|
|
|
90
103
|
console.log('num batch: ', event.Records.length);
|
|
91
104
|
|
|
92
105
|
const results = event.Records.map(async (record) => {
|
|
106
|
+
const runtimeData = JSON.parse(record.body) as AnyQueueMessageWithSession;
|
|
107
|
+
|
|
93
108
|
const resolveStory = await getStoryActionRuntime(
|
|
94
109
|
dynamicModuleLoader,
|
|
95
110
|
getCustomActionProcessors,
|
|
111
|
+
runtimeData.storySession,
|
|
96
112
|
);
|
|
113
|
+
|
|
114
|
+
const queueMessage: QueueMessage<any> = {
|
|
115
|
+
type: runtimeData.type,
|
|
116
|
+
payload: runtimeData.payload,
|
|
117
|
+
};
|
|
118
|
+
|
|
97
119
|
return {
|
|
98
120
|
id: record.messageId,
|
|
99
|
-
result: await resolveStory(askProcessEvent, [
|
|
121
|
+
result: await resolveStory(askProcessEvent, [queueMessage, context]),
|
|
100
122
|
};
|
|
101
123
|
});
|
|
102
124
|
|
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
coreActionProcessor,
|
|
3
|
+
webserverActionProcessor,
|
|
4
|
+
getConfigActionProcessor,
|
|
5
|
+
} from 'quidproquo-actionprocessor-node';
|
|
2
6
|
import { ExecuteServiceFunctionEvent } from 'quidproquo-webserver';
|
|
3
7
|
|
|
4
8
|
import {
|
|
@@ -18,15 +22,13 @@ import {
|
|
|
18
22
|
DynamicModuleLoader,
|
|
19
23
|
} from 'quidproquo-actionprocessor-awslambda';
|
|
20
24
|
|
|
21
|
-
import {
|
|
22
|
-
|
|
23
|
-
import { createRuntime, askProcessEvent, QpqRuntimeType } from 'quidproquo-core';
|
|
25
|
+
import { createRuntime, askProcessEvent, QpqRuntimeType, StorySession } from 'quidproquo-core';
|
|
24
26
|
|
|
25
27
|
import { Context } from 'aws-lambda';
|
|
26
28
|
|
|
27
29
|
import { getLambdaConfigs } from './lambdaConfig';
|
|
28
30
|
import { ActionProcessorListResolver } from './actionProcessorListResolver';
|
|
29
|
-
import { getLogger } from './
|
|
31
|
+
import { getLogger, getRuntimeCorrelation } from './lambda-utils';
|
|
30
32
|
|
|
31
33
|
// @ts-ignore - Special webpack loader
|
|
32
34
|
import { dynamicModuleLoader } from './dynamicModuleLoader';
|
|
@@ -37,11 +39,16 @@ import qpqCustomActionProcessors from 'qpq-custom-action-processors-loader!';
|
|
|
37
39
|
// TODO: Make this a util or something based on server time or something..
|
|
38
40
|
const getDateNow = () => new Date().toISOString();
|
|
39
41
|
|
|
42
|
+
// TODO: Unify this once the lambda code moves from CDK to awslambda
|
|
43
|
+
type AnyExecuteServiceFunctionEventWithSession = ExecuteServiceFunctionEvent<any[]> & {
|
|
44
|
+
storySession: StorySession;
|
|
45
|
+
};
|
|
46
|
+
|
|
40
47
|
export const getServiceFunctionExecuteEventExecutor = (
|
|
41
48
|
dynamicModuleLoader: DynamicModuleLoader,
|
|
42
49
|
getCustomActionProcessors: ActionProcessorListResolver = () => ({}),
|
|
43
50
|
) => {
|
|
44
|
-
return async (event:
|
|
51
|
+
return async (event: AnyExecuteServiceFunctionEventWithSession, context: Context) => {
|
|
45
52
|
const cdkConfig = await getLambdaConfigs();
|
|
46
53
|
|
|
47
54
|
// Build a processor for the session and stuff
|
|
@@ -71,15 +78,20 @@ export const getServiceFunctionExecuteEventExecutor = (
|
|
|
71
78
|
|
|
72
79
|
const resolveStory = createRuntime(
|
|
73
80
|
cdkConfig.qpqConfig,
|
|
74
|
-
|
|
81
|
+
event.storySession,
|
|
75
82
|
storyActionProcessor,
|
|
76
83
|
getDateNow,
|
|
77
84
|
getLogger(cdkConfig.qpqConfig),
|
|
78
|
-
|
|
85
|
+
getRuntimeCorrelation(cdkConfig.qpqConfig),
|
|
79
86
|
QpqRuntimeType.SERVICE_FUNCTION_EXE,
|
|
80
87
|
);
|
|
81
88
|
|
|
82
|
-
const
|
|
89
|
+
const eventWithNoSession: ExecuteServiceFunctionEvent<any[]> = {
|
|
90
|
+
functionName: event.functionName,
|
|
91
|
+
payload: event.payload,
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
const result = await resolveStory(askProcessEvent, [eventWithNoSession, context]);
|
|
83
95
|
|
|
84
96
|
// just return the story result
|
|
85
97
|
return result;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { StoryResult } from 'quidproquo-core';
|
|
2
|
+
|
|
3
|
+
export const serviceFunctionExeGenericTextExtractor = (storyResult: StoryResult<any>): string => {
|
|
4
|
+
if (storyResult.runtimeType === 'SERVICE_FUNCTION_EXE') {
|
|
5
|
+
return storyResult.input[0]?.functionName || '';
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
return '';
|
|
9
|
+
};
|
|
@@ -1,14 +1,20 @@
|
|
|
1
1
|
import { StoryResult, StoryResultMetadata } from 'quidproquo-core';
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
apiGenericTextExtractor,
|
|
4
|
+
unknownGenericTextExtractor,
|
|
5
|
+
queueEventGenericTextExtractor,
|
|
6
|
+
serviceFunctionExeGenericTextExtractor,
|
|
7
|
+
} from './genericTextExtractors';
|
|
3
8
|
|
|
4
9
|
// These have to be strings and not enum due to how the lambda is packaged
|
|
5
10
|
const extractors: Record<string, (sr: StoryResult<any>) => string> = {
|
|
6
11
|
['API']: apiGenericTextExtractor,
|
|
7
|
-
['
|
|
12
|
+
['QUEUE_EVENT']: queueEventGenericTextExtractor,
|
|
13
|
+
['SERVICE_FUNCTION_EXE']: serviceFunctionExeGenericTextExtractor,
|
|
14
|
+
|
|
15
|
+
['RECURRING_SCHEDULE']: unknownGenericTextExtractor,
|
|
8
16
|
['EVENT_SEO_OR']: unknownGenericTextExtractor,
|
|
9
17
|
['EXECUTE_STORY']: unknownGenericTextExtractor,
|
|
10
|
-
['QUEUE_EVENT']: unknownGenericTextExtractor,
|
|
11
|
-
['SERVICE_FUNCTION_EXE']: unknownGenericTextExtractor,
|
|
12
18
|
};
|
|
13
19
|
|
|
14
20
|
export const storyResultToMetadata = (
|
|
@@ -24,10 +24,10 @@ export class InfQpqServiceStack extends QpqServiceStack {
|
|
|
24
24
|
super(scope, id, props);
|
|
25
25
|
|
|
26
26
|
// Build the log storage drive
|
|
27
|
-
const logBucket = new LogStorage(this, 'logStorage', {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
}).bucket;
|
|
27
|
+
// const logBucket = new LogStorage(this, 'logStorage', {
|
|
28
|
+
// awsAccountId: props.awsAccountId,
|
|
29
|
+
// qpqConfig: props.qpqConfig,
|
|
30
|
+
// }).bucket;
|
|
31
31
|
|
|
32
32
|
// Build the storage drives
|
|
33
33
|
const storageDrives = qpqCoreUtils.getStorageDrives(props.qpqConfig).map(
|
|
File without changes
|