@byaga/cdk-patterns 0.10.0 → 0.11.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/README.md +7 -1
- package/archive/ApiAttachPoint.ts +9 -0
- package/archive/ApiCertificate.ts +32 -0
- package/{lib/CognitoApiGatewayAuthorizer.d.ts → archive/CognitoApiGatewayAuthorizer.ts} +13 -7
- package/archive/DynamoDbTable.ts +40 -0
- package/archive/ICorsConfig.ts +5 -0
- package/archive/IDomainConfig.ts +8 -0
- package/archive/IHostedZoneConfig.ts +5 -0
- package/archive/NodeJsLambdaLayer.ts +42 -0
- package/archive/Output.ts +11 -0
- package/{lib/RestApi.js → archive/RestApi.ts} +96 -60
- package/{lib/Role.d.ts → archive/Role.ts} +165 -139
- package/archive/StaticWebSite.ts +159 -0
- package/archive/index.ts +18 -0
- package/archive/methods/apply-schema-to-method-options.ts +38 -0
- package/archive/methods/attach-function-to-api.ts +69 -0
- package/lib/{methods → build}/copy-files.js +1 -1
- package/lib/{methods → build/nodejs}/build-ecmascript.d.ts +2 -2
- package/lib/{methods → build/nodejs}/build-ecmascript.js +5 -5
- package/lib/{methods → build/nodejs}/build-node-source.d.ts +3 -1
- package/lib/{methods → build/nodejs}/build-node-source.js +6 -6
- package/lib/{methods → build/nodejs}/build-typescript.d.ts +2 -2
- package/lib/{methods → build/nodejs}/build-typescript.js +5 -5
- package/lib/{methods → build/nodejs}/install-node-modules.js +1 -1
- package/lib/create-stack.d.ts +41 -0
- package/lib/create-stack.js +48 -0
- package/lib/generate-identifier.d.ts +27 -0
- package/lib/generate-identifier.js +65 -0
- package/lib/index.d.ts +8 -15
- package/lib/index.js +40 -25
- package/lib/lambda/create-function.d.ts +20 -0
- package/lib/lambda/create-function.js +39 -0
- package/lib/lambda/create-nodejs-lambda.d.ts +28 -0
- package/lib/lambda/create-nodejs-lambda.js +38 -0
- package/lib/lambda-layer/apply-honeycomb-to-lambda.d.ts +2 -0
- package/lib/lambda-layer/apply-honeycomb-to-lambda.js +25 -0
- package/lib/lambda-layer/get-layer.d.ts +2 -0
- package/lib/lambda-layer/get-layer.js +20 -0
- package/lib/lambda-layer/layer-cache.d.ts +3 -0
- package/lib/lambda-layer/layer-cache.js +12 -0
- package/lib/load-configuration.d.ts +12 -0
- package/lib/load-configuration.js +42 -0
- package/lib/ssm/SsmParameter.d.ts +12 -0
- package/lib/ssm/get-existing-parameter.d.ts +9 -0
- package/lib/ssm/get-existing-parameter.js +41 -0
- package/lib/ssm/grant-read.d.ts +7 -0
- package/lib/ssm/grant-read.js +24 -0
- package/lib/ssm/index.d.ts +3 -0
- package/lib/ssm/index.js +9 -0
- package/lib/ssm/parameter-cache.d.ts +13 -0
- package/lib/ssm/parameter-cache.js +23 -0
- package/lib/ssm/string-value.d.ts +8 -0
- package/lib/ssm/string-value.js +14 -0
- package/package.json +4 -3
- package/lib/ApiCertificate.d.ts +0 -10
- package/lib/ApiCertificate.js +0 -31
- package/lib/CognitoApiGatewayAuthorizer.js +0 -24
- package/lib/DeployStack.d.ts +0 -19
- package/lib/DeployStack.js +0 -57
- package/lib/DynamoDbTable.d.ts +0 -12
- package/lib/DynamoDbTable.js +0 -34
- package/lib/FunctionIntegration.d.ts +0 -25
- package/lib/FunctionIntegration.js +0 -65
- package/lib/ICorsConfig.d.ts +0 -5
- package/lib/IDomainConfig.d.ts +0 -7
- package/lib/IDomainConfig.js +0 -2
- package/lib/IHostedZoneConfig.d.ts +0 -5
- package/lib/IHostedZoneConfig.js +0 -2
- package/lib/IStackArguments.d.ts +0 -8
- package/lib/IStackArguments.js +0 -2
- package/lib/NodeJsLambda.d.ts +0 -35
- package/lib/NodeJsLambda.js +0 -44
- package/lib/NodeJsLambdaLayer.d.ts +0 -25
- package/lib/NodeJsLambdaLayer.js +0 -35
- package/lib/Output.d.ts +0 -5
- package/lib/Output.js +0 -13
- package/lib/RestApi.d.ts +0 -28
- package/lib/Role.js +0 -27
- package/lib/SsmParameter.d.ts +0 -18
- package/lib/SsmParameter.js +0 -40
- package/lib/StaticWebSite.d.ts +0 -33
- package/lib/StaticWebSite.js +0 -136
- package/lib/methods/BuildOptions.d.ts +0 -3
- package/lib/methods/BuildOptions.js +0 -2
- package/lib/methods/apply-honeycomb-to-lambda.d.ts +0 -3
- package/lib/methods/apply-honeycomb-to-lambda.js +0 -23
- /package/lib/{methods → build}/copy-files.d.ts +0 -0
- /package/lib/{methods → build}/generate-hash.d.ts +0 -0
- /package/lib/{methods → build}/generate-hash.js +0 -0
- /package/lib/{methods → build}/get-files.d.ts +0 -0
- /package/lib/{methods → build}/get-files.js +0 -0
- /package/lib/{methods → build}/get-source-directory.d.ts +0 -0
- /package/lib/{methods → build}/get-source-directory.js +0 -0
- /package/lib/{methods → build}/hash-file.d.ts +0 -0
- /package/lib/{methods → build}/hash-file.js +0 -0
- /package/lib/{methods → build/nodejs}/install-node-modules.d.ts +0 -0
- /package/lib/{ICorsConfig.js → ssm/SsmParameter.js} +0 -0
- /package/lib/{methods → tools}/duration.d.ts +0 -0
- /package/lib/{methods → tools}/duration.js +0 -0
@@ -5,13 +5,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
6
6
|
exports.buildNodeSource = void 0;
|
7
7
|
const fs_extra_1 = require("fs-extra");
|
8
|
-
const get_source_directory_1 = require("
|
9
|
-
const get_files_1 = require("
|
10
|
-
const generate_hash_1 = require("
|
11
|
-
const duration_1 = __importDefault(require("
|
8
|
+
const get_source_directory_1 = require("../get-source-directory");
|
9
|
+
const get_files_1 = require("../get-files");
|
10
|
+
const generate_hash_1 = require("../generate-hash");
|
11
|
+
const duration_1 = __importDefault(require("../../tools/duration"));
|
12
12
|
const build_ecmascript_1 = require("./build-ecmascript");
|
13
13
|
const build_typescript_1 = require("./build-typescript");
|
14
|
-
const hash_file_1 = require("
|
14
|
+
const hash_file_1 = require("../hash-file");
|
15
15
|
/**
|
16
16
|
* Builds the source code for a Node.js project.
|
17
17
|
* @function buildNodeSource
|
@@ -32,7 +32,7 @@ function buildNodeSource(type, id, options) {
|
|
32
32
|
(0, fs_extra_1.emptyDirSync)(buildDir);
|
33
33
|
console.log('Cleanup Duration (ms)', rmComplete());
|
34
34
|
const isTypeScript = !!files.find(file => file.endsWith('tsconfig.json'));
|
35
|
-
isTypeScript ? (0, build_typescript_1.
|
35
|
+
isTypeScript ? (0, build_typescript_1.buildTypeScript)(srcDir, buildDir) : (0, build_ecmascript_1.buildEcmaScript)(files, srcDir, buildDir);
|
36
36
|
(0, hash_file_1.storeHash)(type, id, hash);
|
37
37
|
return buildDir;
|
38
38
|
}
|
@@ -1,8 +1,8 @@
|
|
1
1
|
/**
|
2
2
|
* Builds TypeScript source code.
|
3
3
|
* Ensures the build directory exists, installs necessary node modules, and compiles the TypeScript code.
|
4
|
-
* @function
|
4
|
+
* @function buildTypeScript
|
5
5
|
* @param {string} srcDir - The source directory containing the TypeScript code.
|
6
6
|
* @param {string} buildDir - The output directory for the compiled JavaScript code.
|
7
7
|
*/
|
8
|
-
export declare function
|
8
|
+
export declare function buildTypeScript(srcDir: string, buildDir: string): void;
|
@@ -3,19 +3,19 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
4
|
};
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
6
|
-
exports.
|
6
|
+
exports.buildTypeScript = void 0;
|
7
7
|
const child_process_1 = require("child_process");
|
8
|
-
const duration_1 = __importDefault(require("
|
8
|
+
const duration_1 = __importDefault(require("../../tools/duration"));
|
9
9
|
const fs_extra_1 = require("fs-extra");
|
10
10
|
const install_node_modules_1 = require("./install-node-modules");
|
11
11
|
/**
|
12
12
|
* Builds TypeScript source code.
|
13
13
|
* Ensures the build directory exists, installs necessary node modules, and compiles the TypeScript code.
|
14
|
-
* @function
|
14
|
+
* @function buildTypeScript
|
15
15
|
* @param {string} srcDir - The source directory containing the TypeScript code.
|
16
16
|
* @param {string} buildDir - The output directory for the compiled JavaScript code.
|
17
17
|
*/
|
18
|
-
function
|
18
|
+
function buildTypeScript(srcDir, buildDir) {
|
19
19
|
// Ensure the build directory exists
|
20
20
|
(0, fs_extra_1.ensureDirSync)(buildDir);
|
21
21
|
// Install necessary node modules
|
@@ -30,4 +30,4 @@ function buildTypescript(srcDir, buildDir) {
|
|
30
30
|
// Log the duration of the build process
|
31
31
|
console.log('NPM Install Duration (ms)', done());
|
32
32
|
}
|
33
|
-
exports.
|
33
|
+
exports.buildTypeScript = buildTypeScript;
|
@@ -5,7 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
6
6
|
exports.installNodeModules = void 0;
|
7
7
|
const child_process_1 = require("child_process");
|
8
|
-
const duration_1 = __importDefault(require("
|
8
|
+
const duration_1 = __importDefault(require("../../tools/duration"));
|
9
9
|
/**
|
10
10
|
* Installs node modules in a specified directory.
|
11
11
|
*
|
@@ -0,0 +1,41 @@
|
|
1
|
+
import { IConstruct } from "constructs";
|
2
|
+
import { Stack } from "aws-cdk-lib";
|
3
|
+
import { StackProps } from "aws-cdk-lib/core";
|
4
|
+
import { StackConfiguration } from "./load-configuration";
|
5
|
+
/**
|
6
|
+
* Interface for the arguments when creating a stack.
|
7
|
+
*/
|
8
|
+
export interface StackArguments extends StackProps {
|
9
|
+
stackName: string;
|
10
|
+
stage?: string;
|
11
|
+
project: string;
|
12
|
+
owner: string;
|
13
|
+
region: string;
|
14
|
+
config: StackConfiguration;
|
15
|
+
}
|
16
|
+
/**
|
17
|
+
* Interface for the deploy stack.
|
18
|
+
*/
|
19
|
+
export interface DeployStack {
|
20
|
+
stack: Stack;
|
21
|
+
name: string;
|
22
|
+
stage: string;
|
23
|
+
project: string;
|
24
|
+
config: StackConfiguration;
|
25
|
+
}
|
26
|
+
/**
|
27
|
+
* Creates a new stack.
|
28
|
+
* @param {IConstruct} scope - The scope in which to define this construct.
|
29
|
+
* @param {StackArguments} props - The arguments for creating the stack.
|
30
|
+
* @returns {DeployStack} The created stack.
|
31
|
+
*/
|
32
|
+
export declare function createStack(scope: IConstruct, props: StackArguments): DeployStack;
|
33
|
+
/**
|
34
|
+
* Helpful method to get the 'current' stack that is being defined. Hopefully this will reduce the need to pass the stack around everywhere.
|
35
|
+
*/
|
36
|
+
export declare function getCurrentStack(): DeployStack;
|
37
|
+
/**
|
38
|
+
* This sets the 'current' stack. This should be automatic everywhere, but in case something goes wrong here is a way to force the issue
|
39
|
+
* @param stack
|
40
|
+
*/
|
41
|
+
export declare function setCurrentStack(stack: DeployStack): DeployStack;
|
@@ -0,0 +1,48 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.setCurrentStack = exports.getCurrentStack = exports.createStack = void 0;
|
4
|
+
const aws_cdk_lib_1 = require("aws-cdk-lib");
|
5
|
+
const generate_identifier_1 = require("./generate-identifier");
|
6
|
+
const load_configuration_1 = require("./load-configuration");
|
7
|
+
/**
|
8
|
+
* Creates a new stack.
|
9
|
+
* @param {IConstruct} scope - The scope in which to define this construct.
|
10
|
+
* @param {StackArguments} props - The arguments for creating the stack.
|
11
|
+
* @returns {DeployStack} The created stack.
|
12
|
+
*/
|
13
|
+
function createStack(scope, props) {
|
14
|
+
const { stage = 'develop' } = props;
|
15
|
+
const stack = new aws_cdk_lib_1.Stack(scope, (0, generate_identifier_1.genId)(props.stackName, stage), {
|
16
|
+
...props,
|
17
|
+
stackName: (0, generate_identifier_1.genName)(props.stackName, stage)
|
18
|
+
});
|
19
|
+
stack.tags.setTag('stage', stage);
|
20
|
+
stack.tags.setTag('stack', (0, generate_identifier_1.genName)(props.stackName, stage));
|
21
|
+
stack.tags.setTag('project', props.project);
|
22
|
+
stack.tags.setTag('owner', props.owner);
|
23
|
+
return setCurrentStack({
|
24
|
+
stack,
|
25
|
+
name: props.stackName,
|
26
|
+
stage,
|
27
|
+
project: props.project,
|
28
|
+
config: (0, load_configuration_1.loadConfiguration)(stage)
|
29
|
+
});
|
30
|
+
}
|
31
|
+
exports.createStack = createStack;
|
32
|
+
let currentStack;
|
33
|
+
/**
|
34
|
+
* Helpful method to get the 'current' stack that is being defined. Hopefully this will reduce the need to pass the stack around everywhere.
|
35
|
+
*/
|
36
|
+
function getCurrentStack() {
|
37
|
+
return currentStack;
|
38
|
+
}
|
39
|
+
exports.getCurrentStack = getCurrentStack;
|
40
|
+
/**
|
41
|
+
* This sets the 'current' stack. This should be automatic everywhere, but in case something goes wrong here is a way to force the issue
|
42
|
+
* @param stack
|
43
|
+
*/
|
44
|
+
function setCurrentStack(stack) {
|
45
|
+
currentStack = stack;
|
46
|
+
return stack;
|
47
|
+
}
|
48
|
+
exports.setCurrentStack = setCurrentStack;
|
@@ -0,0 +1,27 @@
|
|
1
|
+
/**
|
2
|
+
* Generates a name by joining the provided strings with a hyphen.
|
3
|
+
* Each string is converted to lowercase and any uppercase letters are replaced with a hyphen followed by the lowercase letter.
|
4
|
+
* @param {...string} name - The strings to join.
|
5
|
+
* @returns {string} The generated name.
|
6
|
+
*/
|
7
|
+
export declare function genName(...name: string[]): string;
|
8
|
+
/**
|
9
|
+
* Generates an ID by joining the provided strings with a hyphen.
|
10
|
+
* The first letter of the ID is capitalized and any hyphen followed by a letter is replaced with the uppercase letter.
|
11
|
+
* @param {...string} name - The strings to join.
|
12
|
+
* @returns {string} The generated ID.
|
13
|
+
*/
|
14
|
+
export declare function genId(...name: string[]): string;
|
15
|
+
/**
|
16
|
+
* Generates a resource name for a stack by joining the stack name, resource, and stage with a hyphen.
|
17
|
+
* @param {...} resource - The resource.
|
18
|
+
* @returns The generated resource name.
|
19
|
+
*/
|
20
|
+
export declare function genStackResourceName(...resource: string[]): string;
|
21
|
+
/**
|
22
|
+
* Generates a resource ID for a stack by joining the stack name, stage, and resource.
|
23
|
+
* The first letter of the ID is capitalized and any hyphen followed by a letter is replaced with the uppercase letter.
|
24
|
+
* @param {...} resource - The resource.
|
25
|
+
* @returns The generated resource ID.
|
26
|
+
*/
|
27
|
+
export declare function genStackResourceId(...resource: string[]): string;
|
@@ -0,0 +1,65 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.genStackResourceId = exports.genStackResourceName = exports.genId = exports.genName = void 0;
|
4
|
+
const create_stack_1 = require("./create-stack");
|
5
|
+
/**
|
6
|
+
* Generates a name by joining the provided strings with a hyphen.
|
7
|
+
* Each string is converted to lowercase and any uppercase letters are replaced with a hyphen followed by the lowercase letter.
|
8
|
+
* @param {...string} name - The strings to join.
|
9
|
+
* @returns {string} The generated name.
|
10
|
+
*/
|
11
|
+
function genName(...name) {
|
12
|
+
return replaceMultipleDashesWithSingleDash(name
|
13
|
+
.filter(n => !!n)
|
14
|
+
.map(removeSpecialCharacters)
|
15
|
+
.map(toKebabCase)
|
16
|
+
.join('-')
|
17
|
+
.toLowerCase());
|
18
|
+
}
|
19
|
+
exports.genName = genName;
|
20
|
+
/**
|
21
|
+
* Generates an ID by joining the provided strings with a hyphen.
|
22
|
+
* The first letter of the ID is capitalized and any hyphen followed by a letter is replaced with the uppercase letter.
|
23
|
+
* @param {...string} name - The strings to join.
|
24
|
+
* @returns {string} The generated ID.
|
25
|
+
*/
|
26
|
+
function genId(...name) {
|
27
|
+
return toProperCase(genName(...name));
|
28
|
+
}
|
29
|
+
exports.genId = genId;
|
30
|
+
/**
|
31
|
+
* Generates a resource name for a stack by joining the stack name, resource, and stage with a hyphen.
|
32
|
+
* @param {...} resource - The resource.
|
33
|
+
* @returns The generated resource name.
|
34
|
+
*/
|
35
|
+
function genStackResourceName(...resource) {
|
36
|
+
const stack = (0, create_stack_1.getCurrentStack)();
|
37
|
+
return genName(stack.name, ...resource, stack.stage);
|
38
|
+
}
|
39
|
+
exports.genStackResourceName = genStackResourceName;
|
40
|
+
/**
|
41
|
+
* Generates a resource ID for a stack by joining the stack name, stage, and resource.
|
42
|
+
* The first letter of the ID is capitalized and any hyphen followed by a letter is replaced with the uppercase letter.
|
43
|
+
* @param {...} resource - The resource.
|
44
|
+
* @returns The generated resource ID.
|
45
|
+
*/
|
46
|
+
function genStackResourceId(...resource) {
|
47
|
+
const stack = (0, create_stack_1.getCurrentStack)();
|
48
|
+
return genId(stack.name, ...resource, stack.stage);
|
49
|
+
}
|
50
|
+
exports.genStackResourceId = genStackResourceId;
|
51
|
+
function removeSpecialCharacters(name) {
|
52
|
+
return name.replace(/[_/\\]/g, '-');
|
53
|
+
}
|
54
|
+
function replaceMultipleDashesWithSingleDash(name) {
|
55
|
+
return name.replace(/-{2,}/g, '-');
|
56
|
+
}
|
57
|
+
function toKebabCase(name) {
|
58
|
+
return name[0] + name.substring(1).replace(/[A-Z]/g, v => '-' + v.toLowerCase());
|
59
|
+
}
|
60
|
+
function toProperCase(name) {
|
61
|
+
return name.split('-')
|
62
|
+
.filter(n => !!n)
|
63
|
+
.map(v => v[0].toUpperCase() + v.substring(1))
|
64
|
+
.join('');
|
65
|
+
}
|
package/lib/index.d.ts
CHANGED
@@ -1,15 +1,8 @@
|
|
1
|
-
export {
|
2
|
-
export {
|
3
|
-
export {
|
4
|
-
export {
|
5
|
-
export {
|
6
|
-
export {
|
7
|
-
export {
|
8
|
-
export
|
9
|
-
export { NodeJsLambda } from "./NodeJsLambda";
|
10
|
-
export { NodeJsLambdaLayer } from "./NodeJsLambdaLayer";
|
11
|
-
export { Output } from "./Output";
|
12
|
-
export { RestApi } from "./RestApi";
|
13
|
-
export { Role } from "./Role";
|
14
|
-
export { SsmParameter } from "./SsmParameter";
|
15
|
-
export { StaticWebSite } from "./StaticWebSite";
|
1
|
+
export { buildNodeSource } from './build/nodejs/build-node-source';
|
2
|
+
export { buildEcmaScript } from './build/nodejs/build-ecmascript';
|
3
|
+
export { buildTypeScript } from './build/nodejs/build-typescript';
|
4
|
+
export { createNodeJsLambda } from './lambda/create-nodejs-lambda';
|
5
|
+
export { createStack, StackArguments } from './create-stack';
|
6
|
+
export { StackConfiguration } from './load-configuration';
|
7
|
+
export { genName, genId, genStackResourceName, genStackResourceId } from './generate-identifier';
|
8
|
+
export * as ssm from "./ssm";
|
package/lib/index.js
CHANGED
@@ -1,27 +1,42 @@
|
|
1
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
|
+
};
|
2
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.
|
4
|
-
var
|
5
|
-
Object.defineProperty(exports, "
|
6
|
-
var
|
7
|
-
Object.defineProperty(exports, "
|
8
|
-
var
|
9
|
-
Object.defineProperty(exports, "
|
10
|
-
var
|
11
|
-
Object.defineProperty(exports, "
|
12
|
-
var
|
13
|
-
Object.defineProperty(exports, "
|
14
|
-
var
|
15
|
-
Object.defineProperty(exports, "
|
16
|
-
|
17
|
-
Object.defineProperty(exports, "
|
18
|
-
|
19
|
-
|
20
|
-
var RestApi_1 = require("./RestApi");
|
21
|
-
Object.defineProperty(exports, "RestApi", { enumerable: true, get: function () { return RestApi_1.RestApi; } });
|
22
|
-
var Role_1 = require("./Role");
|
23
|
-
Object.defineProperty(exports, "Role", { enumerable: true, get: function () { return Role_1.Role; } });
|
24
|
-
var SsmParameter_1 = require("./SsmParameter");
|
25
|
-
Object.defineProperty(exports, "SsmParameter", { enumerable: true, get: function () { return SsmParameter_1.SsmParameter; } });
|
26
|
-
var StaticWebSite_1 = require("./StaticWebSite");
|
27
|
-
Object.defineProperty(exports, "StaticWebSite", { enumerable: true, get: function () { return StaticWebSite_1.StaticWebSite; } });
|
26
|
+
exports.ssm = exports.genStackResourceId = exports.genStackResourceName = exports.genId = exports.genName = exports.createStack = exports.createNodeJsLambda = exports.buildTypeScript = exports.buildEcmaScript = exports.buildNodeSource = void 0;
|
27
|
+
var build_node_source_1 = require("./build/nodejs/build-node-source");
|
28
|
+
Object.defineProperty(exports, "buildNodeSource", { enumerable: true, get: function () { return build_node_source_1.buildNodeSource; } });
|
29
|
+
var build_ecmascript_1 = require("./build/nodejs/build-ecmascript");
|
30
|
+
Object.defineProperty(exports, "buildEcmaScript", { enumerable: true, get: function () { return build_ecmascript_1.buildEcmaScript; } });
|
31
|
+
var build_typescript_1 = require("./build/nodejs/build-typescript");
|
32
|
+
Object.defineProperty(exports, "buildTypeScript", { enumerable: true, get: function () { return build_typescript_1.buildTypeScript; } });
|
33
|
+
var create_nodejs_lambda_1 = require("./lambda/create-nodejs-lambda");
|
34
|
+
Object.defineProperty(exports, "createNodeJsLambda", { enumerable: true, get: function () { return create_nodejs_lambda_1.createNodeJsLambda; } });
|
35
|
+
var create_stack_1 = require("./create-stack");
|
36
|
+
Object.defineProperty(exports, "createStack", { enumerable: true, get: function () { return create_stack_1.createStack; } });
|
37
|
+
var generate_identifier_1 = require("./generate-identifier");
|
38
|
+
Object.defineProperty(exports, "genName", { enumerable: true, get: function () { return generate_identifier_1.genName; } });
|
39
|
+
Object.defineProperty(exports, "genId", { enumerable: true, get: function () { return generate_identifier_1.genId; } });
|
40
|
+
Object.defineProperty(exports, "genStackResourceName", { enumerable: true, get: function () { return generate_identifier_1.genStackResourceName; } });
|
41
|
+
Object.defineProperty(exports, "genStackResourceId", { enumerable: true, get: function () { return generate_identifier_1.genStackResourceId; } });
|
42
|
+
exports.ssm = __importStar(require("./ssm"));
|
@@ -0,0 +1,20 @@
|
|
1
|
+
import { Function as Lambda, FunctionProps } from "aws-cdk-lib/aws-lambda";
|
2
|
+
import { Duration } from "aws-cdk-lib";
|
3
|
+
/**
|
4
|
+
* Interface for the properties of the FunctionIntegration class.
|
5
|
+
*/
|
6
|
+
export interface FunctionIntegrationProps {
|
7
|
+
funcProps?: FunctionProps;
|
8
|
+
timeout?: Duration;
|
9
|
+
memory?: number;
|
10
|
+
}
|
11
|
+
export interface FunctionIntegration {
|
12
|
+
id: string;
|
13
|
+
function: Lambda;
|
14
|
+
}
|
15
|
+
/**
|
16
|
+
* Initializes a new function
|
17
|
+
* @param {string} id - The ID of the function.
|
18
|
+
* @param {FunctionIntegrationProps} options - The properties of the function.
|
19
|
+
*/
|
20
|
+
export declare function createFunction(id: string, options: FunctionIntegrationProps): FunctionIntegration;
|
@@ -0,0 +1,39 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.createFunction = void 0;
|
4
|
+
const aws_lambda_1 = require("aws-cdk-lib/aws-lambda");
|
5
|
+
const aws_cdk_lib_1 = require("aws-cdk-lib");
|
6
|
+
const apply_honeycomb_to_lambda_1 = require("../lambda-layer/apply-honeycomb-to-lambda");
|
7
|
+
const aws_logs_1 = require("aws-cdk-lib/aws-logs");
|
8
|
+
const core_1 = require("aws-cdk-lib/core");
|
9
|
+
const generate_identifier_1 = require("../generate-identifier");
|
10
|
+
const create_stack_1 = require("../create-stack");
|
11
|
+
/**
|
12
|
+
* Initializes a new function
|
13
|
+
* @param {string} id - The ID of the function.
|
14
|
+
* @param {FunctionIntegrationProps} options - The properties of the function.
|
15
|
+
*/
|
16
|
+
function createFunction(id, options) {
|
17
|
+
const props = (0, apply_honeycomb_to_lambda_1.applyHoneycombToLambda)({
|
18
|
+
functionName: (0, generate_identifier_1.genStackResourceName)(id),
|
19
|
+
memorySize: options.memory || 256,
|
20
|
+
timeout: options.timeout || aws_cdk_lib_1.Duration.seconds(30),
|
21
|
+
...(options.funcProps || {})
|
22
|
+
});
|
23
|
+
const { stack } = (0, create_stack_1.getCurrentStack)();
|
24
|
+
const details = {
|
25
|
+
id,
|
26
|
+
function: new aws_lambda_1.Function(stack, (0, generate_identifier_1.genStackResourceId)(id, 'lambda'), props)
|
27
|
+
};
|
28
|
+
new aws_cdk_lib_1.CfnOutput(stack, (0, generate_identifier_1.genStackResourceId)(id, 'function-name'), {
|
29
|
+
value: details.function.functionName,
|
30
|
+
exportName: (0, generate_identifier_1.genStackResourceName)(id, 'function-name')
|
31
|
+
});
|
32
|
+
new aws_logs_1.LogRetention(stack, (0, generate_identifier_1.genStackResourceId)(id, 'log-retention'), {
|
33
|
+
logGroupName: details.function.logGroup.logGroupName,
|
34
|
+
retention: aws_logs_1.RetentionDays.ONE_WEEK,
|
35
|
+
removalPolicy: core_1.RemovalPolicy.DESTROY,
|
36
|
+
});
|
37
|
+
return details;
|
38
|
+
}
|
39
|
+
exports.createFunction = createFunction;
|
@@ -0,0 +1,28 @@
|
|
1
|
+
import { FunctionOptions } from "aws-cdk-lib/aws-lambda";
|
2
|
+
import { FunctionIntegration } from "./create-function";
|
3
|
+
import { Duration } from "aws-cdk-lib";
|
4
|
+
/**
|
5
|
+
* Interface for the properties of a Node.js function.
|
6
|
+
*/
|
7
|
+
interface NodeFunctionProps {
|
8
|
+
/**
|
9
|
+
* The properties of the function.
|
10
|
+
*/
|
11
|
+
funcProps?: FunctionOptions;
|
12
|
+
/**
|
13
|
+
* The timeout duration for the function.
|
14
|
+
*/
|
15
|
+
timeout?: Duration;
|
16
|
+
/**
|
17
|
+
* The memory size for the function.
|
18
|
+
*/
|
19
|
+
memory?: number;
|
20
|
+
}
|
21
|
+
/**
|
22
|
+
* Creates a new Node.js AWS Lambda function.
|
23
|
+
* @param {string} id - The ID of the function.
|
24
|
+
* @param {NodeFunctionProps} [options] - The properties of the function.
|
25
|
+
* @returns {FunctionIntegration} The created function.
|
26
|
+
*/
|
27
|
+
export declare function createNodeJsLambda(id: string, options?: NodeFunctionProps): FunctionIntegration;
|
28
|
+
export {};
|
@@ -0,0 +1,38 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
|
+
};
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
6
|
+
exports.createNodeJsLambda = void 0;
|
7
|
+
const aws_lambda_1 = require("aws-cdk-lib/aws-lambda");
|
8
|
+
const create_function_1 = require("./create-function");
|
9
|
+
const build_node_source_1 = require("../build/nodejs/build-node-source");
|
10
|
+
const duration_1 = __importDefault(require("../tools/duration"));
|
11
|
+
/**
|
12
|
+
* Creates a new Node.js AWS Lambda function.
|
13
|
+
* @param {string} id - The ID of the function.
|
14
|
+
* @param {NodeFunctionProps} [options] - The properties of the function.
|
15
|
+
* @returns {FunctionIntegration} The created function.
|
16
|
+
*/
|
17
|
+
function createNodeJsLambda(id, options) {
|
18
|
+
console.log('Defining Node Lambda', id);
|
19
|
+
// Measure the duration of the build process
|
20
|
+
const done = (0, duration_1.default)();
|
21
|
+
// Build the Node.js source code
|
22
|
+
const buildDir = (0, build_node_source_1.buildNodeSource)('lambda', id);
|
23
|
+
console.log('Total Build Duration (ms)', done());
|
24
|
+
// Call the parent constructor with the function properties
|
25
|
+
return (0, create_function_1.createFunction)(id, {
|
26
|
+
...options,
|
27
|
+
funcProps: {
|
28
|
+
...options?.funcProps,
|
29
|
+
// The source code of the function
|
30
|
+
code: aws_lambda_1.Code.fromAsset(buildDir),
|
31
|
+
// The handler of the function
|
32
|
+
handler: `${id}.handler`,
|
33
|
+
// The runtime of the function
|
34
|
+
runtime: aws_lambda_1.Runtime.NODEJS_20_X
|
35
|
+
}
|
36
|
+
});
|
37
|
+
}
|
38
|
+
exports.createNodeJsLambda = createNodeJsLambda;
|
@@ -0,0 +1,25 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.applyHoneycombToLambda = void 0;
|
4
|
+
const ssm_1 = require("../ssm");
|
5
|
+
const create_stack_1 = require("../create-stack");
|
6
|
+
const get_layer_1 = require("./get-layer");
|
7
|
+
function applyHoneycombToLambda(props) {
|
8
|
+
const { stack } = (0, create_stack_1.getCurrentStack)();
|
9
|
+
const honeyCombLayer = (0, get_layer_1.getLayer)('hc-layer', `arn:aws:lambda:${stack.region}:702835727665:layer:honeycomb-lambda-extension-x86_64-v11-1-1:1`);
|
10
|
+
const layers = props.layers ? [...props.layers] : [];
|
11
|
+
const environment = { ...props.environment };
|
12
|
+
const options = {
|
13
|
+
parameterGroup: (0, create_stack_1.getCurrentStack)().project
|
14
|
+
};
|
15
|
+
layers.push(honeyCombLayer);
|
16
|
+
environment.LIBHONEY_API_KEY = (0, ssm_1.stringValue)(`/honeycomb/api-key`, options);
|
17
|
+
environment.LIBHONEY_DATASET = (0, ssm_1.stringValue)(`/honeycomb/dataset`, options);
|
18
|
+
environment.LOGS_API_DISABLE_PLATFORM_MSGS = "true";
|
19
|
+
return {
|
20
|
+
...props,
|
21
|
+
layers,
|
22
|
+
environment
|
23
|
+
};
|
24
|
+
}
|
25
|
+
exports.applyHoneycombToLambda = applyHoneycombToLambda;
|
@@ -0,0 +1,20 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.getLayer = void 0;
|
4
|
+
const aws_lambda_1 = require("aws-cdk-lib/aws-lambda");
|
5
|
+
const create_stack_1 = require("../create-stack");
|
6
|
+
const layer_cache_1 = require("./layer-cache");
|
7
|
+
const generate_identifier_1 = require("../generate-identifier");
|
8
|
+
function getLayer(name, arn) {
|
9
|
+
let layer = (0, layer_cache_1.get)(arn);
|
10
|
+
if (!layer) {
|
11
|
+
layer = createLayer(name, arn);
|
12
|
+
(0, layer_cache_1.store)(arn, layer);
|
13
|
+
}
|
14
|
+
return layer;
|
15
|
+
}
|
16
|
+
exports.getLayer = getLayer;
|
17
|
+
function createLayer(name, arn) {
|
18
|
+
const { stack } = (0, create_stack_1.getCurrentStack)();
|
19
|
+
return aws_lambda_1.LayerVersion.fromLayerVersionArn(stack, (0, generate_identifier_1.genStackResourceId)(name), arn);
|
20
|
+
}
|
@@ -0,0 +1,12 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.store = exports.get = void 0;
|
4
|
+
const layerCache = {};
|
5
|
+
function get(name) {
|
6
|
+
return layerCache[name];
|
7
|
+
}
|
8
|
+
exports.get = get;
|
9
|
+
function store(name, param) {
|
10
|
+
layerCache[name] = param;
|
11
|
+
}
|
12
|
+
exports.store = store;
|
@@ -0,0 +1,12 @@
|
|
1
|
+
/**
|
2
|
+
* Interface for the stack configuration.
|
3
|
+
*/
|
4
|
+
export interface StackConfiguration {
|
5
|
+
}
|
6
|
+
/**
|
7
|
+
* Loads the configuration for a given stage.
|
8
|
+
* If the configuration file does not exist, an empty object is returned.
|
9
|
+
* @param {string} stage - The stage for which to load the configuration. Defaults to the value of the STAGE environment variable, or "develop" if STAGE is not set.
|
10
|
+
* @returns {StackConfiguration} The loaded configuration.
|
11
|
+
*/
|
12
|
+
export declare function loadConfiguration(stage?: string): StackConfiguration;
|
@@ -0,0 +1,42 @@
|
|
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.loadConfiguration = void 0;
|
27
|
+
const yaml = __importStar(require("js-yaml"));
|
28
|
+
const fs = __importStar(require("fs-extra"));
|
29
|
+
/**
|
30
|
+
* Loads the configuration for a given stage.
|
31
|
+
* If the configuration file does not exist, an empty object is returned.
|
32
|
+
* @param {string} stage - The stage for which to load the configuration. Defaults to the value of the STAGE environment variable, or "develop" if STAGE is not set.
|
33
|
+
* @returns {StackConfiguration} The loaded configuration.
|
34
|
+
*/
|
35
|
+
function loadConfiguration(stage = process.env.STAGE || "develop") {
|
36
|
+
const path = `config/${stage}.yml`;
|
37
|
+
if (fs.existsSync(path)) {
|
38
|
+
return yaml.load(fs.readFileSync(`config/${stage}.yml`).toString());
|
39
|
+
}
|
40
|
+
return {};
|
41
|
+
}
|
42
|
+
exports.loadConfiguration = loadConfiguration;
|
@@ -0,0 +1,12 @@
|
|
1
|
+
import { IStringParameter } from "aws-cdk-lib/aws-ssm";
|
2
|
+
import { IKey } from "aws-cdk-lib/aws-kms";
|
3
|
+
export interface SsmParameterOptions {
|
4
|
+
decryptWithKey?: IKey;
|
5
|
+
parameterGroup?: string;
|
6
|
+
}
|
7
|
+
export interface SsmParameter {
|
8
|
+
shortName: string;
|
9
|
+
parameterArn: string;
|
10
|
+
decryptWithKey?: IKey;
|
11
|
+
parameter: IStringParameter;
|
12
|
+
}
|
@@ -0,0 +1,9 @@
|
|
1
|
+
import { SsmParameter, SsmParameterOptions } from "./SsmParameter";
|
2
|
+
/**
|
3
|
+
* Retrieves an existing SSM parameter.
|
4
|
+
* If the parameter is not in the cache, it references the parameter and stores it in the cache.
|
5
|
+
* @param {string} name - The name of the parameter.
|
6
|
+
* @param {SsmParameterOptions} [options] - The options for the parameter.
|
7
|
+
* @returns {SsmParameter} The SSM parameter.
|
8
|
+
*/
|
9
|
+
export declare function getExistingParameter(name: string, options?: SsmParameterOptions): SsmParameter;
|