@composurecdk/lambda 0.1.2 → 0.1.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.
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Function as LambdaFunction, type FunctionProps } from "aws-cdk-lib/aws-lambda";
|
|
2
|
+
import type { LogGroup } from "aws-cdk-lib/aws-logs";
|
|
2
3
|
import { type IConstruct } from "constructs";
|
|
3
4
|
import { type IBuilder, type Lifecycle } from "@composurecdk/core";
|
|
4
5
|
export type FunctionBuilderProps = FunctionProps;
|
|
@@ -9,6 +10,20 @@ export type FunctionBuilderProps = FunctionProps;
|
|
|
9
10
|
export interface FunctionBuilderResult {
|
|
10
11
|
/** The Lambda function construct created by the builder. */
|
|
11
12
|
function: LambdaFunction;
|
|
13
|
+
/**
|
|
14
|
+
* The CloudWatch LogGroup created for the function, or `undefined` if
|
|
15
|
+
* the user provided their own via the `logGroup` property.
|
|
16
|
+
*
|
|
17
|
+
* By default the builder creates a managed LogGroup using
|
|
18
|
+
* {@link createLogGroupBuilder} with well-architected defaults (retention
|
|
19
|
+
* policy, removal policy). This follows AWS CDK guidance to create a
|
|
20
|
+
* `LogGroup` explicitly rather than relying on the auto-created default,
|
|
21
|
+
* which cannot be configured via CDK.
|
|
22
|
+
*
|
|
23
|
+
* @see https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_lambda-readme.html
|
|
24
|
+
* @see https://docs.aws.amazon.com/lambda/latest/dg/monitoring-cloudwatchlogs-loggroups.html
|
|
25
|
+
*/
|
|
26
|
+
logGroup?: LogGroup;
|
|
12
27
|
}
|
|
13
28
|
/**
|
|
14
29
|
* A fluent builder for configuring and creating an AWS Lambda function.
|
|
@@ -22,6 +37,14 @@ export interface FunctionBuilderResult {
|
|
|
22
37
|
* a Lambda function with the configured properties and returns a
|
|
23
38
|
* {@link FunctionBuilderResult}.
|
|
24
39
|
*
|
|
40
|
+
* Unless a user-supplied `logGroup` is provided, the builder automatically
|
|
41
|
+
* creates a managed CloudWatch LogGroup via {@link createLogGroupBuilder}
|
|
42
|
+
* with well-architected defaults (retention, removal policy) and wires it
|
|
43
|
+
* to the function. This ensures full control over log lifecycle and follows
|
|
44
|
+
* AWS CDK guidance to create a LogGroup explicitly.
|
|
45
|
+
*
|
|
46
|
+
* @see https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_lambda-readme.html
|
|
47
|
+
*
|
|
25
48
|
* @example
|
|
26
49
|
* ```ts
|
|
27
50
|
* const handler = createFunctionBuilder()
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"function-builder.d.ts","sourceRoot":"","sources":["../src/function-builder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,IAAI,cAAc,EAAE,KAAK,aAAa,EAAE,MAAM,wBAAwB,CAAC;AACxF,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,EAAW,KAAK,QAAQ,EAAE,KAAK,SAAS,EAAE,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"function-builder.d.ts","sourceRoot":"","sources":["../src/function-builder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,IAAI,cAAc,EAAE,KAAK,aAAa,EAAE,MAAM,wBAAwB,CAAC;AACxF,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,EAAW,KAAK,QAAQ,EAAE,KAAK,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAI5E,MAAM,MAAM,oBAAoB,GAAG,aAAa,CAAC;AAEjD;;;GAGG;AACH,MAAM,WAAW,qBAAqB;IACpC,4DAA4D;IAC5D,QAAQ,EAAE,cAAc,CAAC;IAEzB;;;;;;;;;;;;OAYG;IACH,QAAQ,CAAC,EAAE,QAAQ,CAAC;CACrB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,MAAM,MAAM,gBAAgB,GAAG,QAAQ,CAAC,oBAAoB,EAAE,eAAe,CAAC,CAAC;AAE/E,cAAM,eAAgB,YAAW,SAAS,CAAC,qBAAqB,CAAC;IAC/D,KAAK,EAAE,OAAO,CAAC,oBAAoB,CAAC,CAAM;IAE1C,KAAK,CAAC,KAAK,EAAE,UAAU,EAAE,EAAE,EAAE,MAAM,GAAG,qBAAqB;CAoB5D;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,wBAAgB,qBAAqB,IAAI,gBAAgB,CAExD"}
|
package/dist/function-builder.js
CHANGED
|
@@ -1,15 +1,24 @@
|
|
|
1
1
|
import { Function as LambdaFunction } from "aws-cdk-lib/aws-lambda";
|
|
2
2
|
import { Builder } from "@composurecdk/core";
|
|
3
|
+
import { createLogGroupBuilder } from "@composurecdk/logs";
|
|
3
4
|
import { FUNCTION_DEFAULTS } from "./defaults.js";
|
|
4
5
|
class FunctionBuilder {
|
|
5
6
|
props = {};
|
|
6
7
|
build(scope, id) {
|
|
8
|
+
let logGroup;
|
|
9
|
+
let logGroupProps = {};
|
|
10
|
+
if (!this.props.logGroup) {
|
|
11
|
+
logGroup = createLogGroupBuilder().build(scope, `${id}LogGroup`).logGroup;
|
|
12
|
+
logGroupProps = { logGroup };
|
|
13
|
+
}
|
|
7
14
|
const mergedProps = {
|
|
8
15
|
...FUNCTION_DEFAULTS,
|
|
16
|
+
...logGroupProps,
|
|
9
17
|
...this.props,
|
|
10
18
|
};
|
|
11
19
|
return {
|
|
12
20
|
function: new LambdaFunction(scope, id, mergedProps),
|
|
21
|
+
logGroup,
|
|
13
22
|
};
|
|
14
23
|
}
|
|
15
24
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"function-builder.js","sourceRoot":"","sources":["../src/function-builder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,IAAI,cAAc,EAAsB,MAAM,wBAAwB,CAAC;
|
|
1
|
+
{"version":3,"file":"function-builder.js","sourceRoot":"","sources":["../src/function-builder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,IAAI,cAAc,EAAsB,MAAM,wBAAwB,CAAC;AAGxF,OAAO,EAAE,OAAO,EAAiC,MAAM,oBAAoB,CAAC;AAC5E,OAAO,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAC3D,OAAO,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AA4DlD,MAAM,eAAe;IACnB,KAAK,GAAkC,EAAE,CAAC;IAE1C,KAAK,CAAC,KAAiB,EAAE,EAAU;QACjC,IAAI,QAA8B,CAAC;QACnC,IAAI,aAAa,GAAG,EAAE,CAAC;QAEvB,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC;YACzB,QAAQ,GAAG,qBAAqB,EAAE,CAAC,KAAK,CAAC,KAAK,EAAE,GAAG,EAAE,UAAU,CAAC,CAAC,QAAQ,CAAC;YAC1E,aAAa,GAAG,EAAE,QAAQ,EAAE,CAAC;QAC/B,CAAC;QAED,MAAM,WAAW,GAAG;YAClB,GAAG,iBAAiB;YACpB,GAAG,aAAa;YAChB,GAAG,IAAI,CAAC,KAAK;SACU,CAAC;QAE1B,OAAO;YACL,QAAQ,EAAE,IAAI,cAAc,CAAC,KAAK,EAAE,EAAE,EAAE,WAAW,CAAC;YACpD,QAAQ;SACT,CAAC;IACJ,CAAC;CACF;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,MAAM,UAAU,qBAAqB;IACnC,OAAO,OAAO,CAAwC,eAAe,CAAC,CAAC;AACzE,CAAC"}
|