@composurecdk/lambda
v0.1.2
Published
Composable Lambda function builder with well-architected defaults
Readme
@composurecdk/lambda
Lambda builders for ComposureCDK.
This package provides a fluent builder for AWS Lambda functions with secure, AWS-recommended defaults. It wraps the CDK Function construct — refer to the CDK documentation for the full set of configurable properties.
Function Builder
import { createFunctionBuilder } from "@composurecdk/lambda";
const handler = createFunctionBuilder()
.runtime(Runtime.NODEJS_22_X)
.handler("index.handler")
.code(Code.fromAsset("lambda"))
.build(stack, "MyFunction");Every FunctionProps property is available as a fluent setter on the builder.
Secure Defaults
createFunctionBuilder applies the following defaults. Each can be overridden via the builder's fluent API.
| Property | Default | Rationale |
| --------------- | -------- | ------------------------------------------------------------------------------------ |
| tracing | ACTIVE | Enables X-Ray distributed tracing for observability. |
| loggingFormat | JSON | Structured logs for CloudWatch Logs Insights auto-discovery and consistent querying. |
These defaults are guided by the AWS Well-Architected Serverless Applications Lens.
The defaults are exported as FUNCTION_DEFAULTS for visibility and testing:
import { FUNCTION_DEFAULTS } from "@composurecdk/lambda";Overriding defaults
import { LoggingFormat, Tracing } from "aws-cdk-lib/aws-lambda";
const handler = createFunctionBuilder()
.runtime(Runtime.NODEJS_22_X)
.handler("index.handler")
.code(Code.fromAsset("lambda"))
.tracing(Tracing.PASS_THROUGH)
.loggingFormat(LoggingFormat.TEXT)
.build(stack, "MyFunction");Examples
- LambdaApiStack — REST API backed by a Lambda function, wired with
ref - DualFunctionStack — Two Lambda functions with different configurations
- MultiStackApp — Lambda split across stacks via
.withStacks() - StrategyStackApp — Lambda split across stacks via
.withStackStrategy()
