Skip to content

feat: add AWS Lambda Web Functions support - #103

Merged
ncipollina merged 23 commits into
mainfrom
feat/lambda-web-functions
Oct 26, 2026
Merged

ncipollina merged 23 commits into
mainfrom
feat/lambda-web-functions

Conversation

@ncipollina

@ncipollina ncipollina commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Adds AWS Lambda Web Function constructs to LayeredCraft.Cdk.Constructs, letting consumers deploy an ordinary HTTP server (Next.js, ASP.NET Core, Blazor Static SSR) from a zip in a versioned S3 bucket behind an AWS-managed HTTPS endpoint. Implements the approved design (revision 4, docs/designs/lambda-web-functions-integration.md) tracked by #98. The change is additive: no existing construct (Lambda Function, Static Site, DynamoDB Table, Cognito) is modified and their synthesized templates are unchanged.

Release sequencing: merging this PR is intended to publish a v2.6.0 preview package via the existing main-merge pipeline. Stable v2.6.0 will not be published until Sharedale milestone 6 is complete and the preview package is validated in Sharedale (release-gate bead cdkc-18e.17).

Changes

New public APIs

  • WebFunctionConstruct — owns one Web Function: function, revision, default endpoint, optional execution role, optional log group, and the function's single resource-based policy. AddEndpoint adds additional endpoints; reserved child ids are rejected.
  • WebFunctionEndpointConstruct (IWebFunctionEndpoint : IResourceWithPolicyV2) — an individual endpoint exposing EndpointName, EndpointArn, DomainName, Url, AuthType, EndpointType, plus GrantInvoke (identity- or resource-policy based), GrantCloudFrontInvoke, AddToResourcePolicy, and FromEndpointAttributes for imports.
  • WebFunctionOrigin — returns a CloudFront IOrigin with origin access control (OAC) and the required resource-policy statement for IamAuth endpoints.
  • Models — WebFunctionConstructProps, WebFunctionCode / WebFunctionCodeFromBucketOptions / WebFunctionCodeBucketPolicy, WebFunctionRuntime, WebFunctionLogs, WebFunctionEndpointOptions / IWebFunctionEndpointOptions, WebFunctionEndpointAttributes, WebFunctionEndpointType, WebFunctionAuthType, WebFunctionCallerPolicy / WebFunctionInvokeGrantOptions, WebFunctionOriginProps / WebFunctionOriginWithOacProps / WebFunctionOriginPermissions.

CloudFront OAC integration

WebFunctionOrigin wires an origin access control together with the matching resource-policy statement on the Web Function endpoint, for same-stack distributions. Adding/removing a second distribution adds/removes a scoped statement (verified live).

IAM / resource-policy security model

  • Invokes are scoped to lambda:InvokeWebFunctionEndpoint per endpoint.
  • GrantInvoke writes an identity policy only when the caller account can be established; otherwise it fails closed. Service, wildcard, account, and condition-wrapped principals are rejected.
  • Each function owns exactly one resource-based policy. WebFunctionCallerPolicy distinguishes Automatic vs ExternallyManaged grants; immutable imported roles receive resource-policy-only grants.

Minimum AWS CDK version

Amazon.CDK.Lib floor raised to 2.274.0 (required for the OAC signing enums). Consumers below the floor receive an automatic NuGet resolution upgrade.

Workload support

Next.js, ASP.NET Core shims, and Blazor Static SSR deploy through the same public API; differences live only in the artifact and configuration. There are no workload-specific constructs or helpers.

Validation

  • Build: dotnet build -c Release — 0 warnings / 0 errors across net8.0–net11.0.
  • Tests: 2140 passed, 0 failed, 0 skipped (535 × 4 TFMs; xUnit v3 / Microsoft.Testing.Platform).
  • Coverage (net8.0): 94.30% line, 85.89% branch — above the repository's 80% gate.
  • Docs: mkdocs build --strict passes.
  • Golden templates: 17 existing-construct goldens remain byte-identical; 8 new Web Function goldens added.
  • Real AWS sandbox: deployed, updated (v1→v2 revision move), and destroyed on live AWS. Design §19.1 items 3.1–3.6 and 3.8 PASS (artifact bucket-policy modes, revision activation/routing, signed/unsigned/ungranted/endpoint-scoped invocation, CloudFront OAC, live resource-policy statements, Blazor page + static asset). Full teardown verified — no residual stacks, buckets, roles, policies, distributions, OACs, or tagged resources.

Documented limitations

  • Cross-account invocation was not exercised (no second sandbox account available; recorded as unverified, not unsupported).
  • SigV4A / MultiRegion / PerRegion runtime scenarios were not exercised (single HomeRegion endpoint).
  • WebFunctionCode.FromAsset is not available in this release — upload to a versioned bucket first.
  • CDK 2.274.0 emits F3006 default-rule validation warnings for the new AWS::Lambda::WebFunction* resource types (warnings by default).
  • With WebFunctionLogs.ServiceDefault() the Lambda service creates a log group that is not stack-owned and survives CloudFormation teardown.

Intentional deferrals

  • Customer-managed revision encryption (KmsKeyArn) — deferred; S3 artifact encryption (SSE-S3 / SSE-KMS on the code bucket) is supported.
  • Optional T4a spike (managed AllViewer policy warning) closed won't-implement — not feasible with public CDK APIs.

Related

Notes for Reviewers

  • Public API additions only; no changes to existing construct source.
  • Merge is expected to trigger the existing main-merge preview NuGet publish (v2.6.0 preview line). No stable tag/release is created by this PR.
  • The WebFunctionConstruct IAM classification relies partly on CDK/jsii principal materialization in Amazon.CDK.Lib 2.274.0; the CdkUpgradeGuard_* security suite guards future CDK bumps.

ncipollina and others added 21 commits October 22, 2026 21:22
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Adapt the read-only smoke suite to the documented AWS CLI 2.38.x lambda-web
response shapes without weakening any mandatory acceptance check:

- revision identity now comes from get-web-function-endpoint
  (RevisionWeights[].RevisionId, endpoint State) corroborated by
  list-web-function-revisions; get-web-function no longer exposes a revision.
- resource-policy lookups use get-resource-policy --resource-arn with the
  web-function ARN derived from the endpoint ARN.
- capture_revision is errexit-safe on bash 3.2 so a missing API path reports
  BLOCKED instead of aborting the run.
- stub and regression harness extended to the new shapes (smoke 44/44,
  lifecycle 61/61); missing/malformed responses stay BLOCKED, never PASS.
…stic

- Correct the owned-bucket SSE-KMS/DSSE error messages to reference
  lambda.amazonaws.com (the principal whose key policy must allow
  kms:Decrypt), not the function execution role
- Document that service-created default log groups outlive the stack
  (T7c teardown observation) and how to clean them up in sandboxes
- Pin the corrected wording in the Web Function construct tests
- Add cdkc-18e.17 (P1): Sharedale consumer validation and stable release gate,
  tracking Sharedale milestone 6 as an external dependency.
- Redact real AWS account, IAM user, sandbox id, and CloudFront distribution
  identifiers from cdkc-18e.13/cdkc-18e.14 evidence; preserve all AWS
  acceptance results and verification detail.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 25, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-26T00:01:46.774896Z 9413fe5 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@github-actions github-actions Bot added the type: feat New feature label Oct 25, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 00dc8f8835

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +210 to +212
if (homeRegion is not null
&& !Token.IsUnresolved(homeRegion)
&& resolved.All(region => string.Equals(region, homeRegion, StringComparison.Ordinal)))

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Defer region validation when non-home regions are unresolved

When the function's stack has an explicit region, configuring a MultiRegion or PerRegion endpoint with regions supplied through CloudFormation tokens (for example, Fn.ImportValue) throws during construction. Tokens are filtered out of resolved, so resolved.All(...) returns true for an empty list, or for a list containing only the literal home region—even though an unresolved entry may resolve to a valid non-home region. Reject this configuration only when all supplied regions are literal and demonstrably home-region-only; otherwise defer the check to deployment. The existing ValidateRegions_SkipsTokens test misses this path because it does not supply homeRegion, whereas the endpoint constructor always supplies the stack's region.

Useful? React with 👍 / 👎.

…d Regions

Addresses Codex review on PR #103 (P2).

WebFunctionValidation.ValidateRegions rejected a MultiRegion/PerRegion endpoint
whose Regions were all unresolved CloudFormation tokens whenever the stack had a
literal region: resolved was empty, and resolved.All(...) returns true for an
empty sequence. This contradicted the module's contract that unresolved tokens
are skipped rather than rejected, and blocked token-supplied non-home Regions.

The home-Region-only check now applies only when every supplied Region is
literal (resolved.Count == regions.Count); otherwise validation is deferred to
deployment. Adds tests covering all-token and mixed token/literal Region lists.

Also marks the props-builder _runtime field readonly (it is never reassigned).
@ncipollina

Copy link
Copy Markdown
Contributor Author

@codex review

Addressed the P2 finding on WebFunctionValidation.ValidateRegions in commit a2eb9ff: the multi-Region home-Region-only check now runs only when every supplied Region is literal (resolved.Count == regions.Count); otherwise validation is deferred to deployment, so token-supplied non-home Regions no longer throw. Added tests for the all-token and mixed token/literal cases. Also marked the props-builder _runtime field readonly.

Please re-review this change specifically and check for regressions introduced by it.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep it up!

Reviewed commit: a2eb9ff203

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Behaviour-preserving cleanups flagged by the GitHub code-quality review:

- ValidateTimeout: test whole-second timeouts with decimal modulo instead of
  double comparison.
- ValidateEntryPoint: drop the redundant 'entryPoint is null' constant check
  and rely on 'string.IsNullOrEmpty' (keeps nullable flow without CS8602).
- WebFunctionConstructAssertions: use OfType<T>() instead of an implicit
  filter in a foreach.
- Use Path.Join instead of Path.Combine in the golden-template harness and the
  ASP.NET Core / Blazor samples where a later argument could in principle be
  rooted.

Build remains 0 warnings / 0 errors; 537/537 net8.0 tests pass.
@ncipollina

Copy link
Copy Markdown
Contributor Author

@codex review

Follow-up on the earlier P2 finding (ValidateRegions multi-Region home-Region check). The fix landed in a2eb9ff and is in the current head; the original comment was posted against the pre-fix commit 00dc8f8, so please re-review the current head.

Current head 9413fe5 includes:

  • a2eb9ff: defer the multi-Region home-Region-only check unless every supplied Region is literal (resolved.Count == regions.Count); new tests for all-token and mixed token/literal Region lists.
  • 9413fe5: behaviour-preserving cleanups for the automated code-quality review (decimal whole-second check, remove redundant entryPoint is null, OfType<T>(), Path.Join).

Please confirm the region validation is now correct and check for regressions in these changes.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Can't wait for the next one!

Reviewed commit: 9413fe5321

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@ncipollina
ncipollina merged commit d647ad8 into main Oct 26, 2026
9 checks passed
@ncipollina
ncipollina deleted the feat/lambda-web-functions branch October 26, 2026 00:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type: feat New feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]: Investigate a focused AWS Lambda Web Functions CDK construct

1 participant