@byaga/cdk-patterns 0.11.1 → 0.11.3
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/cloud-watch/create-log-group.d.ts +15 -0
- package/lib/cloud-watch/create-log-group.js +22 -0
- package/lib/create-stack.d.ts +0 -1
- package/lib/index.d.ts +1 -1
- package/lib/index.js +2 -1
- package/lib/lambda/create-function.d.ts +3 -1
- package/lib/lambda/create-function.js +11 -5
- package/package.json +1 -1
@@ -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;
|
package/lib/create-stack.d.ts
CHANGED
package/lib/index.d.ts
CHANGED
@@ -2,7 +2,7 @@ export { buildNodeSource } from './build/nodejs/build-node-source';
|
|
2
2
|
export { buildEcmaScript } from './build/nodejs/build-ecmascript';
|
3
3
|
export { buildTypeScript } from './build/nodejs/build-typescript';
|
4
4
|
export { createNodeJsLambda } from './lambda/create-nodejs-lambda';
|
5
|
-
export { createStack, StackArguments } from './create-stack';
|
5
|
+
export { createStack, StackArguments, getCurrentStack } from './create-stack';
|
6
6
|
export { StackConfiguration } from './load-configuration';
|
7
7
|
export { genName, genId, genStackResourceName, genStackResourceId } from './generate-identifier';
|
8
8
|
export * as ssm from "./ssm";
|
package/lib/index.js
CHANGED
@@ -23,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
23
23
|
return result;
|
24
24
|
};
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
26
|
-
exports.ssm = exports.genStackResourceId = exports.genStackResourceName = exports.genId = exports.genName = exports.createStack = exports.createNodeJsLambda = exports.buildTypeScript = exports.buildEcmaScript = exports.buildNodeSource = void 0;
|
26
|
+
exports.ssm = exports.genStackResourceId = exports.genStackResourceName = exports.genId = exports.genName = exports.getCurrentStack = exports.createStack = exports.createNodeJsLambda = exports.buildTypeScript = exports.buildEcmaScript = exports.buildNodeSource = void 0;
|
27
27
|
var build_node_source_1 = require("./build/nodejs/build-node-source");
|
28
28
|
Object.defineProperty(exports, "buildNodeSource", { enumerable: true, get: function () { return build_node_source_1.buildNodeSource; } });
|
29
29
|
var build_ecmascript_1 = require("./build/nodejs/build-ecmascript");
|
@@ -34,6 +34,7 @@ var create_nodejs_lambda_1 = require("./lambda/create-nodejs-lambda");
|
|
34
34
|
Object.defineProperty(exports, "createNodeJsLambda", { enumerable: true, get: function () { return create_nodejs_lambda_1.createNodeJsLambda; } });
|
35
35
|
var create_stack_1 = require("./create-stack");
|
36
36
|
Object.defineProperty(exports, "createStack", { enumerable: true, get: function () { return create_stack_1.createStack; } });
|
37
|
+
Object.defineProperty(exports, "getCurrentStack", { enumerable: true, get: function () { return create_stack_1.getCurrentStack; } });
|
37
38
|
var generate_identifier_1 = require("./generate-identifier");
|
38
39
|
Object.defineProperty(exports, "genName", { enumerable: true, get: function () { return generate_identifier_1.genName; } });
|
39
40
|
Object.defineProperty(exports, "genId", { enumerable: true, get: function () { return generate_identifier_1.genId; } });
|
@@ -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,7 +11,8 @@ export interface FunctionIntegrationProps {
|
|
10
11
|
}
|
11
12
|
export interface FunctionIntegration {
|
12
13
|
id: string;
|
13
|
-
|
14
|
+
logGroup: LogGroup;
|
15
|
+
lambda: Lambda;
|
14
16
|
}
|
15
17
|
/**
|
16
18
|
* Initializes a new function
|
@@ -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
|
-
value: details.
|
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