Skip to content

[bb-async-job + 2 more] Route event-block resources to their resolved compute - #459

Merged
Simone319 merged 8 commits into
mainfrom
zimzha/multi-compute-c1-c3-event-blocks
Sep 4, 2026
Merged

Simone319 merged 8 commits into
mainfrom
zimzha/multi-compute-c1-c3-event-blocks

Conversation

@Simone319

@Simone319 Simone319 commented Aug 31, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Event Building Blocks (AsyncJob, CronJob, Realtime) wired their native AWS resources — SQS event source, EventBridge scheduler target, WebSocket integration — directly to the stack's shared Lambda handler. For multi-compute, each event block must instead target the compute that owns it, so its resources follow the resolved compute rather than assuming the single default handler.

Changes

  • AsyncJob (bb-async-job): attach the SQS event source to this.compute's function (guarded on LambdaCompute) instead of the shared handler; partial-batch-failure options preserved.
  • Synth guard (new, all three blocks): AsyncJob, CronJob, and Realtime each gain a LambdaCompute guard in this change (none had one before) that throws a typed UnsupportedCompute error on any other compute type — assertable via isBlocksError and covered by a throw-path test per block.
  • CronJob (bb-cron-job): resolve the scheduler target from this.compute.
  • Realtime (bb-realtime): wire the shared WebSocket infra from this.compute's function.
  • Each event block declares a @aws-blocks/bb-lambda-compute dependency and imports the CDK-typed LambdaCompute via its new /cdk subpath (no coupling to core internals).
  • No public { compute } option is added here — blocks reach this.compute, which resolves to the default compute for any current app. The customer-facing assignment surface is a later track.

Validation

  • CDK tests updated to the BlocksStack.create harness and assert the event source / target / integration lands on the resolved compute's function (default and ancestor-_compute cases).
  • Green locally: bb-async-job 77, bb-cron-job 29, bb-realtime 72, core 729; full build + lint pass.

Checklist

  • PR description included
  • Tests are changed or added
  • Relevant documentation is changed or added (changeset event-blocks-compute-targeting.md)

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@changeset-bot

changeset-bot Bot commented Aug 31, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 330acaa

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-async-job Minor
@aws-blocks/bb-cron-job Minor
@aws-blocks/bb-realtime Minor
@aws-blocks/bb-lambda-compute Minor
@aws-blocks/bb-agent Patch
@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-dashboard Patch
@aws-blocks/bb-file-bucket 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

AsyncJob, CronJob, and Realtime attach their compute-bound resources to the
compute resolved via `this.compute` instead of the stack's shared handler:
- AsyncJob attaches its SQS event source to the compute's function;
- CronJob points its EventBridge Scheduler target at the compute's function;
- Realtime wires its shared WebSocket API integrations to the compute's function.

All three require a LambdaCompute today and fail at synth with a clear error on
any other compute type. On the default single-Lambda setup `this.compute`
resolves to the stack's default compute (the shared handler), so this is
non-breaking with no change to synthesized infrastructure. AsyncJob also grants
SQS send to the shared execution role.

bb-agent's CDK test moves onto the BlocksStack.create harness (which initializes
the default compute the blocks now resolve). CronJob's CDK test keeps its
synth-time schedule/timezone validation coverage alongside the compute-targeting
coverage.

@soberm soberm left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code review — the compute-targeting refactor is sound (IAM swap is correct, ./cdk export is well-formed, no circular dependency, dependency placement is right). Most findings are posted inline. Two items that don't anchor to a changed line:

[LOW] Extraneous nested @aws-blocks/core@0.2.0 in package-lock.json (marked "extraneous": true, under bb-agent/node_modules/.../bb-lambda-compute/node_modules/@aws-blocks/core). Hygiene noise, but relevant to instanceof LambdaCompute: if a block ever resolves a different copy of bb-lambda-compute than the default-compute factory used, the guard misfires. ^0.3.0 is consistent across manifests so dedup should hold — please regenerate the lockfile cleanly to drop the extraneous entry.

[LOW] Test-only type assertions (e.g. _defaultCompute as LambdaCompute, defaultChild as cdk.CfnElement) brush against the AGENTS.md no-casts rule. They're narrowing casts (not as any) and test-only, so low severity — a small typed helper would keep them out of the assertion sites.

Minor nit on the PR description: it says AsyncJob "now guards this the same way CronJob and Realtime do" — the diff shows the guard added to all three simultaneously; CronJob/Realtime had no prior guard.

Comment thread packages/bb-async-job/src/index.cdk.ts Outdated
Comment thread packages/bb-async-job/src/index.cdk.ts Outdated
Comment thread packages/bb-cron-job/src/index.cdk.ts Outdated
Comment thread packages/bb-realtime/src/index.cdk.ts Outdated
… sanitized key

Address review on #459:

- bb-async-job: sanitize the BLOCKS_HANDLER_OWNER_ config key identically to
  the adjacent QUEUE_URL key. Config entries are loaded into process.env at
  runtime (loadConfigToProcessEnv), so the key must be a valid env var name and
  the Phase-2 owner-match reader must reconstruct the same string byte-for-byte.
- All three event blocks: throw a typed UnsupportedCompute error from the
  Lambda-compute guard (assertable via isBlocksError) instead of a bare Error,
  matching each block's existing synth-time error taxonomy.
- Add throw-path tests for all three: construct a non-Lambda compute and assert
  the guard throws the typed error (the headline "fail loud at synth" behavior
  was previously uncovered).
- Drop a stale extraneous @aws-blocks/core@0.2.0 entry from package-lock.json.
@Simone319

Copy link
Copy Markdown
Contributor Author

Thanks for the thorough pass, @soberm. Addressed the inline findings in f5ba09d; on the three summary items:

  • Extraneous nested @aws-blocks/core@0.2.0: removed in f5ba09d. It was a stale lockfile-only entry (no backing dir on disk, not required by the tree) that npm install / --package-lock-only wouldn't prune, so I dropped the block and re-validated with npm install --package-lock-only (npm did not re-add it). ^0.3.0 is consistent across manifests, so the dedup holds and the instanceof LambdaCompute guard resolves a single copy.
  • Test-only casts: leaving these. They are test-internal assertions (_defaultCompute is an internal field; CfnElement is CDK-tree introspection), not customer-facing API usage, so they fall under the test-plumbing exception to the no-casts rule rather than the customer-DX surface it protects. Happy to add a small typed helper if you feel strongly.
  • Description wording: the "matches the CronJob / Realtime guards" phrasing was in the AsyncJob code comment (the description didn't actually claim a prior guard); corrected it in 72cb60c, and made the PR description explicit that all three guards are added together in this change.

soberm
soberm previously approved these changes Sep 3, 2026
Comment thread packages/bb-async-job/src/index.cdk.ts Outdated
Comment thread packages/bb-async-job/src/index.cdk.ts
Comment thread packages/bb-async-job/src/index.cdk.ts Outdated
Comment thread packages/bb-async-job/src/index.cdk.ts Outdated
Comment thread packages/bb-cron-job/src/index.cdk.ts Outdated
Comment thread packages/bb-realtime/src/index.cdk.ts Outdated
Comment thread packages/bb-realtime/src/index.cdk.ts
Comment thread packages/bb-async-job/src/index.cdk.test.ts
Comment thread packages/bb-async-job/src/index.cdk.test.ts
Comment thread .changeset/event-blocks-compute-targeting.md Outdated
…ealtime shared-role publish

Address @sarayev review on #459:

- Replace `instanceof LambdaCompute` in all three event-block guards with
  `LambdaCompute.isLambdaCompute()`, backed by a `Symbol.for('blocks:LambdaCompute')`
  brand, so the check survives duplicate bb-lambda-compute copies in one tree
  (where `instanceof` misfires once versions diverge).
- Add a single `blocksError(name, message)` to @aws-blocks/core (exported from
  every entry) and route all three guards through it; bb-async-job/errors.ts and
  bb-realtime/utils.ts re-export it instead of defining their own.
- Add `sanitizeConfigKey(id)` to @aws-blocks/core/bb-utils; use it for both the
  QUEUE_URL and HANDLER_OWNER writers and the runtime reader so writer/reader
  can't drift.
- Realtime: bind the shared WebSocket routes to the stack DEFAULT compute
  deterministically (new @internal Scope.defaultCompute) instead of the block's
  resolved compute, and grant postToConnection to the shared execution role so
  publish() works from any compute — removes the per-stack-singleton divergence.
- Changeset bumped to minor for the added public surface (blocksError,
  sanitizeConfigKey, bb-lambda-compute ./cdk + isLambdaCompute, UnsupportedCompute
  members); regenerated core API report.
…ort from bb-utils

The config module owns the config-key contract, so the key-sanitization rule
lives beside getConfigSync/loadConfigToProcessEnv. bb-utils re-exports it (pure
aggregator pattern) so BB authors still import from @aws-blocks/core/bb-utils.
No behavior or public-surface change.

This branch was previously deployed

1 inactive deployment
publish — 330acaab Deployed Sep 4, 2026 by Simone319 via E2E Hosting (spa) #1796
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.

3 participants