Skip to content

feat(core): run an API namespace on its own compute - #948

Merged
Simone319 merged 20 commits into
mainfrom
zimzha/release-compute-api
Oct 26, 2026
Merged

Simone319 merged 20 commits into
mainfrom
zimzha/release-compute-api

Conversation

@Simone319

@Simone319 Simone319 commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Releases per-namespace compute to customers. ApiNamespace takes an optional fourth argument, { compute }:

const reportsCompute = new Compute(scope, 'reports', { type: 'serverless', memory: 4096 });
export const reports = new ApiNamespace(scope, 'reports', (context) => ({ /* methods */ }), { compute: reportsCompute });

The mechanism shipped in #736 (shared gateway fan-out by export name, per-namespace RPC paths), and #944 moved the native clients onto per-namespace paths. This PR adds the public option and wires it into the namespace's compute resolver.

Surface

  • ApiNamespaceOptions.compute is typed structurally ({ resolve(): { readonly type: 'serverless' } }) so core's default entry doesn't pull in CDK types; a Compute block (or a raw backing) satisfies it. A container compute is a type error for now.
  • Resolved lazily, at gateway build time; the option wins over the scope's compute.
  • A compute that belongs to another BlocksBackend can't be routed by this backend's gateway: synth warns (blocks:apigateway:namespace-compute-not-owned, naming the export and the compute) and the namespace runs on the default compute. A compute inherited from the scope (the cached sub-module case) is still skipped silently.
  • Exported from @aws-blocks/core and @aws-blocks/blocks. API.md adds only ApiNamespaceOptions.

Behaviour / limits (full list in the bb-compute README's API namespaces section; JSDoc and the changeset summarise it)

  • Clients are unchanged: the TypeScript client, and the Swift/Kotlin/Dart clients since feat(native): call each API namespace at its own path #944, call POST /aws-blocks/api/{export}, on every front door: apigateway, cloudfront, and behind Hosting.
  • A call to the bare /aws-blocks/api (raw HTTP, or a native client from before feat(native): call each API namespace at its own path #944) runs on the default compute.
  • API calls are capped at ~29 s by the gateway, whatever the compute's maxTimeoutSeconds.
  • Routing follows the export name, not the second constructor argument.
  • Local dev runs every namespace in the dev server.

Tests: one deployed e2e per front door

  • apigateway: test-apps/comprehensive adds isolatedApi on its own Compute (existing E2E Sandbox job).
  • Hosting: test-apps/hosting-spa test 12 calls a namespace through Hosting, on both of its E2E Hosting legs: the CloudFront door, and the ALB door added by feat(hosting): swappable front doors + free-form bring-your-own front door #510 (verified locally, 13/13).
  • cloudfront: the compute suite, test-apps/compute-smoke (E2E Compute Smoke). This PR folds the separate multi-compute app into it, so there's no extra deploy job:
    • Shape: one VPC app with a scenario module per compute kind and workload (container AsyncJobs; an API namespace on its own serverless compute, including the bare-endpoint call and the path/body mismatch). A harness deploys once and runs every module, like comprehensive's e2e.test.ts.
    • Front-door legs: the API front door is a matrix leg (COMPUTE_API_FRONT_DOOR, the way E2E Hosting uses HOSTING_COMPUTE_TYPE). Today there is one leg, cloudfront; the container-API work adds apigateway.
    • Stack names: stacks are now bb-test-compute-*, so the scheduled cleanup and the CI role's E2E prefixes cover them (bb-compute-smoke-* wasn't covered).
    • Name length: the derived FileBucket name was exactly 63 characters with today's CI suffix and would have failed from PR ci(release): publish to npm with trusted publishing (OIDC) from an npm-release environment #1000.
    • Teardown: in CI a failed teardown fails the run. The left-behind destroy runs only after a failure or cancellation, which saves a ~4-minute no-op destroy on every passing run.
  • Unit / synth:
    • api.test.ts: precedence and laziness.
    • shared-gateway.test.ts: the foreign-compute warning, and the silent inherited case.
    • umbrella-compute.test.ts: BlocksStack, BlocksBackend and the cloudfront tier. Covers route by export name, memory, a shared AsyncJob, one API-scoped permission, no other method on the function, and compile-time container rejection.

Verification beyond CI

  • Synth diff: apps that don't use the option are byte-identical to main.
  • Mutation pass: ignoring the option, resolving it eagerly, widening the type, and dropping the foreign-compute warning are each caught.
  • On real AWS: the compute suite's cloudfront leg (6/6), hosting-spa (12/12), and the earlier scratch matrix (66/66 across 6 front doors). Native clients built from feat(native): call each API namespace at its own path #944 were checked against a two-compute deployment from this branch: Swift, Kotlin and Dart all reach reports on its own 512 MB function, and main's clients land on the default one.

Follow-ups (not in this PR)

  • Export ApiNamespaceConstructor so the API report shows its signature (predates this PR; adds a public type).
  • Compute suite, pre-existing: the wall-clock timeout test can pass if the slow worker never picks the job up; the "production" stack-name branch is unreachable; the 60-minute job timeout vs 1-hour credentials is getting tight.

ApiNamespace takes an optional fourth argument, { compute }, that runs the
namespace on a Compute instead of the app default. The namespace's compute
resolver (from #736) now prefers that option over the scope's compute, so the
shared gateway routes /aws-blocks/api/<export name> to it on every front door.
The option is typed structurally (resolve() → a serverless compute), so a
container Compute is a type error and core's default entry carries no CDK types.

E2E, one deploy per front door: comprehensive (apigateway tier, E2E
Sandbox/Production) and hosting-spa (Hosting's distribution) each get a
namespace on its own 512 MB Compute; a new test-apps/multi-compute app and
'E2E Multi-Compute' job cover the managed CloudFront tier.
Docs and changeset spell out the TS-client vs bare-endpoint routing, the
gateway's ~29 s cap and serverless-only support; the umbrella test checks
that no other method integrates the namespace's function; the multi-compute
CI job tears down a left-behind stack.
…ient

The cloudfront e2e calls through the real ApiNamespaceClient; the CI job
assumes the E2E pool role like the other E2E jobs; the app ships its
generated client and telemetry project id like the other test apps.
…e-api

# Conflicts:
#	.github/workflows/pr-checks.yml
@changeset-bot

changeset-bot Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: e9afc4e

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

This PR includes changesets to release 27 packages
Name Type
@aws-blocks/core Minor
@aws-blocks/bb-compute Patch
@aws-blocks/blocks Minor
@aws-blocks/create-blocks-app Patch
@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-secret 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/bb-container-compute 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

…e-api

# Conflicts:
#	test-apps/hosting-spa/aws-blocks/index.ts
#	test-apps/hosting-spa/test/e2e.test.ts
…nt door

#510 added the ALB leg; the comments named only the CloudFront distribution.
osama-rizk
osama-rizk previously approved these changes Oct 26, 2026
This was referenced Oct 28, 2026

This branch was previously deployed

2 inactive deployments
e2e — e9afc4ea Deployed Oct 26, 2026 by Simone319 via E2E Compute Smoke (cloudfront) #4069
agent-bench — e9afc4ea Deployed Oct 26, 2026 by Simone319 via bench / summary #3421
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.

2 participants