Skip to content

feat(core): Switch client to the CloudFront front door + reuse Hosting's - #513

Draft
Simone319 wants to merge 2 commits into
zimzha/front-door-d2from
zimzha/front-door-d3
Draft

feat(core): Switch client to the CloudFront front door + reuse Hosting's#513
Simone319 wants to merge 2 commits into
zimzha/front-door-d2from
zimzha/front-door-d3

Conversation

@Simone319

@Simone319 Simone319 commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

Draft — Track D, D3. Stacked on #512 (D2) — its base is the D2 branch, so this PR's diff is D3-only. Review/merge #512 first.

What this does

Completes the front door: the client now resolves the front-door origin, and a Hosting app reuses Hosting's distribution instead of provisioning a second one.

  • Replaces D2's eager builder with scheduleFrontDoor, a one-shot CDK aspect resolved at synth (after a Hosting construct built past create() exists): Hosting present → reuse it (no 2nd distribution); no Hosting + provision → create the Blocks-owned one; else nothing.
  • Distribution is scoped under the owning BlocksStack/BlocksBackend so multiple backends in one stack don't collide (a real bug the core suite caught).
  • BlocksStack's ApiUrl output is Lazy → the front-door origin when provisioned, else the gateway; the deploy script writes it into config.json, so the client switch needs no client-code change.
  • Drops D2's per-compute frontDoorOrigin in favor of a URL contract: httpOriginFromApiUrl centralizes origin construction and Hosting's addApiBehaviors reuses it. Hosting publishes its distribution via registerHostingDistribution.
  • Deprecates BlocksStack/BlocksBackend gateway + apiUrl (removed in D5).

Deferred to D4: per-namespace behaviors, per-compute URLs, the client's per-namespace path.

Testing (this is where the e2e lands)

  • Unit/synth: front-door.cdk.test.ts — prod creates one distribution + ApiUrl references it; sandbox none; Hosting present → no Blocks-owned distribution. Core 783, bb-lambda-compute, blocks all green.
  • e2e (new): the comprehensive app now uses the production preset in production mode (overriding only removalPolicy→DESTROY + deletionProtection→false so CI can tear down, keeping sandbox allowedOrigins). So e2e-production provisions the managed front door, the client resolves the CloudFront origin, and the whole suite — including the auth cookie round-trip — runs through it. Added a prod-only assertion that config.json.apiUrl is *.cloudfront.net, not execute-api.
  • Coverage by tier: sandbox e2e → no-front-door path; prod e2e → managed front door; hosting-* Playwright → Hosting-reuse path (cookie-through-CloudFront).

CI note: this PR is stacked on the D2 branch as a native GitHub stack (#514), and the full pr-checks suite — including Build, Unit Tests, E2E Local — runs against it, so the front-door e2e runs here. (An earlier pr-checks.yml base-branch tweak was dropped: the stack triggers the full suite without it.) Non-breaking coordinated redeploy (no prod traffic yet).

@changeset-bot

changeset-bot Bot commented Sep 8, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 9002551

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 23 packages
Name Type
@aws-blocks/core Minor
@aws-blocks/bb-logger Patch
@aws-blocks/bb-kv-store Patch
@aws-blocks/bb-distributed-table Patch
@aws-blocks/auth-common Patch
@aws-blocks/bb-app-setting Patch
@aws-blocks/bb-data Patch
@aws-blocks/bb-distributed-data Patch
@aws-blocks/bb-auth-basic Patch
@aws-blocks/bb-auth-cognito Patch
@aws-blocks/bb-auth-oidc Patch
@aws-blocks/bb-realtime Patch
@aws-blocks/bb-async-job Patch
@aws-blocks/bb-dashboard Patch
@aws-blocks/bb-cron-job Patch
@aws-blocks/bb-file-bucket Patch
@aws-blocks/bb-agent Patch
@aws-blocks/bb-knowledge-base Patch
@aws-blocks/bb-email-client Patch
@aws-blocks/bb-tracer Patch
@aws-blocks/bb-metrics Patch
@aws-blocks/bb-lambda-compute Patch
@aws-blocks/blocks Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@Simone319 Simone319 changed the title feat(core): Switch client to the CloudFront front door + reuse Hosting's (Track D, D3) feat(core): Switch client to the CloudFront front door + reuse Hosting's Sep 8, 2026
…'s (D3)

Complete the front door (Track D, D3): the client now resolves the front-door
origin, and a Hosting app reuses Hosting's distribution instead of provisioning
a second one.

- Replace D2's eager finalizeFrontDoor with scheduleFrontDoor, which registers a
  one-shot CDK aspect resolved at synth — after a Hosting construct built past
  create() exists. Branches: Hosting present → reuse it (no 2nd distribution);
  no Hosting + provision → create the Blocks-owned distribution; else nothing.
- The distribution is scoped under the owning BlocksStack/BlocksBackend so
  multiple backends in one parent stack don't collide on the construct id.
- BlocksStack's ApiUrl output is now Lazy → the front-door origin when
  provisioned, else the gateway; the deploy script writes it into the client
  config.json, so the client switch needs no client-code change.
- Drop the per-compute frontDoorOrigin seam (added in D2) in favor of a URL
  contract: httpOriginFromApiUrl centralizes origin construction and Hosting's
  addApiBehaviors reuses it. Hosting publishes its distribution via
  registerHostingDistribution.
- Deprecate BlocksStack/BlocksBackend gateway + apiUrl (removed in D5).

Per-namespace routing to multiple computes and the client's per-namespace path
land with multi-compute fan-out (D4). Non-breaking coordinated redeploy.
The comprehensive app hard-pinned BlocksPresets.sandbox in every mode, so the
production e2e never ran the production posture and the managed CloudFront API
front door (provisionApiFrontDoor, on in the production preset) had no deployed
coverage.

- index.cdk.ts: production mode now uses BlocksPresets.production, overriding
  only the teardown-hostile fields (removalPolicy → DESTROY, deletionProtection
  → false) so CI can still destroy the stack, and keeping the sandbox
  allowedOrigins so the Node e2e client's cross-origin probes still pass.
  Sandbox mode is unchanged.
- e2e.test.ts: add a production-only assertion that the client resolves the
  CloudFront front-door origin (config.json apiUrl is *.cloudfront.net, not
  execute-api). Every other test then runs THROUGH the front door in prod mode
  by virtue of that resolved URL — including the auth cookie round-trip.

Covers the "no Hosting + provisionApiFrontDoor" branch in the right tier (prod
e2e), leaving the no-front-door path to the sandbox e2e and the Hosting-reuse
path to the hosting-* Playwright suites.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant