@byaga/cdk-patterns 0.11.2 → 0.11.4
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/build/nodejs/build-typescript.js +8 -0
- package/lib/build/nodejs/install-node-modules.js +1 -1
- package/lib/cloud-watch/create-log-group.d.ts +15 -0
- package/lib/cloud-watch/create-log-group.js +22 -0
- package/lib/lambda/create-function.d.ts +2 -0
- package/lib/lambda/create-function.js +10 -4
- package/package.json +1 -1
@@ -8,6 +8,8 @@ const child_process_1 = require("child_process");
|
|
8
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
|
+
const copy_files_1 = require("../copy-files");
|
12
|
+
const path_1 = require("path");
|
11
13
|
/**
|
12
14
|
* Builds TypeScript source code.
|
13
15
|
* Ensures the build directory exists, installs necessary node modules, and compiles the TypeScript code.
|
@@ -27,6 +29,12 @@ function buildTypeScript(srcDir, buildDir) {
|
|
27
29
|
cwd: srcDir,
|
28
30
|
stdio: 'inherit'
|
29
31
|
});
|
32
|
+
// Manually Move the package.json and install prod dependencies
|
33
|
+
(0, copy_files_1.copyFiles)([
|
34
|
+
(0, path_1.resolve)(srcDir, 'package.json'),
|
35
|
+
(0, path_1.resolve)(srcDir, 'package-lock.json'),
|
36
|
+
], srcDir, buildDir);
|
37
|
+
(0, install_node_modules_1.installNodeModules)(buildDir, ['dev', 'optional', 'peer']);
|
30
38
|
// Log the duration of the build process
|
31
39
|
console.log('NPM Install Duration (ms)', done());
|
32
40
|
}
|
@@ -21,7 +21,7 @@ function installNodeModules(dir, omit = []) {
|
|
21
21
|
// Start measuring the duration of the `npm install` command
|
22
22
|
const installComplete = (0, duration_1.default)();
|
23
23
|
// Run the `npm install` command in the specified directory, omitting certain types of dependencies if specified
|
24
|
-
(0, child_process_1.execSync)(`npm i${omit.
|
24
|
+
(0, child_process_1.execSync)(`npm i${omit.map(o => ` --omit=${o}`).join('')} --quite`, {
|
25
25
|
cwd: dir
|
26
26
|
});
|
27
27
|
// Log the duration of the `npm install` command
|
@@ -0,0 +1,15 @@
|
|
1
|
+
import { LogGroup, RetentionDays } from "aws-cdk-lib/aws-logs";
|
2
|
+
/**
|
3
|
+
* Interface for the properties of the FunctionIntegration class.
|
4
|
+
*/
|
5
|
+
export interface LogGroupProps {
|
6
|
+
category?: string;
|
7
|
+
retention?: RetentionDays;
|
8
|
+
}
|
9
|
+
/**
|
10
|
+
* Initializes a new function
|
11
|
+
* @param id - The name of the resource sending logs to this log group
|
12
|
+
* @param type - The type of resource sending logs to this log group.
|
13
|
+
* @param options - The properties of the function.
|
14
|
+
*/
|
15
|
+
export declare function createLogGroup(id: string, type: string, options?: LogGroupProps): LogGroup;
|
@@ -0,0 +1,22 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.createLogGroup = void 0;
|
4
|
+
const aws_logs_1 = require("aws-cdk-lib/aws-logs");
|
5
|
+
const generate_identifier_1 = require("../generate-identifier");
|
6
|
+
const create_stack_1 = require("../create-stack");
|
7
|
+
/**
|
8
|
+
* Initializes a new function
|
9
|
+
* @param id - The name of the resource sending logs to this log group
|
10
|
+
* @param type - The type of resource sending logs to this log group.
|
11
|
+
* @param options - The properties of the function.
|
12
|
+
*/
|
13
|
+
function createLogGroup(id, type, options) {
|
14
|
+
const category = options?.category ?? 'aws';
|
15
|
+
const { stack } = (0, create_stack_1.getCurrentStack)();
|
16
|
+
const logGroupName = `/${category}/${type}/${id}`;
|
17
|
+
return new aws_logs_1.LogGroup(stack, (0, generate_identifier_1.genStackResourceId)(id, 'log-group'), {
|
18
|
+
logGroupName,
|
19
|
+
retention: options?.retention ?? aws_logs_1.RetentionDays.ONE_WEEK
|
20
|
+
});
|
21
|
+
}
|
22
|
+
exports.createLogGroup = createLogGroup;
|
@@ -1,5 +1,6 @@
|
|
1
1
|
import { Function as Lambda, FunctionProps } from "aws-cdk-lib/aws-lambda";
|
2
2
|
import { Duration } from "aws-cdk-lib";
|
3
|
+
import { LogGroup } from "aws-cdk-lib/aws-logs";
|
3
4
|
/**
|
4
5
|
* Interface for the properties of the FunctionIntegration class.
|
5
6
|
*/
|
@@ -10,6 +11,7 @@ export interface FunctionIntegrationProps {
|
|
10
11
|
}
|
11
12
|
export interface FunctionIntegration {
|
12
13
|
id: string;
|
14
|
+
logGroup: LogGroup;
|
13
15
|
lambda: Lambda;
|
14
16
|
}
|
15
17
|
/**
|
@@ -5,9 +5,10 @@ const aws_lambda_1 = require("aws-cdk-lib/aws-lambda");
|
|
5
5
|
const aws_cdk_lib_1 = require("aws-cdk-lib");
|
6
6
|
const apply_honeycomb_to_lambda_1 = require("../lambda-layer/apply-honeycomb-to-lambda");
|
7
7
|
const aws_logs_1 = require("aws-cdk-lib/aws-logs");
|
8
|
-
const core_1 = require("aws-cdk-lib/core");
|
9
8
|
const generate_identifier_1 = require("../generate-identifier");
|
10
9
|
const create_stack_1 = require("../create-stack");
|
10
|
+
const core_1 = require("aws-cdk-lib/core");
|
11
|
+
const create_log_group_1 = require("../cloud-watch/create-log-group");
|
11
12
|
/**
|
12
13
|
* Initializes a new function
|
13
14
|
* @param {string} id - The ID of the function.
|
@@ -21,18 +22,23 @@ function createFunction(id, options) {
|
|
21
22
|
...(options.funcProps || {})
|
22
23
|
});
|
23
24
|
const { stack } = (0, create_stack_1.getCurrentStack)();
|
25
|
+
const logGroup = (0, create_log_group_1.createLogGroup)(id, 'lambda');
|
24
26
|
const details = {
|
25
27
|
id,
|
26
|
-
|
28
|
+
logGroup,
|
29
|
+
lambda: new aws_lambda_1.Function(stack, (0, generate_identifier_1.genStackResourceId)(id, 'lambda'), {
|
30
|
+
...props,
|
31
|
+
logGroup
|
32
|
+
})
|
27
33
|
};
|
28
34
|
new aws_cdk_lib_1.CfnOutput(stack, (0, generate_identifier_1.genStackResourceId)(id, 'function-name'), {
|
29
35
|
value: details.lambda.functionName,
|
30
36
|
exportName: (0, generate_identifier_1.genStackResourceName)(id, 'function-name')
|
31
37
|
});
|
32
38
|
new aws_logs_1.LogRetention(stack, (0, generate_identifier_1.genStackResourceId)(id, 'log-retention'), {
|
33
|
-
logGroupName:
|
39
|
+
logGroupName: logGroup.logGroupName,
|
34
40
|
retention: aws_logs_1.RetentionDays.ONE_WEEK,
|
35
|
-
removalPolicy: core_1.RemovalPolicy.DESTROY
|
41
|
+
removalPolicy: core_1.RemovalPolicy.DESTROY
|
36
42
|
});
|
37
43
|
return details;
|
38
44
|
}
|
package/package.json
CHANGED