@byaga/cdk-patterns 0.11.2 → 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.
@@ -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
- lambda: new aws_lambda_1.Function(stack, (0, generate_identifier_1.genStackResourceId)(id, 'lambda'), props)
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: details.lambda.logGroup.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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@byaga/cdk-patterns",
3
- "version": "0.11.2",
3
+ "version": "0.11.3",
4
4
  "description": "Collection of common patterns used when making AWS CloudFormation templates using CDK",
5
5
  "main": "./lib/index.js",
6
6
  "types": "./lib/index.d.ts",