quidproquo-deploy-awscdk 0.0.18
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/README.md +7 -0
- package/lib/QPQPrototypeStack.d.ts +16 -0
- package/lib/QPQPrototypeStack.js +139 -0
- package/lib/eventBridge.d.ts +3 -0
- package/lib/eventBridge.js +31 -0
- package/lib/index.d.ts +1 -0
- package/lib/index.js +7 -0
- package/lib/route.d.ts +7 -0
- package/lib/route.js +72 -0
- package/package.json +47 -0
package/README.md
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Stack, StackProps } from 'aws-cdk-lib';
|
|
2
|
+
import { Construct } from 'constructs';
|
|
3
|
+
import { QPQConfig } from 'quidproquo-core';
|
|
4
|
+
export interface LambdaEntry {
|
|
5
|
+
src: string;
|
|
6
|
+
runtime: string;
|
|
7
|
+
}
|
|
8
|
+
export interface QPQPrototypeStackProps extends StackProps {
|
|
9
|
+
serviceBuildPath: string;
|
|
10
|
+
qpqConfig: QPQConfig;
|
|
11
|
+
routeEntry: LambdaEntry;
|
|
12
|
+
eventEntry: LambdaEntry;
|
|
13
|
+
}
|
|
14
|
+
export declare class QPQPrototypeStack extends Stack {
|
|
15
|
+
constructor(scope: Construct, id: string, props: QPQPrototypeStackProps);
|
|
16
|
+
}
|
|
@@ -0,0 +1,139 @@
|
|
|
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.QPQPrototypeStack = void 0;
|
|
27
|
+
const path = __importStar(require("path"));
|
|
28
|
+
const aws_cdk_lib_1 = require("aws-cdk-lib");
|
|
29
|
+
const cdk = __importStar(require("aws-cdk-lib"));
|
|
30
|
+
const quidproquo_core_1 = require("quidproquo-core");
|
|
31
|
+
class QPQPrototypeStack extends aws_cdk_lib_1.Stack {
|
|
32
|
+
constructor(scope, id, props) {
|
|
33
|
+
super(scope, id, props);
|
|
34
|
+
const settings = {
|
|
35
|
+
environment: process.env.ENVIRONMENT || 'dev',
|
|
36
|
+
service: quidproquo_core_1.qpqCoreUtils.getAppName(props.qpqConfig),
|
|
37
|
+
aws: {
|
|
38
|
+
account: process.env.CDK_DEPLOY_ACCOUNT || process.env.CDK_DEFAULT_ACCOUNT,
|
|
39
|
+
region: process.env.CDK_DEPLOY_REGION || process.env.CDK_DEFAULT_REGION,
|
|
40
|
+
},
|
|
41
|
+
};
|
|
42
|
+
const resourceName = (name) => {
|
|
43
|
+
return `${settings.service}-${settings.environment}-${name}`;
|
|
44
|
+
};
|
|
45
|
+
const BLLayer = new aws_cdk_lib_1.aws_lambda.LayerVersion(this, `${id}-BLLayer`, {
|
|
46
|
+
layerVersionName: `${id}-BLLayer`,
|
|
47
|
+
code: new aws_cdk_lib_1.aws_lambda.AssetCode(props.serviceBuildPath),
|
|
48
|
+
compatibleRuntimes: [aws_cdk_lib_1.aws_lambda.Runtime.NODEJS_16_X],
|
|
49
|
+
});
|
|
50
|
+
const ownedSecrets = quidproquo_core_1.qpqCoreUtils.getOwnedSecrets(props.qpqConfig).map((secret) => new aws_cdk_lib_1.aws_secretsmanager.Secret(this, `secret-${secret.key}`, {
|
|
51
|
+
secretName: secret.key,
|
|
52
|
+
removalPolicy: cdk.RemovalPolicy.DESTROY,
|
|
53
|
+
description: `${settings.environment}-${settings.service}`,
|
|
54
|
+
}));
|
|
55
|
+
const buckets = quidproquo_core_1.qpqCoreUtils.getStorageDriveNames(props.qpqConfig).map((driveName) => {
|
|
56
|
+
const bucketName = resourceName(driveName);
|
|
57
|
+
const bucket = new aws_cdk_lib_1.aws_s3.Bucket(this, bucketName, {
|
|
58
|
+
bucketName: resourceName(driveName),
|
|
59
|
+
// Disable public access to this bucket, CloudFront will do that
|
|
60
|
+
publicReadAccess: false,
|
|
61
|
+
blockPublicAccess: aws_cdk_lib_1.aws_s3.BlockPublicAccess.BLOCK_ALL,
|
|
62
|
+
// Allow bucket to auto delete upon cdk:Destroy
|
|
63
|
+
removalPolicy: cdk.RemovalPolicy.DESTROY,
|
|
64
|
+
autoDeleteObjects: true,
|
|
65
|
+
});
|
|
66
|
+
return {
|
|
67
|
+
driveName,
|
|
68
|
+
bucketName: bucketName,
|
|
69
|
+
bucket: bucket,
|
|
70
|
+
};
|
|
71
|
+
});
|
|
72
|
+
// This should be all resource names
|
|
73
|
+
const runtimeConfigLambdaConfig = {
|
|
74
|
+
resourceNameMap: buckets.reduce((acc, b) => (Object.assign(Object.assign({}, acc), { [b.driveName]: b.bucketName })), {}),
|
|
75
|
+
};
|
|
76
|
+
const lambdaHandler = new aws_cdk_lib_1.aws_lambda_nodejs.NodejsFunction(this, `${settings.environment}-${settings.service}-lambda-rest`, {
|
|
77
|
+
functionName: `lambda-rest-${settings.service}-${settings.environment}`,
|
|
78
|
+
entry: `${path.resolve(__dirname)}/route.ts`,
|
|
79
|
+
handler: 'executeRoute',
|
|
80
|
+
timeout: cdk.Duration.seconds(25),
|
|
81
|
+
runtime: aws_cdk_lib_1.aws_lambda.Runtime.NODEJS_16_X,
|
|
82
|
+
layers: [BLLayer],
|
|
83
|
+
bundling: {
|
|
84
|
+
tsconfig: './tsconfig.json',
|
|
85
|
+
define: {
|
|
86
|
+
'process.env.lambdaRuntimeConfig': JSON.stringify(JSON.stringify(runtimeConfigLambdaConfig)),
|
|
87
|
+
},
|
|
88
|
+
},
|
|
89
|
+
environment: {
|
|
90
|
+
TABLES: JSON.stringify([]),
|
|
91
|
+
},
|
|
92
|
+
});
|
|
93
|
+
// Grant access to the lambda
|
|
94
|
+
buckets.forEach((b) => b.bucket.grantReadWrite(lambdaHandler));
|
|
95
|
+
ownedSecrets.forEach((os) => os.grantRead(lambdaHandler));
|
|
96
|
+
// Create a rest api
|
|
97
|
+
const api = new aws_cdk_lib_1.aws_apigateway.LambdaRestApi(this, `${settings.environment}-${settings.service}-http-api`, {
|
|
98
|
+
restApiName: `${settings.environment}-${settings.service}-http-api`,
|
|
99
|
+
handler: lambdaHandler,
|
|
100
|
+
deployOptions: {
|
|
101
|
+
loggingLevel: aws_cdk_lib_1.aws_apigateway.MethodLoggingLevel.INFO,
|
|
102
|
+
dataTraceEnabled: true,
|
|
103
|
+
},
|
|
104
|
+
proxy: true,
|
|
105
|
+
});
|
|
106
|
+
quidproquo_core_1.qpqCoreUtils.getScheduleEvents(props.qpqConfig).forEach((se, index) => {
|
|
107
|
+
const schedulerFunction = new aws_cdk_lib_1.aws_lambda_nodejs.NodejsFunction(this, `${settings.environment}-${settings.service}-SE-${index}`, {
|
|
108
|
+
functionName: `SE-${index}-${se.runtime}-${settings.environment}-${settings.service}`,
|
|
109
|
+
entry: props.eventEntry.src,
|
|
110
|
+
handler: props.eventEntry.runtime,
|
|
111
|
+
timeout: cdk.Duration.minutes(15),
|
|
112
|
+
runtime: aws_cdk_lib_1.aws_lambda.Runtime.NODEJS_16_X,
|
|
113
|
+
memorySize: 400,
|
|
114
|
+
layers: [BLLayer],
|
|
115
|
+
bundling: {
|
|
116
|
+
tsconfig: './tsconfig.json',
|
|
117
|
+
define: {
|
|
118
|
+
'process.env.lambdaRuntimeConfig': JSON.stringify(JSON.stringify(Object.assign(Object.assign({}, runtimeConfigLambdaConfig), { lambdaRuntimeConfig: {
|
|
119
|
+
src: se.src,
|
|
120
|
+
runtime: se.runtime,
|
|
121
|
+
} }))),
|
|
122
|
+
},
|
|
123
|
+
},
|
|
124
|
+
environment: {
|
|
125
|
+
TABLES: JSON.stringify([]),
|
|
126
|
+
},
|
|
127
|
+
});
|
|
128
|
+
buckets.forEach((b) => b.bucket.grantReadWrite(schedulerFunction));
|
|
129
|
+
ownedSecrets.forEach((os) => os.grantRead(schedulerFunction));
|
|
130
|
+
// EventBridge rule which runs every five minutes
|
|
131
|
+
const cronRule = new aws_cdk_lib_1.aws_events.Rule(this, `se-cronrule-${index}`, {
|
|
132
|
+
schedule: aws_cdk_lib_1.aws_events.Schedule.expression(`cron(${se.cronExpression})`),
|
|
133
|
+
});
|
|
134
|
+
// Set the targert as lambda function
|
|
135
|
+
cronRule.addTarget(new aws_cdk_lib_1.aws_events_targets.LambdaFunction(schedulerFunction));
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
exports.QPQPrototypeStack = QPQPrototypeStack;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.executeEvent = exports.getDateNow = void 0;
|
|
16
|
+
const quidproquo_actionprocessor_node_1 = require("quidproquo-actionprocessor-node");
|
|
17
|
+
const quidproquo_actionprocessor_awslambda_1 = require("quidproquo-actionprocessor-awslambda");
|
|
18
|
+
const quidproquo_core_1 = require("quidproquo-core");
|
|
19
|
+
const envConfig_1 = __importDefault(require("./envConfig"));
|
|
20
|
+
const getDateNow = () => new Date().toISOString();
|
|
21
|
+
exports.getDateNow = getDateNow;
|
|
22
|
+
const executeEvent = (event, context) => __awaiter(void 0, void 0, void 0, function* () {
|
|
23
|
+
// Build a processor for the session and stuff
|
|
24
|
+
// Remove the non event ones
|
|
25
|
+
const storyActionProcessor = 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)(envConfig_1.default.lambdaConfig)), (0, quidproquo_actionprocessor_awslambda_1.getSystemActionProcessor)(envConfig_1.default.lambdaConfig)), (0, quidproquo_actionprocessor_awslambda_1.getFileActionProcessor)(envConfig_1.default.lambdaConfig)), (0, quidproquo_actionprocessor_awslambda_1.getConfigGetSecretActionProcessor)(envConfig_1.default.lambdaConfig));
|
|
26
|
+
const logger = (result) => __awaiter(void 0, void 0, void 0, function* () { });
|
|
27
|
+
// Run the callback
|
|
28
|
+
const resolveStory = (0, quidproquo_core_1.createRuntime)({}, storyActionProcessor, exports.getDateNow, logger, quidproquo_actionprocessor_awslambda_1.awsLambdaUtils.randomGuid);
|
|
29
|
+
yield resolveStory(quidproquo_core_1.askProcessEvent, [event, context]);
|
|
30
|
+
});
|
|
31
|
+
exports.executeEvent = executeEvent;
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const helloWorld: () => void;
|
package/lib/index.js
ADDED
package/lib/route.d.ts
ADDED
package/lib/route.js
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.executeRoute = exports.getDateNow = void 0;
|
|
16
|
+
const quidproquo_actionprocessor_node_1 = require("quidproquo-actionprocessor-node");
|
|
17
|
+
const quidproquo_actionprocessor_awslambda_1 = require("quidproquo-actionprocessor-awslambda");
|
|
18
|
+
const quidproquo_core_1 = require("quidproquo-core");
|
|
19
|
+
const envConfig_1 = __importDefault(require("./envConfig"));
|
|
20
|
+
const getDateNow = () => new Date().toISOString();
|
|
21
|
+
exports.getDateNow = getDateNow;
|
|
22
|
+
const ErrorTypeHttpResponseMap = {
|
|
23
|
+
[quidproquo_core_1.ErrorTypeEnum.BadRequest]: 400,
|
|
24
|
+
[quidproquo_core_1.ErrorTypeEnum.Unauthorized]: 401,
|
|
25
|
+
[quidproquo_core_1.ErrorTypeEnum.PaymentRequired]: 402,
|
|
26
|
+
[quidproquo_core_1.ErrorTypeEnum.Forbidden]: 403,
|
|
27
|
+
[quidproquo_core_1.ErrorTypeEnum.NotFound]: 404,
|
|
28
|
+
[quidproquo_core_1.ErrorTypeEnum.TimeOut]: 408,
|
|
29
|
+
[quidproquo_core_1.ErrorTypeEnum.UnsupportedMediaType]: 415,
|
|
30
|
+
[quidproquo_core_1.ErrorTypeEnum.OutOfResources]: 500,
|
|
31
|
+
[quidproquo_core_1.ErrorTypeEnum.GenericError]: 500,
|
|
32
|
+
[quidproquo_core_1.ErrorTypeEnum.NotImplemented]: 501,
|
|
33
|
+
[quidproquo_core_1.ErrorTypeEnum.NoContent]: 204,
|
|
34
|
+
};
|
|
35
|
+
const executeRoute = (event, context) => __awaiter(void 0, void 0, void 0, function* () {
|
|
36
|
+
// Build a processor for the session and stuff
|
|
37
|
+
// Remove the non route ones ~ let the story execute action add them
|
|
38
|
+
const storyActionProcessor = 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)(envConfig_1.default.qpqConfig)), (0, quidproquo_actionprocessor_awslambda_1.getConfigGetSecretActionProcessor)(envConfig_1.default.lambdaConfig)), (0, quidproquo_actionprocessor_awslambda_1.getSystemActionProcessor)(envConfig_1.default.lambdaConfig)), (0, quidproquo_actionprocessor_awslambda_1.getFileActionProcessor)(envConfig_1.default.lambdaConfig));
|
|
39
|
+
// const doWeCarePath = (event.path || "").replace(
|
|
40
|
+
// new RegExp(`^(\/${envConfig.appName})/`),
|
|
41
|
+
// "/"
|
|
42
|
+
// );
|
|
43
|
+
const logger = (result) => __awaiter(void 0, void 0, void 0, function* () {
|
|
44
|
+
// addResult(
|
|
45
|
+
// envConfig.appName,
|
|
46
|
+
// getDateNow(),
|
|
47
|
+
// doWeCarePath,
|
|
48
|
+
// "route-infrastructure",
|
|
49
|
+
// "infrastructure",
|
|
50
|
+
// "askRoute",
|
|
51
|
+
// result
|
|
52
|
+
// );
|
|
53
|
+
});
|
|
54
|
+
// // Run the callback
|
|
55
|
+
const resolveStory = (0, quidproquo_core_1.createRuntime)({}, storyActionProcessor, exports.getDateNow, logger, quidproquo_actionprocessor_awslambda_1.awsLambdaUtils.randomGuid);
|
|
56
|
+
const result = yield resolveStory(quidproquo_core_1.askProcessEvent, [event, context]);
|
|
57
|
+
// // Run the callback
|
|
58
|
+
if (!result.error) {
|
|
59
|
+
return {
|
|
60
|
+
statusCode: result.result.statusCode,
|
|
61
|
+
body: JSON.stringify(result.error ? result.error : result.result.body),
|
|
62
|
+
headers: result.result.headers,
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
const code = ErrorTypeHttpResponseMap[result.error.errorType];
|
|
66
|
+
return {
|
|
67
|
+
statusCode: code || 500,
|
|
68
|
+
body: JSON.stringify(result.error),
|
|
69
|
+
headers: {},
|
|
70
|
+
};
|
|
71
|
+
});
|
|
72
|
+
exports.executeRoute = executeRoute;
|
package/package.json
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "quidproquo-deploy-awscdk",
|
|
3
|
+
"version": "0.0.18",
|
|
4
|
+
"description": "",
|
|
5
|
+
"main": "./lib/index.js",
|
|
6
|
+
"types": "./lib/index.d.js",
|
|
7
|
+
"files": [
|
|
8
|
+
"lib/**/*"
|
|
9
|
+
],
|
|
10
|
+
"scripts": {
|
|
11
|
+
"test": "echo \"Error: no test specified\" && exit 1",
|
|
12
|
+
"build": "npx rimraf lib && tsc",
|
|
13
|
+
"watch": "tsc -w"
|
|
14
|
+
},
|
|
15
|
+
"repository": {
|
|
16
|
+
"type": "git",
|
|
17
|
+
"url": "git+https://github.com/joe-coady/quidproquo.git"
|
|
18
|
+
},
|
|
19
|
+
"keywords": [],
|
|
20
|
+
"author": "",
|
|
21
|
+
"license": "MIT",
|
|
22
|
+
"bugs": {
|
|
23
|
+
"url": "https://github.com/joe-coady/quidproquo/issues"
|
|
24
|
+
},
|
|
25
|
+
"homepage": "https://github.com/joe-coady/quidproquo#readme",
|
|
26
|
+
"dependencies": {
|
|
27
|
+
"aws-cdk-lib": "2.52.1",
|
|
28
|
+
"constructs": "^10.0.0",
|
|
29
|
+
"esbuild": "^0.15.16",
|
|
30
|
+
"quidproquo-actionprocessor-awslambda": "*",
|
|
31
|
+
"quidproquo-actionprocessor-node": "*",
|
|
32
|
+
"quidproquo-core": "*",
|
|
33
|
+
"quidproquo-webserver": "*",
|
|
34
|
+
"uuid": "^9.0.0"
|
|
35
|
+
},
|
|
36
|
+
"devDependencies": {
|
|
37
|
+
"@types/aws-lambda": "^8.10.109",
|
|
38
|
+
"@types/babel__traverse": "7.18.2",
|
|
39
|
+
"@types/node": "^10.17.60",
|
|
40
|
+
"@types/prettier": "2.6.0",
|
|
41
|
+
"@types/uuid": "^8.3.4",
|
|
42
|
+
"aws-cdk": "2.52.1",
|
|
43
|
+
"ts-node": "^10.9.1",
|
|
44
|
+
"quidproquo-tsconfig": "*",
|
|
45
|
+
"typescript": "^4.9.3"
|
|
46
|
+
}
|
|
47
|
+
}
|