Skip to content

feat(core): Provision managed CloudFront API front door - #512

Draft
Simone319 wants to merge 1 commit into
mainfrom
zimzha/front-door-d2
Draft

feat(core): Provision managed CloudFront API front door#512
Simone319 wants to merge 1 commit into
mainfrom
zimzha/front-door-d2

Conversation

@Simone319

@Simone319 Simone319 commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

Draft. First of a stacked pair — a follow-up PR (#513) builds on this branch and switches the client to route through the front door. This PR stands on its own: it provisions infrastructure but changes no request path yet.

What this does

Provisions a managed CloudFront API front door: a single CloudFront distribution that becomes the stable public origin for the backend's HTTP surface. Today a browser talks directly to the API Gateway, whose hostname changes whenever the backend's compute topology changes; routing all backend traffic through one long-lived distribution keeps the public hostname fixed, which is what lets Secure auth cookies survive adding, scaling, or swapping a compute.

In this PR the distribution is provisioned and its URL published, but nothing routes through it yet — the client still calls the API Gateway directly. That makes this an additive, no-traffic-change step that can be deployed and smoke-tested before the client is switched over in the follow-up.

  • BlocksDefaults.provisionApiFrontDoor (boolean) gates the feature: true in the production preset, false in sandbox. A sandbox's dev server is same-origin localhost and a deployed sandbox is disposable, so a stable origin buys nothing there and isn't worth the CloudFront propagation time. Apps that spread a BlocksPresets preset need no change; a hand-written BlocksDefaults literal must add the field.
  • scheduleFrontDoor (in @aws-blocks/core/cdk) registers a one-shot CDK aspect from create(), so the decision is deferred to synth (when the whole app exists). When provisioning is on, the aspect builds one cloudfront.Distribution whose single default behavior proxies the stack's API origin — forwarding cookies + Authorization and disabling caching (the backend is dynamic and auth-bearing) — and emits a FrontDoorUrl output. When off (sandbox / opt-out) it does nothing.
  • The origin is built from the stack's API URL by httpOriginFromApiUrl, the single place the framework turns a Blocks API URL into a CloudFront origin (a follow-up reuses it for Hosting).
  • The distribution and its output are scoped to the owning BlocksStack / BlocksBackend, so several front-door-enabled backends can share one stack without colliding on a logical id.

Testing

Synth unit tests (bb-lambda-compute/src/front-door.cdk.test.ts):

  • production → exactly one distribution + a FrontDoorUrl output, and the client-facing ApiUrl output still points at the API Gateway (nothing routes through the distribution yet); sandbox → none; an explicit provisionApiFrontDoor: false opts a production app out.
  • two front-door-enabled backends in one stack synthesize to two distinct distributions/outputs (guards the per-owner scoping).
  • httpOriginFromApiUrl builds a CloudFront origin from a Blocks API URL.

Build, lint, and affected unit tests pass on Node 22. There is no end-to-end coverage here because nothing routes through the distribution yet — the client switch and its e2e land in the follow-up PR.

Non-breaking: purely additive; single-compute apps keep reaching the API Gateway directly.

@changeset-bot

changeset-bot Bot commented Sep 8, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 464222a

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-lambda-compute Minor
@aws-blocks/blocks 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

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): Provision managed CloudFront API front door (Track D, D2) feat(core): Provision managed CloudFront API front door Sep 8, 2026
@Simone319
Simone319 force-pushed the zimzha/front-door-d2 branch from de1e4e9 to df68b0d Compare September 8, 2026 13:11
Add a managed CloudFront distribution that becomes the stable public origin for
the backend HTTP surface, so adding or scaling a compute never changes the
browser hostname and Secure auth cookies persist. The distribution is
provisioned and its URL published, but the client is not switched to it yet —
an additive, no-traffic-change step that can be deployed and smoke-tested first.

- Gate on a new BlocksDefaults.provisionApiFrontDoor (true in production, false
  in sandbox), with a matching preset field.
- scheduleFrontDoor registers a synth-time CDK aspect that, when provisioning is
  on, builds one Distribution whose single default behavior proxies the stack's
  API origin (cookies + Authorization forwarded, caching off) and emits a
  FrontDoorUrl output. httpOriginFromApiUrl is the single place a Blocks API URL
  becomes a CloudFront origin.
- Scope the distribution and its output under the owning BlocksStack/
  BlocksBackend so several front-door-enabled backends can share one stack
  without colliding on a logical id.

Non-breaking: nothing routes through the distribution yet.
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