@aws-blocks/core 0.4.0 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (90) hide show
  1. package/README.md +12 -0
  2. package/dist/cdk/blocks-backend.d.ts +4 -1
  3. package/dist/cdk/blocks-backend.d.ts.map +1 -1
  4. package/dist/cdk/blocks-backend.js +56 -10
  5. package/dist/cdk/blocks-backend.test.js +71 -1
  6. package/dist/cdk/blocks-defaults.d.ts +11 -0
  7. package/dist/cdk/blocks-defaults.d.ts.map +1 -1
  8. package/dist/cdk/blocks-stack.test.js +23 -3
  9. package/dist/cdk/compute/compute.d.ts +80 -2
  10. package/dist/cdk/compute/compute.d.ts.map +1 -1
  11. package/dist/cdk/compute/compute.js +57 -3
  12. package/dist/cdk/config-registry.test.js +12 -0
  13. package/dist/cdk/dashboard-registry.d.ts +41 -0
  14. package/dist/cdk/dashboard-registry.d.ts.map +1 -0
  15. package/dist/cdk/dashboard-registry.js +61 -0
  16. package/dist/cdk/index.d.ts +67 -11
  17. package/dist/cdk/index.d.ts.map +1 -1
  18. package/dist/cdk/index.js +100 -18
  19. package/dist/cdk/internal.d.ts +3 -1
  20. package/dist/cdk/internal.d.ts.map +1 -1
  21. package/dist/cdk/internal.js +4 -1
  22. package/dist/cdk/tracer-registry.d.ts +31 -0
  23. package/dist/cdk/tracer-registry.d.ts.map +1 -0
  24. package/dist/cdk/tracer-registry.js +49 -0
  25. package/dist/cdk/vpc-requirements-registry.d.ts +33 -0
  26. package/dist/cdk/vpc-requirements-registry.d.ts.map +1 -0
  27. package/dist/cdk/vpc-requirements-registry.js +46 -0
  28. package/dist/cdk/vpc-types.d.ts +151 -0
  29. package/dist/cdk/vpc-types.d.ts.map +1 -0
  30. package/dist/cdk/vpc-types.js +3 -0
  31. package/dist/cdk/vpc.d.ts +59 -0
  32. package/dist/cdk/vpc.d.ts.map +1 -0
  33. package/dist/cdk/vpc.js +298 -0
  34. package/dist/cdk/vpc.test.d.ts +2 -0
  35. package/dist/cdk/vpc.test.d.ts.map +1 -0
  36. package/dist/cdk/vpc.test.js +285 -0
  37. package/dist/errors.d.ts +5 -0
  38. package/dist/errors.d.ts.map +1 -1
  39. package/dist/errors.js +5 -0
  40. package/dist/hosting.d.ts.map +1 -1
  41. package/dist/hosting.js +2 -0
  42. package/dist/hosting.test.js +39 -1
  43. package/dist/index.cdk.d.ts +2 -1
  44. package/dist/index.cdk.d.ts.map +1 -1
  45. package/dist/index.cdk.js +1 -1
  46. package/dist/lambda-handler.js +9 -2
  47. package/dist/lambda-handler.test.js +61 -1
  48. package/dist/raw-route.d.ts +15 -1
  49. package/dist/raw-route.d.ts.map +1 -1
  50. package/dist/raw-route.js +96 -12
  51. package/dist/raw-route.test.js +332 -1
  52. package/dist/scripts/dev-server.d.ts.map +1 -1
  53. package/dist/scripts/dev-server.js +11 -0
  54. package/dist/scripts/extract-ts-types.d.ts.map +1 -1
  55. package/dist/scripts/extract-ts-types.js +107 -23
  56. package/dist/scripts/extract-ts-types.test.js +225 -26
  57. package/dist/scripts/generate-spec.d.ts.map +1 -1
  58. package/dist/scripts/generate-spec.js +14 -5
  59. package/dist/scripts/generate-spec.test.js +93 -0
  60. package/dist/version.d.ts +1 -1
  61. package/dist/version.js +1 -1
  62. package/package.json +8 -1
  63. package/src/cdk/blocks-backend.test.ts +144 -60
  64. package/src/cdk/blocks-backend.ts +298 -239
  65. package/src/cdk/blocks-defaults.ts +12 -0
  66. package/src/cdk/blocks-stack.test.ts +32 -13
  67. package/src/cdk/compute/compute.ts +105 -3
  68. package/src/cdk/config-registry.test.ts +14 -0
  69. package/src/cdk/dashboard-registry.ts +68 -0
  70. package/src/cdk/index.ts +426 -298
  71. package/src/cdk/internal.ts +6 -2
  72. package/src/cdk/tracer-registry.ts +54 -0
  73. package/src/cdk/vpc-requirements-registry.ts +63 -0
  74. package/src/cdk/vpc-types.ts +158 -0
  75. package/src/cdk/vpc.test.ts +348 -0
  76. package/src/cdk/vpc.ts +336 -0
  77. package/src/errors.ts +5 -0
  78. package/src/hosting.test.ts +59 -1
  79. package/src/hosting.ts +3 -0
  80. package/src/index.cdk.ts +7 -0
  81. package/src/lambda-handler.test.ts +79 -1
  82. package/src/lambda-handler.ts +11 -2
  83. package/src/raw-route.test.ts +427 -1
  84. package/src/raw-route.ts +125 -12
  85. package/src/scripts/dev-server.ts +12 -1
  86. package/src/scripts/extract-ts-types.test.ts +228 -26
  87. package/src/scripts/extract-ts-types.ts +104 -20
  88. package/src/scripts/generate-spec.test.ts +101 -0
  89. package/src/scripts/generate-spec.ts +15 -5
  90. package/src/version.ts +1 -1
@@ -0,0 +1,61 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ import * as cdk from 'aws-cdk-lib';
4
+ const REGISTRY_KEY = Symbol.for('BLOCKS_DASHBOARD_REGISTRY');
5
+ /**
6
+ * Get or create the deferred-dashboard list for a given stack. Stored on the
7
+ * stack object (keyed by a Symbol), so each stack in a multi-stack synth gets
8
+ * its own — mirrors the config + compute registries.
9
+ */
10
+ function getRegistry(stack) {
11
+ let list = stack[REGISTRY_KEY];
12
+ if (!list) {
13
+ list = [];
14
+ stack[REGISTRY_KEY] = list;
15
+ }
16
+ return list;
17
+ }
18
+ /**
19
+ * Register a Dashboard's deferred body-build, to run after every Building Block
20
+ * in the app has been constructed (the end of `BlocksStack`/`BlocksBackend`
21
+ * `create()`, once the backend module has fully imported).
22
+ *
23
+ * The Dashboard builds its widget body here rather than in its constructor
24
+ * because the body depends on which computes are traced, and a `Tracer` may be
25
+ * constructed *after* the Dashboard. Deferring makes the Dashboard observe the
26
+ * complete app, so it never depends on construction order. (The Dashboard's
27
+ * CloudWatch resource itself is created eagerly in the constructor, so its URL /
28
+ * redirect route never dangle — only the body is deferred.)
29
+ *
30
+ * This is intentionally scoped to the Dashboard (the only deferred-build case
31
+ * today) rather than a generic finalizer mechanism; generalize it only if a
32
+ * second use case appears.
33
+ *
34
+ * @param scope - Any construct in the stack (used to locate the stack).
35
+ * @param finalize - The deferred body-build; run once (in registration order)
36
+ * by {@link finalizeDashboards}.
37
+ */
38
+ export function registerDashboardFinalizer(scope, finalize) {
39
+ getRegistry(cdk.Stack.of(scope)).push(finalize);
40
+ }
41
+ /**
42
+ * Run — and clear — every registered Dashboard finalizer on `scope`'s stack, in
43
+ * registration order. Called once from `create()` after the backend module has
44
+ * imported. Clearing the list makes a repeated call a no-op, so a dashboard's
45
+ * body is never built twice.
46
+ *
47
+ * A Dashboard constructed outside `create()` (e.g. directly in a unit test) must
48
+ * call this explicitly before synth — the same way `config-registry.test.ts`
49
+ * drives `finalizeConfigRegistry`. (A Dashboard's CloudWatch resource is created
50
+ * eagerly in its constructor, so even if its finalizer never runs its URL /
51
+ * redirect never dangle — only the widget body is missing.)
52
+ *
53
+ * @param scope - Any construct in the stack (used to locate the stack).
54
+ */
55
+ export function finalizeDashboards(scope) {
56
+ const list = getRegistry(cdk.Stack.of(scope));
57
+ // Drain the list so a repeated call can't rebuild an already-built dashboard.
58
+ const pending = list.splice(0, list.length);
59
+ for (const finalize of pending)
60
+ finalize();
61
+ }
@@ -1,19 +1,24 @@
1
1
  import * as cdk from 'aws-cdk-lib';
2
2
  import { Construct } from 'constructs';
3
- import { type BlocksStackProps, type BlocksStack as BaseBlocksStack, type ScopeParent, type ScopeOptions } from '../common/index.js';
3
+ import { type BlocksStack as BaseBlocksStack, type BlocksStackProps, type ScopeOptions, type ScopeParent } from '../common/index.js';
4
4
  import { type BlocksDefaults } from './blocks-defaults.js';
5
5
  import type { Compute } from './compute/compute.js';
6
6
  import type { DefaultComputeFactory } from './compute/default-compute-factory.js';
7
+ import type { VpcRequirements } from './vpc-types.js';
8
+ export { ApiError, DEFAULT_API_ERROR_NAME, hasAuthError, isBlocksError } from '../errors.js';
9
+ export type { ScopeOptions } from '../index.js';
10
+ export { ensureApiGatewayAccount } from './apigateway-account.js';
7
11
  export { BlocksBackend, type BlocksBackendProps, type CoreBlocksBackendProps, SHARED_HANDLER_TIMEOUT_SECONDS, } from './blocks-backend.js';
8
- export { DEFAULT_NODE_RUNTIME } from './node-version.js';
12
+ export { type BlocksDefaults, BlocksPresets, type BlocksThrottling, } from './blocks-defaults.js';
9
13
  export { blocksNodejsBundling } from './bundling.js';
14
+ export { finalizeConfigRegistry, getConfigLocation, registerConfig } from './config-registry.js';
15
+ export { finalizeDashboards, registerDashboardFinalizer } from './dashboard-registry.js';
10
16
  export { SandboxDisableDeletionProtection } from './mixins.js';
11
- export { registerConfig, finalizeConfigRegistry, getConfigLocation } from './config-registry.js';
12
- export { ensureApiGatewayAccount } from './apigateway-account.js';
13
- export { type BlocksDefaults, type BlocksThrottling, BlocksPresets, } from './blocks-defaults.js';
17
+ export { DEFAULT_NODE_RUNTIME } from './node-version.js';
14
18
  export { synthGuard } from './synth-guard.js';
15
- export type { ScopeOptions } from '../index.js';
16
- export { ApiError, isBlocksError, hasAuthError, DEFAULT_API_ERROR_NAME } from '../errors.js';
19
+ export { finalizeTracing, registerTracer } from './tracer-registry.js';
20
+ export { getVpcContext } from './vpc.js';
21
+ export type { BlocksVpcOptions, SubnetRole, VpcContext, VpcRequirements } from './vpc-types.js';
17
22
  /**
18
23
  * Core's `create()` props: the public {@link BlocksStackProps} plus the required
19
24
  * `defaultComputeFactory`. The umbrella (`@aws-blocks/blocks`) supplies the
@@ -50,9 +55,12 @@ export declare class BlocksStack extends cdk.Stack implements BaseBlocksStack {
50
55
  get gateway(): cdk.aws_apigateway.RestApi;
51
56
  /** The default compute's RPC endpoint URL. To be removed once consumers move to the multi-compute model. */
52
57
  get apiUrl(): string;
53
- /** The default compute's handler CloudWatch log group. `bb-logger` reconfigures its retention. */
58
+ /** The default compute's handler CloudWatch log group. Its retention comes from
59
+ * the compute's `logRetention` (falling back to `defaults.logRetention`); the
60
+ * `bb-logger` CDK construct is a no-op and no longer touches it. */
54
61
  get handlerLogGroup(): cdk.aws_logs.ILogGroup;
55
62
  private requireDefaultCompute;
63
+ private _vpcOptions?;
56
64
  private constructor();
57
65
  static create(scope: Construct, id: string, props: CoreBlocksStackProps): Promise<BlocksStack>;
58
66
  }
@@ -129,9 +137,9 @@ export declare class Scope extends Construct {
129
137
  /**
130
138
  * The shared handler Lambda's CloudWatch log group (the default compute's).
131
139
  * Resolves the same way as {@link handler} — via the owning
132
- * BlocksStack/BlocksBackend. `bb-logger` uses this to reconfigure retention on
133
- * the single, framework-owned group rather than creating a second one that
134
- * would collide on the log-group name.
140
+ * BlocksStack/BlocksBackend. Its retention comes from the compute's
141
+ * `logRetention` (falling back to `defaults.logRetention`); the `bb-logger`
142
+ * CDK construct is a no-op and no longer reconfigures it.
135
143
  */
136
144
  get handlerLogGroup(): cdk.aws_logs.ILogGroup;
137
145
  get fullId(): string;
@@ -153,4 +161,52 @@ export declare class Scope extends Construct {
153
161
  get clientMiddleware(): readonly string[];
154
162
  get devAttachments(): readonly string[];
155
163
  }
164
+ /**
165
+ * A VPC-requirements provider: either the requirements directly, or a callback
166
+ * that returns them. Use the callback form when the value depends on `fullId`
167
+ * or other post-construction state — it is evaluated by the base constructor
168
+ * *after* `super()` runs, so `this` is fully available.
169
+ */
170
+ export type VpcRequirementsProvider = VpcRequirements | (() => VpcRequirements);
171
+ /**
172
+ * Constructor options for a {@link BuildingBlockScope} — the {@link ScopeOptions}
173
+ * every Scope takes, plus the block's VPC requirements. `vpc` is **required** so
174
+ * a BB author can't silently omit it; pass `{}` when the block needs nothing
175
+ * VPC-specific.
176
+ */
177
+ export interface BuildingBlockScopeOptions extends ScopeOptions {
178
+ /**
179
+ * What this block needs from the VPC — endpoints, runtime egress, whether it
180
+ * requires a VPC at all. A value, or a callback (evaluated after `super()`,
181
+ * so it may read `this.fullId`). See {@link VpcRequirements}.
182
+ */
183
+ vpc: VpcRequirementsProvider;
184
+ }
185
+ /**
186
+ * Base class for Building Block CDK constructs.
187
+ *
188
+ * BBs extend this instead of `Scope` directly and **must** declare their VPC
189
+ * requirements as a constructor argument — the base registers them centrally
190
+ * (see `vpc-requirements-registry.ts`) so `finalizeVpc` can pull, deduplicate,
191
+ * and provision endpoints, and so the lazy VPC can answer "does anything here
192
+ * need a VPC?". Passing the requirements is required by the constructor
193
+ * signature, so a BB author cannot silently forget to declare them — the same
194
+ * forcing the previous `abstract getVpcRequirements()` gave, but without a
195
+ * standing method on every subclass.
196
+ *
197
+ * Declare `{}` when the BB needs nothing VPC-specific.
198
+ *
199
+ * @example
200
+ * ```ts
201
+ * export class KVStore extends BuildingBlockScope {
202
+ * constructor(scope: ScopeParent, id: string) {
203
+ * super(id, { parent: scope, vpc: { gatewayEndpoints: [ec2.GatewayVpcEndpointAwsService.DYNAMODB] } });
204
+ * // …
205
+ * }
206
+ * }
207
+ * ```
208
+ */
209
+ export declare class BuildingBlockScope extends Scope {
210
+ constructor(id: string, options: BuildingBlockScopeOptions);
211
+ }
156
212
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/cdk/index.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,GAAG,MAAM,aAAa,CAAC;AACnC,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAGvC,OAAO,EACL,KAAK,gBAAgB,EACrB,KAAK,WAAW,IAAI,eAAe,EACnC,KAAK,WAAW,EAChB,KAAK,YAAY,EAElB,MAAM,oBAAoB,CAAC;AAI5B,OAAO,EAAE,KAAK,cAAc,EAAiB,MAAM,sBAAsB,CAAC;AAC1E,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAEpD,OAAO,KAAK,EAAE,qBAAqB,EAAuB,MAAM,sCAAsC,CAAC;AAEvG,OAAO,EACN,aAAa,EACb,KAAK,kBAAkB,EACvB,KAAK,sBAAsB,EAC3B,8BAA8B,GAC9B,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AACzD,O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AAC,iBAAiB,EAAE,MAAM,GAAG,IAAI;IACzD,qBAAqB,CAAC,iBAAiB,EAAE,MAAM,GAAG,IAAI;IACtD,0BAA0B,CACzB,YAAY,EAAE,MAAM,EACpB,WAAW,EAAE,MAAM,EACnB,QAAQ,EAAE,CAAC,MAAM,EAAE,GAAG,KAAK,OAAO,CAAC,IAAI,CAAC,GACtC,IAAI;IACP,IAAI,gBAAgB,IAAI,SAAS,MAAM,EAAE,CAExC;IACD,IAAI,cAAc,IAAI,SAAS,MAAM,EAAE,CAEtC;CACD;AAED;;;;;GAKG;AACH,MAAM,MAAM,uBAAuB,GAAG,eAAe,GAAG,CAAC,MAAM,eAAe,CAAC,CAAC;AAEhF;;;;;GAKG;AACH,MAAM,WAAW,yBAA0B,SAAQ,YAAY;IAC9D;;;;OAIG;IACH,GAAG,EAAE,uBAAuB,CAAC;CAC7B;AAED;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,qBAAa,kBAAmB,SAAQ,KAAK;gBAChC,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,yBAAyB;CAU1D"}
package/dist/cdk/index.js CHANGED
@@ -1,24 +1,31 @@
1
1
  // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
2
  // SPDX-License-Identifier: Apache-2.0
3
- import * as cdk from 'aws-cdk-lib';
4
- import { Construct } from 'constructs';
5
3
  import { pathToFileURL } from 'node:url';
6
4
  import { __PIPELINE_STAGE_SCOPE__ } from '@aws-blocks/pipeline';
5
+ import * as cdk from 'aws-cdk-lib';
6
+ import { Construct } from 'constructs';
7
7
  import { computeScopeFullId, } from '../common/index.js';
8
- import { setupBlocksInfra, BlocksBackend, assertCdkConditionActive } from './blocks-backend.js';
9
- import { addBlocksStackMetadata } from './stack-metadata.js';
10
- import { finalizeConfigRegistry } from './config-registry.js';
8
+ import { assertCdkConditionActive, BlocksBackend, setupBlocksInfra } from './blocks-backend.js';
11
9
  import { BlocksPresets } from './blocks-defaults.js';
12
10
  import { getComputes } from './compute/compute-registry.js';
11
+ import { finalizeConfigRegistry } from './config-registry.js';
12
+ import { finalizeDashboards } from './dashboard-registry.js';
13
+ import { addBlocksStackMetadata } from './stack-metadata.js';
14
+ import { finalizeTracing } from './tracer-registry.js';
15
+ import { anyRequirementNeedsVpc, finalizeVpc, getOrCreateVpc, initializeVpc } from './vpc.js';
16
+ import { registerVpcRequirements } from './vpc-requirements-registry.js';
17
+ export { ApiError, DEFAULT_API_ERROR_NAME, hasAuthError, isBlocksError } from '../errors.js';
18
+ export { ensureApiGatewayAccount } from './apigateway-account.js';
13
19
  export { BlocksBackend, SHARED_HANDLER_TIMEOUT_SECONDS, } from './blocks-backend.js';
14
- export { DEFAULT_NODE_RUNTIME } from './node-version.js';
20
+ export { BlocksPresets, } from './blocks-defaults.js';
15
21
  export { blocksNodejsBundling } from './bundling.js';
22
+ export { finalizeConfigRegistry, getConfigLocation, registerConfig } from './config-registry.js';
23
+ export { finalizeDashboards, registerDashboardFinalizer } from './dashboard-registry.js';
16
24
  export { SandboxDisableDeletionProtection } from './mixins.js';
17
- export { registerConfig, finalizeConfigRegistry, getConfigLocation } from './config-registry.js';
18
- export { ensureApiGatewayAccount } from './apigateway-account.js';
19
- export { BlocksPresets, } from './blocks-defaults.js';
25
+ export { DEFAULT_NODE_RUNTIME } from './node-version.js';
20
26
  export { synthGuard } from './synth-guard.js';
21
- export { ApiError, isBlocksError, hasAuthError, DEFAULT_API_ERROR_NAME } from '../errors.js';
27
+ export { finalizeTracing, registerTracer } from './tracer-registry.js';
28
+ export { getVpcContext } from './vpc.js';
22
29
  export class BlocksStack extends cdk.Stack {
23
30
  id;
24
31
  backendHandlerPath;
@@ -46,7 +53,9 @@ export class BlocksStack extends cdk.Stack {
46
53
  get apiUrl() {
47
54
  return this.requireDefaultCompute().apiUrl;
48
55
  }
49
- /** The default compute's handler CloudWatch log group. `bb-logger` reconfigures its retention. */
56
+ /** The default compute's handler CloudWatch log group. Its retention comes from
57
+ * the compute's `logRetention` (falling back to `defaults.logRetention`); the
58
+ * `bb-logger` CDK construct is a no-op and no longer touches it. */
50
59
  get handlerLogGroup() {
51
60
  return this.requireDefaultCompute().logGroup;
52
61
  }
@@ -56,14 +65,23 @@ export class BlocksStack extends cdk.Stack {
56
65
  }
57
66
  return this._defaultCompute;
58
67
  }
68
+ _vpcOptions;
59
69
  constructor(scope, id, props) {
60
70
  super(scope, id, props);
61
71
  this.id = id;
62
72
  this.backendHandlerPath = props.backendHandlerPath;
63
- this.defaults = props.defaults;
64
73
  this.backendModulePath = props.backendCDKPath;
74
+ this.defaults = props.defaults;
75
+ this._vpcOptions = props.defaults.vpc;
65
76
  // Set globalThis so Building Blocks attach directly to this stack
66
77
  globalThis.CURRENT_BLOCKS_STACK = this;
78
+ // Initialize VPC context before the default compute is created and before
79
+ // BBs are constructed, so both can discover it: the default compute
80
+ // (LambdaCompute) reads it via getVpcContext(this) to place its function in
81
+ // the VPC, and BBs (e.g. bb-data) read it to co-locate their resources.
82
+ if (this._vpcOptions) {
83
+ initializeVpc(this, this._vpcOptions);
84
+ }
67
85
  const infra = setupBlocksInfra(this, props, id);
68
86
  this.executionRole = infra.executionRole;
69
87
  }
@@ -95,6 +113,29 @@ export class BlocksStack extends cdk.Stack {
95
113
  }
96
114
  // Finalize BB config → S3 (after all BBs have registered their config)
97
115
  finalizeConfigRegistry(stack, stack.executionRole, getComputes(stack));
116
+ // Tracing is presence-gated: if the app contains a Tracer, enable X-Ray on
117
+ // every compute. Runs before the dashboard finalize so tracingEnabled is
118
+ // set when the dashboard reads it.
119
+ finalizeTracing(stack, stack.executionRole);
120
+ // Build any deferred Dashboards now that every compute's observability
121
+ // state is settled — so the dashboard is order-independent.
122
+ finalizeDashboards(stack);
123
+ // Finalize VPC. A VPC is a derived resource: use the customer's if they
124
+ // brought one, else lazily create one only if a Building Block genuinely
125
+ // requires it (requiresVpc). Most apps need neither — Lambda reaches AWS
126
+ // services from the managed network without a VPC.
127
+ if (stack._vpcOptions) {
128
+ finalizeVpc(stack, stack._vpcOptions);
129
+ }
130
+ else if (anyRequirementNeedsVpc(stack)) {
131
+ const derived = getOrCreateVpc(stack);
132
+ const options = { network: derived };
133
+ initializeVpc(stack, options);
134
+ finalizeVpc(stack, options);
135
+ cdk.Annotations.of(stack).addInfoV2('blocks:vpc:derived', 'A Building Block required a VPC and none was provided, so Blocks created one ' +
136
+ '(with a NAT gateway, which has an ongoing cost). Pass `defaults.vpc: { network }` to ' +
137
+ 'BlocksStack.create to bring your own. See packages/blocks/VPC.md.');
138
+ }
98
139
  new cdk.CfnOutput(stack, 'ApiUrl', { value: stack.apiUrl });
99
140
  addBlocksStackMetadata(stack);
100
141
  return stack;
@@ -220,9 +261,9 @@ export class Scope extends Construct {
220
261
  /**
221
262
  * The shared handler Lambda's CloudWatch log group (the default compute's).
222
263
  * Resolves the same way as {@link handler} — via the owning
223
- * BlocksStack/BlocksBackend. `bb-logger` uses this to reconfigure retention on
224
- * the single, framework-owned group rather than creating a second one that
225
- * would collide on the log-group name.
264
+ * BlocksStack/BlocksBackend. Its retention comes from the compute's
265
+ * `logRetention` (falling back to `defaults.logRetention`); the `bb-logger`
266
+ * CDK construct is a no-op and no longer reconfigures it.
226
267
  */
227
268
  get handlerLogGroup() {
228
269
  return this.root.handlerLogGroup;
@@ -252,7 +293,8 @@ export class Scope extends Construct {
252
293
  return current.defaults;
253
294
  }
254
295
  }
255
- const ambient = globalThis.CURRENT_BLOCKS_STACK?.defaults;
296
+ const ambient = globalThis.CURRENT_BLOCKS_STACK
297
+ ?.defaults;
256
298
  if (ambient)
257
299
  return ambient;
258
300
  // No owning BlocksStack/BlocksBackend in the tree and none ambient — this is
@@ -270,6 +312,46 @@ export class Scope extends Construct {
270
312
  registerClientMiddleware(_packageSpecifier) { }
271
313
  registerDevAttachment(_packageSpecifier) { }
272
314
  registerLambdaEventHandler(_eventSource, _identifier, _handler) { }
273
- get clientMiddleware() { return []; }
274
- get devAttachments() { return []; }
315
+ get clientMiddleware() {
316
+ return [];
317
+ }
318
+ get devAttachments() {
319
+ return [];
320
+ }
321
+ }
322
+ /**
323
+ * Base class for Building Block CDK constructs.
324
+ *
325
+ * BBs extend this instead of `Scope` directly and **must** declare their VPC
326
+ * requirements as a constructor argument — the base registers them centrally
327
+ * (see `vpc-requirements-registry.ts`) so `finalizeVpc` can pull, deduplicate,
328
+ * and provision endpoints, and so the lazy VPC can answer "does anything here
329
+ * need a VPC?". Passing the requirements is required by the constructor
330
+ * signature, so a BB author cannot silently forget to declare them — the same
331
+ * forcing the previous `abstract getVpcRequirements()` gave, but without a
332
+ * standing method on every subclass.
333
+ *
334
+ * Declare `{}` when the BB needs nothing VPC-specific.
335
+ *
336
+ * @example
337
+ * ```ts
338
+ * export class KVStore extends BuildingBlockScope {
339
+ * constructor(scope: ScopeParent, id: string) {
340
+ * super(id, { parent: scope, vpc: { gatewayEndpoints: [ec2.GatewayVpcEndpointAwsService.DYNAMODB] } });
341
+ * // …
342
+ * }
343
+ * }
344
+ * ```
345
+ */
346
+ export class BuildingBlockScope extends Scope {
347
+ constructor(id, options) {
348
+ const { vpc, ...scopeOptions } = options;
349
+ super(id, scopeOptions);
350
+ // Resolve the provider (callback form is evaluated here, after super(), so
351
+ // values that depend on this.fullId are available) and self-register on the
352
+ // owning stack. Register even when empty so the registry is a faithful
353
+ // census of every BB — the lazy VPC and finalizeVpc both rely on that.
354
+ const requirements = typeof vpc === 'function' ? vpc() : vpc;
355
+ registerVpcRequirements(this, requirements);
356
+ }
275
357
  }
@@ -19,7 +19,9 @@
19
19
  *
20
20
  * @internal
21
21
  */
22
+ export { BLOCKS_NAMESPACE } from '../constants.js';
23
+ export type { ComputeDashboardSection } from './compute/compute.js';
22
24
  export { Compute } from './compute/compute.js';
25
+ export { getComputes } from './compute/compute-registry.js';
23
26
  export type { DefaultComputeFactory } from './compute/default-compute-factory.js';
24
- export { BLOCKS_NAMESPACE } from '../constants.js';
25
27
  //# sourceMappingURL=internal.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"internal.d.ts","sourceRoot":"","sources":["../../src/cdk/internal.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAC/C,YAAY,EAAE,qBAAqB,EAAE,MAAM,sCAAsC,CAAC;AAGlF,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC"}
1
+ {"version":3,"file":"internal.d.ts","sourceRoot":"","sources":["../../src/cdk/internal.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;;;;;;;;;;;GAoBG;AAIH,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AACnD,YAAY,EAAE,uBAAuB,EAAE,MAAM,sBAAsB,CAAC;AACpE,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAG/C,OAAO,EAAE,WAAW,EAAE,MAAM,+BAA+B,CAAC;AAC5D,YAAY,EAAE,qBAAqB,EAAE,MAAM,sCAAsC,CAAC"}
@@ -21,7 +21,10 @@
21
21
  *
22
22
  * @internal
23
23
  */
24
- export { Compute } from './compute/compute.js';
25
24
  // Reserved `/aws-blocks` path segment, needed by concrete computes (e.g.
26
25
  // LambdaCompute in @aws-blocks/bb-lambda-compute) to build their API route tree.
27
26
  export { BLOCKS_NAMESPACE } from '../constants.js';
27
+ export { Compute } from './compute/compute.js';
28
+ // Enumerate the computes registered on a stack — the Dashboard BB's default
29
+ // compute selection resolves through this at finalize.
30
+ export { getComputes } from './compute/compute-registry.js';
@@ -0,0 +1,31 @@
1
+ import { type IRole } from 'aws-cdk-lib/aws-iam';
2
+ import type { Construct } from 'constructs';
3
+ /**
4
+ * Mark that the app contains a `Tracer`. Tracing is **presence-gated**: a Tracer
5
+ * anywhere in the app means every compute should be traced (X-Ray provisions
6
+ * real, costed infra, so it's off unless the app opts in by creating a Tracer).
7
+ * Multiple Tracers are fine — this just records the boolean. Stored per stack
8
+ * (keyed by a Symbol), like the config/compute registries.
9
+ *
10
+ * @param scope - Any construct in the stack (used to locate the stack).
11
+ */
12
+ export declare function registerTracer(scope: Construct): void;
13
+ /**
14
+ * If the app contains a `Tracer`, enable tracing on **every** compute in the
15
+ * stack and grant X-Ray publish **once** on the shared execution role. Runs at
16
+ * the end of `create()` (after the backend module has imported, so all computes
17
+ * are registered). `Compute.enableTracing()` is idempotent, so this is safe
18
+ * regardless of how many Tracers exist.
19
+ *
20
+ * The IAM grant lives here — at the framework level, once on the shared role —
21
+ * rather than in each compute's `applyTracing()`: every compute assumes the same
22
+ * execution role, so a per-compute grant would add N identical statements. The
23
+ * compute only flips its own tracing mode (e.g. Lambda `TracingConfig: Active`);
24
+ * the permission to publish segments is a single stack-level concern.
25
+ *
26
+ * @param scope - Any construct in the stack (used to locate the stack + computes).
27
+ * @param executionRole - The shared execution role every compute assumes; granted
28
+ * X-Ray publish once when tracing is enabled.
29
+ */
30
+ export declare function finalizeTracing(scope: Construct, executionRole: IRole): void;
31
+ //# sourceMappingURL=tracer-registry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tracer-registry.d.ts","sourceRoot":"","sources":["../../src/cdk/tracer-registry.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,KAAK,KAAK,EAAmB,MAAM,qBAAqB,CAAC;AAClE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAK5C;;;;;;;;GAQG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,SAAS,GAAG,IAAI,CAErD;AAMD;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,SAAS,EAAE,aAAa,EAAE,KAAK,GAAG,IAAI,CAU5E"}
@@ -0,0 +1,49 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ import * as cdk from 'aws-cdk-lib';
4
+ import { PolicyStatement } from 'aws-cdk-lib/aws-iam';
5
+ import { getComputes } from './compute/compute-registry.js';
6
+ const REGISTRY_KEY = Symbol.for('BLOCKS_TRACER_PRESENCE');
7
+ /**
8
+ * Mark that the app contains a `Tracer`. Tracing is **presence-gated**: a Tracer
9
+ * anywhere in the app means every compute should be traced (X-Ray provisions
10
+ * real, costed infra, so it's off unless the app opts in by creating a Tracer).
11
+ * Multiple Tracers are fine — this just records the boolean. Stored per stack
12
+ * (keyed by a Symbol), like the config/compute registries.
13
+ *
14
+ * @param scope - Any construct in the stack (used to locate the stack).
15
+ */
16
+ export function registerTracer(scope) {
17
+ cdk.Stack.of(scope)[REGISTRY_KEY] = true;
18
+ }
19
+ function hasTracer(stack) {
20
+ return stack[REGISTRY_KEY] === true;
21
+ }
22
+ /**
23
+ * If the app contains a `Tracer`, enable tracing on **every** compute in the
24
+ * stack and grant X-Ray publish **once** on the shared execution role. Runs at
25
+ * the end of `create()` (after the backend module has imported, so all computes
26
+ * are registered). `Compute.enableTracing()` is idempotent, so this is safe
27
+ * regardless of how many Tracers exist.
28
+ *
29
+ * The IAM grant lives here — at the framework level, once on the shared role —
30
+ * rather than in each compute's `applyTracing()`: every compute assumes the same
31
+ * execution role, so a per-compute grant would add N identical statements. The
32
+ * compute only flips its own tracing mode (e.g. Lambda `TracingConfig: Active`);
33
+ * the permission to publish segments is a single stack-level concern.
34
+ *
35
+ * @param scope - Any construct in the stack (used to locate the stack + computes).
36
+ * @param executionRole - The shared execution role every compute assumes; granted
37
+ * X-Ray publish once when tracing is enabled.
38
+ */
39
+ export function finalizeTracing(scope, executionRole) {
40
+ if (!hasTracer(cdk.Stack.of(scope)))
41
+ return;
42
+ for (const compute of getComputes(scope))
43
+ compute.enableTracing();
44
+ // One grant on the shared role rather than one per traced compute.
45
+ executionRole.addToPrincipalPolicy(new PolicyStatement({
46
+ actions: ['xray:PutTraceSegments', 'xray:PutTelemetryRecords'],
47
+ resources: ['*'],
48
+ }));
49
+ }
@@ -0,0 +1,33 @@
1
+ import * as cdk from 'aws-cdk-lib';
2
+ import type { Construct } from 'constructs';
3
+ import type { VpcRequirements } from './vpc-types.js';
4
+ /** A registered requirement plus the fullId of the BB that declared it (for errors). */
5
+ export interface RegisteredVpcRequirement {
6
+ readonly fullId: string;
7
+ readonly requirements: VpcRequirements;
8
+ }
9
+ /**
10
+ * Register a Building Block's VPC requirements on its owning stack. Called from
11
+ * the {@link BuildingBlockScope} base constructor, so every BB self-registers the
12
+ * moment it is constructed — `finalizeVpc` then enumerates them without a separate
13
+ * discovery pass (mirrors how `registerCompute`/`registerConfig` accumulate during
14
+ * the backend import). Because it's driven by the base constructor, a BB **cannot**
15
+ * silently skip declaring its requirements: the constructor won't compile without
16
+ * supplying them (see `BuildingBlockScope`).
17
+ *
18
+ * @param bb - The construct declaring the requirement (used to locate its stack and name it).
19
+ * @param requirements - What the BB needs from the VPC.
20
+ */
21
+ export declare function registerVpcRequirements(bb: Construct & {
22
+ readonly fullId: string;
23
+ }, requirements: VpcRequirements): void;
24
+ /**
25
+ * The VPC requirements registered on the stack that owns `scope`, in construction
26
+ * order. Returns an empty array before any BB is constructed.
27
+ *
28
+ * @param scope - Any construct in the stack (used to locate the stack).
29
+ */
30
+ export declare function getVpcRequirements(scope: Construct): readonly RegisteredVpcRequirement[];
31
+ /** Clear the registry. **For test cleanup only.** */
32
+ export declare function _resetVpcRequirementsRegistry(stack: cdk.Stack): void;
33
+ //# sourceMappingURL=vpc-requirements-registry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vpc-requirements-registry.d.ts","sourceRoot":"","sources":["../../src/cdk/vpc-requirements-registry.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,GAAG,MAAM,aAAa,CAAC;AACnC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAC5C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAItD,wFAAwF;AACxF,MAAM,WAAW,wBAAwB;IACxC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,YAAY,EAAE,eAAe,CAAC;CACvC;AAiBD;;;;;;;;;;;GAWG;AACH,wBAAgB,uBAAuB,CACtC,EAAE,EAAE,SAAS,GAAG;IAAE,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;CAAE,EAC3C,YAAY,EAAE,eAAe,GAC3B,IAAI,CAEN;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,SAAS,GAAG,SAAS,wBAAwB,EAAE,CAExF;AAED,qDAAqD;AACrD,wBAAgB,6BAA6B,CAAC,KAAK,EAAE,GAAG,CAAC,KAAK,GAAG,IAAI,CAEpE"}
@@ -0,0 +1,46 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ import * as cdk from 'aws-cdk-lib';
4
+ const REGISTRY_KEY = Symbol.for('BLOCKS_VPC_REQUIREMENTS_REGISTRY');
5
+ /**
6
+ * Get or create the VPC-requirements list for a given stack. Stored on the stack
7
+ * object (keyed by a Symbol), so each stack in a multi-stack synth gets its own —
8
+ * a requirement never leaks into another stack's list. Mirrors the compute and
9
+ * config registries, which scope their state the same way.
10
+ */
11
+ function getRegistry(stack) {
12
+ let list = stack[REGISTRY_KEY];
13
+ if (!list) {
14
+ list = [];
15
+ stack[REGISTRY_KEY] = list;
16
+ }
17
+ return list;
18
+ }
19
+ /**
20
+ * Register a Building Block's VPC requirements on its owning stack. Called from
21
+ * the {@link BuildingBlockScope} base constructor, so every BB self-registers the
22
+ * moment it is constructed — `finalizeVpc` then enumerates them without a separate
23
+ * discovery pass (mirrors how `registerCompute`/`registerConfig` accumulate during
24
+ * the backend import). Because it's driven by the base constructor, a BB **cannot**
25
+ * silently skip declaring its requirements: the constructor won't compile without
26
+ * supplying them (see `BuildingBlockScope`).
27
+ *
28
+ * @param bb - The construct declaring the requirement (used to locate its stack and name it).
29
+ * @param requirements - What the BB needs from the VPC.
30
+ */
31
+ export function registerVpcRequirements(bb, requirements) {
32
+ getRegistry(cdk.Stack.of(bb)).push({ fullId: bb.fullId, requirements });
33
+ }
34
+ /**
35
+ * The VPC requirements registered on the stack that owns `scope`, in construction
36
+ * order. Returns an empty array before any BB is constructed.
37
+ *
38
+ * @param scope - Any construct in the stack (used to locate the stack).
39
+ */
40
+ export function getVpcRequirements(scope) {
41
+ return getRegistry(cdk.Stack.of(scope));
42
+ }
43
+ /** Clear the registry. **For test cleanup only.** */
44
+ export function _resetVpcRequirementsRegistry(stack) {
45
+ stack[REGISTRY_KEY] = [];
46
+ }