[bb-async-job + 2 more] Route event-block resources to their resolved compute - #459
Conversation
🦋 Changeset detectedLatest commit: 330acaa The changes in this PR will be included in the next version bump. This PR includes changesets to release 23 packages
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.
There was a problem hiding this comment.
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.
… 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.
|
Thanks for the thorough pass, @soberm. Addressed the inline findings in f5ba09d; on the three summary items:
|
…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.
…rtCdkConditionActive)
…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.
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
bb-async-job): attach the SQS event source tothis.compute's function (guarded onLambdaCompute) instead of the shared handler; partial-batch-failure options preserved.LambdaComputeguard in this change (none had one before) that throws a typedUnsupportedComputeerror on any other compute type — assertable viaisBlocksErrorand covered by a throw-path test per block.bb-cron-job): resolve the scheduler target fromthis.compute.bb-realtime): wire the shared WebSocket infra fromthis.compute's function.@aws-blocks/bb-lambda-computedependency and imports the CDK-typedLambdaComputevia its new/cdksubpath (no coupling to core internals).{ compute }option is added here — blocks reachthis.compute, which resolves to the default compute for any current app. The customer-facing assignment surface is a later track.Validation
BlocksStack.createharness and assert the event source / target / integration lands on the resolved compute's function (default and ancestor-_computecases).bb-async-job77,bb-cron-job29,bb-realtime72,core729; full build + lint pass.Checklist
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.