Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion .beads/issues.jsonl

Large diffs are not rendered by default.

14 changes: 11 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

**Lambda Web Functions** — deploy an ordinary HTTP server (Next.js, ASP.NET Core, Blazor Static SSR, and so on) from a zip in a versioned S3 bucket, behind a managed HTTPS endpoint:

- **`WebFunctionConstruct`**: owns one Web Function's function, revision, default endpoint, execution role (optional), log group (optional), and single resource-based policy. Supports `AddEndpoint` for additional endpoints.
- **`WebFunctionConstruct`**: owns one Web Function's function, revision, default endpoint, execution role (optional), log groups (optional), and single resource-based policy. Supports `AddEndpoint` for additional endpoints.
- **Managed companion log groups** ([#104](https://github.com/LayeredCraft/cdk-constructs/issues/104)): `WebFunctionLogs.Create` now creates the centralized `/aws/lambda/web/{FunctionName}` group **and** its home-Region `.local` companion. The companion defaults to `THREE_DAYS` retention (centralized remains `TWO_WEEKS`) and can be set independently with `companionRetention`. Both groups share the configured removal policy, the revision depends on both, and `WebFunctionConstruct.LocalLogGroup` exposes the companion.
- **Caller-owned companions**: `WebFunctionLogs.Use(logGroup, companion)` optionally accepts the existing `.local` companion. `Use` never creates a group, and literal companion names must be `{centralized-name}.local`.
- **Logging warnings**: W1 (`@layeredcraft/cdk-constructs:webFunctionUnmanagedCompanionLogGroup`) for `Use` without a companion, and W2 (`@layeredcraft/cdk-constructs:webFunctionRemoteCompanionLogGroups`) for `PerRegion`/`MultiRegion` endpoints, which create unmanaged companions outside the home Region. Both are acknowledgeable and can fail `cdk synth --strict` until acknowledged.
- **`WebFunctionEndpointConstruct`** (`IWebFunctionEndpoint`): an individual endpoint, with `GrantInvoke` (identity- or resource-policy based), `GrantCloudFrontInvoke`, `AddToResourcePolicy`, and `FromEndpointAttributes` for imported endpoints.
- **`WebFunctionOrigin`**: returns a CloudFront `IOrigin` with origin access control (OAC) and the required resource-policy statement, for `IamAuth` endpoints.
- **Models**: `WebFunctionCode` / `WebFunctionCodeFromBucketOptions` / `WebFunctionCodeBucketPolicy`, `WebFunctionRuntime`, `WebFunctionLogs`, `WebFunctionEndpointOptions` (and `IWebFunctionEndpointOptions`), `WebFunctionEndpointAttributes`, `WebFunctionEndpointType`, `WebFunctionAuthType`, `WebFunctionCallerPolicy` / `WebFunctionInvokeGrantOptions`, `WebFunctionOriginProps` / `WebFunctionOriginWithOacProps` / `WebFunctionOriginPermissions`, and `WebFunctionConstructProps`.
- **Testing helpers**: `WebFunctionConstructAssertions` fluent `Template` assertions and `WebFunctionConstructPropsBuilder` via `CdkTestHelper.CreateWebFunctionPropsBuilder()` (plus `WebFunctionConstructAutoData`).
- **Testing helpers**: `WebFunctionConstructAssertions` fluent `Template` assertions and `WebFunctionConstructPropsBuilder` via `CdkTestHelper.CreateWebFunctionPropsBuilder()` (plus `WebFunctionConstructAutoData`). Companion logging adds `ShouldHaveWebFunctionLogGroup`, `ShouldHaveCompanionLogGroup`, and `ShouldHaveRevisionDependingOnLogGroups`.

### 🔄 Changed

Expand All @@ -30,10 +33,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- **Customer-managed revision encryption** (`KmsKeyArn`) is **deferred**. S3 artifact encryption (SSE-S3 / SSE-KMS on the code bucket) is supported.
- **Principal-behavior regression rule**: identity-policy write detection and principal classification rely partly on CDK/jsii behavior observed in `Amazon.CDK.Lib` 2.274.0. Every `Amazon.CDK.Lib` upgrade (including Dependabot bumps) must pass the focused real-CDK Web Function security tests — especially the `CdkUpgradeGuard_*` suite — and a failure blocks the upgrade until the signals are re-verified. The library fails closed when authorization cannot be established.
- **Compatibility**: Lambda Web Functions require a Region where the feature is available; CDK 2.274.0 emits `F3006` default-rule validation warnings for the new `AWS::Lambda::WebFunction*` resource types (warnings by default).
- **Service-created default log groups**: with `WebFunctionLogs.ServiceDefault()` the construct creates no `AWS::Logs::LogGroup`; the Lambda service creates `/aws/lambda/web/{name}` on first invocation. That group has no expiry and is **not** removed by CloudFormation on teardown, so it keeps your invocation history. CDK-managed `Create()` groups are stack-owned and follow their `RemovalPolicy`.
- **Service-created default log groups**: with `WebFunctionLogs.ServiceDefault()` the construct creates no `AWS::Logs::LogGroup`; the Lambda service creates `/aws/lambda/web/{name}` and its `.local` companion on first invocation. Those groups have no expiry and are **not** removed by CloudFormation on teardown, so they keep your invocation history. CDK-managed `Create()` groups are stack-owned, follow their `RemovalPolicy`, and are both removed or both retained.
- **Two log groups per `Create()`** ([#104](https://github.com/LayeredCraft/cdk-constructs/issues/104)): Lambda writes to the serving Region's `.local` companion and centralizes into the home-Region group without removing the companion events. The same events therefore appear in both groups and storage is billed for both. Use the centralized group for ordinary queries and alarms; use the serving Region's `.local` group for the lowest-latency Live Tail.
- **Upgrading an existing function** ([#104](https://github.com/LayeredCraft/cdk-constructs/issues/104)): if Lambda already created `{centralized-name}.local` (for example from an earlier preview, `ServiceDefault()`, or `Use(g)`), a deployment that now manages that companion can fail with `AlreadyExists`. Remedies are to delete the service-created group immediately before deploying (accepting event loss) or to move to a new centralized group name. There is no adoption or migration support.
- **Compatibility**: existing source calls (`Create()`, `Create(r)`, `Create(r, p)`, and `Use(g)`) compile unchanged. Because optional parameters were appended to `WebFunctionLogs.Create` and `Use`, assemblies built against `2.6.0-preview.27` must be recompiled; otherwise they fail with `MissingMethodException`. No released package version is claimed by this entry.

### 🐛 Fixed

- **Companion log-group write grant** ([#104](https://github.com/LayeredCraft/cdk-constructs/issues/104)): `WebFunctionLogs.Use` with a custom or tokenized centralized name now also grants the execution role write access to the `.local` companion's log streams, and `logs:CreateLogGroup` where Lambda may create the companion. Without it, Lambda did not deliver logs from that Region.
- **Log-group ordering** ([#104](https://github.com/LayeredCraft/cdk-constructs/issues/104)): the revision now depends on both managed groups in `Create` mode, and on same-stack supplied groups in `Use` mode. Imported and cross-stack groups remain caller-ordered and must exist before deployment.
- **KMS diagnostic wording**: the owned-artifact-bucket SSE-KMS and DSSE error messages now name the **Lambda service principal** (`lambda.amazonaws.com`) as the principal whose key policy must allow `kms:Decrypt`, instead of the function execution role. Authorization behavior is unchanged; only the message text and its tests changed.

## [2.0.0] - 2025-08-06
Expand Down
7 changes: 4 additions & 3 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ dotnet add test/LayeredCraft.Cdk.Constructs.Tests/ package PackageName
- Handles Lambda permissions for multiple targets (function, version, alias)

**WebFunctionConstruct** (`src/LayeredCraft.Cdk.Constructs/WebFunctionConstruct.cs`)
- Creates an AWS Lambda Web Function from a versioned S3 artifact (`WebFunctionCode.FromBucket`), plus its immutable revision, default endpoint, execution role (optional), log group (optional), and the function's **single** resource-based policy
- Creates an AWS Lambda Web Function from a versioned S3 artifact (`WebFunctionCode.FromBucket`), plus its immutable revision, default endpoint, execution role (optional), logging (optional), and the function's **single** resource-based policy
- `WebFunctionLogs.Create` creates the centralized log group and its home-Region `.local` companion (defaults: 14 days and 3 days, shared removal policy); `Use(logGroup, companion)` accepts a caller-owned companion; `ServiceDefault()` creates neither. `WebFunctionConstruct.LocalLogGroup` exposes the managed or supplied companion, and warnings W1/W2 cover unmanaged and remote companions
- `WebFunctionEndpointConstruct` (`IWebFunctionEndpoint`) represents each endpoint; `AddEndpoint` adds more; `GrantInvoke` (identity- or resource-policy based) and `GrantCloudFrontInvoke` are endpoint-scoped
- `WebFunctionOrigin` returns a CloudFront `IOrigin` that configures origin access control (OAC) and the required resource-policy statement for `IamAuth` endpoints
- Workload-neutral: Next.js, ASP.NET Core, and Blazor Static SSR deploy through the same public API; the differences live in the artifacts and configuration only
Expand Down Expand Up @@ -185,8 +186,8 @@ The library includes comprehensive testing helpers for consumers:

**WebFunctionConstructAssertions** (`WebFunctionConstructAssertions.cs`):
- Extension methods for `Template` assertions specific to Web Functions
- `ShouldHaveWebFunction()`, `ShouldHaveRevision()`, `ShouldHaveRevisionCode()`, `ShouldHaveEndpoint()`, `ShouldHaveEndpointScaling()`, `ShouldHaveInvokeGrant()`, `ShouldHaveSingleResourcePolicy()`, `ShouldHaveNoResourcePolicy()`, `ShouldAllowCloudFront()`, `ShouldAllowResourcePolicyPrincipal()`, `ShouldHaveWebFunctionOac()`, `ShouldHaveCodeBucketReadStatement()`
- Match by function and endpoint **names**, not logical IDs; require `Effect = Allow` with the expected action and endpoint resource
- `ShouldHaveWebFunction()`, `ShouldHaveRevision()`, `ShouldHaveRevisionCode()`, `ShouldHaveEndpoint()`, `ShouldHaveEndpointScaling()`, `ShouldHaveInvokeGrant()`, `ShouldHaveSingleResourcePolicy()`, `ShouldHaveNoResourcePolicy()`, `ShouldAllowCloudFront()`, `ShouldAllowResourcePolicyPrincipal()`, `ShouldHaveWebFunctionOac()`, `ShouldHaveCodeBucketReadStatement()`, `ShouldHaveWebFunctionLogGroup()`, `ShouldHaveCompanionLogGroup()`, `ShouldHaveRevisionDependingOnLogGroups()`
- Match by function and endpoint **names**, not logical IDs; require `Effect = Allow` with the expected action and endpoint resource. Log-group assertions match by log-group name and exact `RetentionInDays`; use `ShouldHaveWebFunctionLogGroup`, not the Lambda construct's `ShouldHaveLogGroup`

**WebFunctionConstructPropsBuilder** (`WebFunctionConstructPropsBuilder.cs`):
- Fluent builder for Web Function props: `WithFunctionName()`, `WithCode()`, `WithTestArtifact()`, `WithIamAuthEndpoint()`, `WithApplicationManagedEndpoint()`, `WithEndpoint()`, `WithEnvironmentVariable()`, `WithEntryPoint()`, `WithTimeout()`, `WithMaxConcurrencyPerEnvironment()`, `WithRole()`, `WithLogs()`, `Build()`
Expand Down
Loading
Loading