Skip to content

feat(cloudflare): Hyperdrive → AWS Aurora example + ref-bindable bindings#645

Draft
sam-goodwin wants to merge 3 commits into
claude/serene-bartik-0d2bcbfrom
claude/cf-hyperdrive-aurora
Draft

feat(cloudflare): Hyperdrive → AWS Aurora example + ref-bindable bindings#645
sam-goodwin wants to merge 3 commits into
claude/serene-bartik-0d2bcbfrom
claude/cf-hyperdrive-aurora

Conversation

@sam-goodwin

Copy link
Copy Markdown
Contributor

Stacked on #640. Adds the Cloudflare → AWS Aurora story: a Worker reaching Aurora through Hyperdrive, with Drizzle migrations applied via the RDS Data API.

Ref-bindable resources (framework)

A Cloudflare Worker can't carry AWS requirements in its init — a deployed Worker has no AWS credentials at runtime — so it can't bind a Hyperdrive whose origin is created from an AWS resource the usual way. The fix lets a Worker bind a resource by reference into another stack, so the AWS side stays in its own stack and the Worker bundle stays Cloudflare-only:

// app stack (Cloudflare only)
const conn = yield* Cloudflare.Hyperdrive.bind(
  Cloudflare.Hyperdrive.ref("AppHyperdrive", { stack: INFRA_STACK }),
);
  • Resource.ts — the host.bind\...`tagged-template resolves aRefExprto itsresourceId` for the binding key.
  • Output.tsRefExpr exposes LogicalId (binding metadata reads it; it was undefined for refs).

Example — examples/cloudflare-aurora-hyperdrive

Two stacks: infra (Aurora + Drizzle.Schema + AWS.RDS.Schema migrations + the Hyperdrive) and app (the Worker binding the Hyperdrive by ref). Deploy infra → app.

Public-firewall path — implemented + live-tested (deploy both stacks → user CRUD over Worker → Hyperdrive → Aurora → destroy, all green; verified via curl). The Hyperdrive's origin is gated on the migration resource so Cloudflare's connect-time validation runs only after the writer is reachable.

Tunnel + Access path — documented + scaffolded (WIP). Keeps Aurora private behind cloudflared (ECS) + a Cloudflare Tunnel + Access. The README documents both paths with security/perf trade-offs.

Status

Draft: the Tunnel + Access path is documented and scaffolded (cloudflared Dockerfile) but not yet implemented/live-tested. The public path and the framework change are complete and validated against real AWS + Cloudflare.

…ings

Cross-cloud story: a Cloudflare Worker reaching AWS RDS Aurora through
Hyperdrive, with Drizzle migrations applied via the RDS Data API.

- Resource binding by ref: a Worker can now bind a resource created in
  another stack/provider via `SomeResource.ref(id, { stack })` — the bind
  tagged-template resolves a RefExpr to its `resourceId`, and `RefExpr`
  exposes `LogicalId`. This keeps AWS requirements/credentials out of the
  Worker (a Worker has no AWS env at runtime), which is what makes a
  Worker→AWS-backed-Hyperdrive binding possible.
- example `cloudflare-aurora-hyperdrive`: infra stack (Aurora + Hyperdrive)
  + app stack (Worker binding the Hyperdrive by ref). Public-firewall path
  is implemented and live-tested end to end (deploy → CRUD over
  Hyperdrive → Aurora → destroy). The Tunnel + Access (private) path is
  documented with trade-offs and scaffolded (cloudflared Dockerfile),
  implementation in progress.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@alchemy-version-bot

alchemy-version-bot Bot commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

Install the packages built from this commit:

alchemy

bun add alchemy@https://pkg.ing/alchemy/60ee787

@alchemy.run/better-auth

bun add @alchemy.run/better-auth@https://pkg.ing/@alchemy.run/better-auth/60ee787

@alchemy.run/pr-package

bun add @alchemy.run/pr-package@https://pkg.ing/@alchemy.run/pr-package/60ee787

sam-goodwin and others added 2 commits June 17, 2026 21:19
cloudflared on ECS Fargate + Cloudflare Tunnel (TCP) + Access (self-hosted
app, Service-Auth policy, service token) fronting a private Aurora cluster,
with Hyperdrive using an Access-protected origin. Adds tunnel-infra/tunnel-app
stacks and a zone-gated tunnel suite to the integ test.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
The Tunnel + Access (private) path now provisions and round-trips CRUD end to
end: Worker → Hyperdrive → Access → Tunnel → cloudflared (ECS) → private Aurora.

- cloudflared on Fargate: pin `runtimePlatform` to the deploy host's arch so
  Fargate can pull the locally-built image (arm64 Macs → Graviton).
- SecurityGroup: allow cloudflared's outbound Tunnel control plane on 7844
  (QUIC/UDP + HTTP2/TCP) — without it the connector never registers.
- Resolve the zone via `findZoneByName` (default `alchemy-test-2.us`) instead of
  requiring a `CLOUDFLARE_ZONE_ID` env var.
- Add `scripts/enable-universal-ssl.ts`: `bun nuke` can leave a test zone with
  Universal SSL "enabled" but zero cert packs (no edge cert), which makes
  Hyperdrive's create-time validation fail with HANDSHAKE_FAILURE_ON_CLIENT_HELLO.
  The script re-orders the universal cert (toggle off→on) and waits for an
  active pack. Documented in the README.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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