@aws-blocks/core 0.1.18 → 0.3.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.
- package/dist/cdk/__fixtures__/import-meta-handler.d.ts +6 -0
- package/dist/cdk/__fixtures__/import-meta-handler.d.ts.map +1 -0
- package/dist/cdk/__fixtures__/import-meta-handler.js +13 -0
- package/dist/cdk/blocks-backend.d.ts +46 -9
- package/dist/cdk/blocks-backend.d.ts.map +1 -1
- package/dist/cdk/blocks-backend.js +66 -67
- package/dist/cdk/blocks-backend.test.js +114 -56
- package/dist/cdk/blocks-defaults.d.ts +70 -0
- package/dist/cdk/blocks-defaults.d.ts.map +1 -0
- package/dist/cdk/blocks-defaults.js +27 -0
- package/dist/cdk/blocks-defaults.test.d.ts +2 -0
- package/dist/cdk/blocks-defaults.test.d.ts.map +1 -0
- package/dist/cdk/blocks-defaults.test.js +24 -0
- package/dist/cdk/blocks-stack.test.js +74 -31
- package/dist/cdk/bundling.d.ts +42 -0
- package/dist/cdk/bundling.d.ts.map +1 -0
- package/dist/cdk/bundling.js +72 -0
- package/dist/cdk/bundling.test.d.ts +2 -0
- package/dist/cdk/bundling.test.d.ts.map +1 -0
- package/dist/cdk/bundling.test.js +80 -0
- package/dist/cdk/compute/compute.d.ts +33 -0
- package/dist/cdk/compute/compute.d.ts.map +1 -0
- package/dist/cdk/compute/compute.js +28 -0
- package/dist/cdk/compute/default-compute-factory.d.ts +33 -0
- package/dist/cdk/compute/default-compute-factory.d.ts.map +1 -0
- package/dist/cdk/compute/default-compute-factory.js +3 -0
- package/dist/cdk/index.d.ts +92 -12
- package/dist/cdk/index.d.ts.map +1 -1
- package/dist/cdk/index.js +141 -25
- package/dist/cdk/internal.d.ts +25 -0
- package/dist/cdk/internal.d.ts.map +1 -0
- package/dist/cdk/internal.js +27 -0
- package/dist/cdk/mixins.d.ts +18 -4
- package/dist/cdk/mixins.d.ts.map +1 -1
- package/dist/cdk/mixins.js +31 -7
- package/dist/cdk/mixins.test.js +45 -0
- package/dist/common/index.d.ts +9 -0
- package/dist/common/index.d.ts.map +1 -1
- package/dist/hosting-secrets.d.ts +48 -0
- package/dist/hosting-secrets.d.ts.map +1 -0
- package/dist/hosting-secrets.js +57 -0
- package/dist/hosting-secrets.test.d.ts +2 -0
- package/dist/hosting-secrets.test.d.ts.map +1 -0
- package/dist/hosting-secrets.test.js +81 -0
- package/dist/hosting.d.ts +88 -6
- package/dist/hosting.d.ts.map +1 -1
- package/dist/hosting.js +83 -24
- package/dist/hosting.test.js +158 -10
- package/dist/index.cdk.d.ts +13 -11
- package/dist/index.cdk.d.ts.map +1 -1
- package/dist/index.cdk.js +13 -8
- package/dist/index.d.ts +8 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -5
- package/dist/lambda-handler.test.js +66 -0
- package/dist/pipeline/index.d.ts +24 -2
- package/dist/pipeline/index.d.ts.map +1 -1
- package/dist/pipeline/index.js +41 -1
- package/dist/pipeline.test.d.ts +2 -0
- package/dist/pipeline.test.d.ts.map +1 -0
- package/dist/pipeline.test.js +47 -0
- package/dist/rpc.d.ts +21 -0
- package/dist/rpc.d.ts.map +1 -1
- package/dist/rpc.js +46 -3
- package/dist/rpc.test.js +58 -1
- package/dist/scripts/config.d.ts +15 -0
- package/dist/scripts/config.d.ts.map +1 -0
- package/dist/scripts/config.js +29 -0
- package/dist/scripts/deploy.d.ts.map +1 -1
- package/dist/scripts/deploy.js +4 -0
- package/dist/scripts/dev-server.d.ts +8 -0
- package/dist/scripts/dev-server.d.ts.map +1 -1
- package/dist/scripts/dev-server.js +31 -0
- package/dist/scripts/generate-client.d.ts.map +1 -1
- package/dist/scripts/generate-client.js +9 -4
- package/dist/scripts/generate-client.test.js +19 -4
- package/dist/scripts/index.d.ts +13 -10
- package/dist/scripts/index.d.ts.map +1 -1
- package/dist/scripts/index.js +11 -8
- package/dist/scripts/preflight-credentials.d.ts +30 -0
- package/dist/scripts/preflight-credentials.d.ts.map +1 -0
- package/dist/scripts/preflight-credentials.js +108 -0
- package/dist/scripts/preflight-credentials.test.d.ts +2 -0
- package/dist/scripts/preflight-credentials.test.d.ts.map +1 -0
- package/dist/scripts/preflight-credentials.test.js +77 -0
- package/dist/scripts/sandbox-args.test.d.ts +2 -0
- package/dist/scripts/sandbox-args.test.d.ts.map +1 -0
- package/dist/scripts/sandbox-args.test.js +77 -0
- package/dist/scripts/sandbox.d.ts +52 -0
- package/dist/scripts/sandbox.d.ts.map +1 -1
- package/dist/scripts/sandbox.js +92 -15
- package/dist/scripts/secret.d.ts +15 -0
- package/dist/scripts/secret.d.ts.map +1 -0
- package/dist/scripts/secret.js +29 -0
- package/dist/scripts/secret.test.d.ts +2 -0
- package/dist/scripts/secret.test.d.ts.map +1 -0
- package/dist/scripts/secret.test.js +28 -0
- package/dist/scripts/telemetry.test.js +2 -0
- package/dist/scripts/typegen.d.ts +15 -0
- package/dist/scripts/typegen.d.ts.map +1 -0
- package/dist/scripts/typegen.js +16 -0
- package/dist/secret-naming.d.ts +58 -0
- package/dist/secret-naming.d.ts.map +1 -0
- package/dist/secret-naming.js +67 -0
- package/dist/secret-naming.test.d.ts +2 -0
- package/dist/secret-naming.test.d.ts.map +1 -0
- package/dist/secret-naming.test.js +40 -0
- package/dist/telemetry/environment.d.ts.map +1 -1
- package/dist/telemetry/environment.js +3 -1
- package/dist/telemetry/telemetry.test.js +10 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.d.ts.map +1 -1
- package/dist/version.js +1 -1
- package/package.json +7 -1
- package/src/cdk/__fixtures__/import-meta-handler.ts +16 -0
- package/src/cdk/blocks-backend.test.ts +308 -237
- package/src/cdk/blocks-backend.ts +98 -77
- package/src/cdk/blocks-defaults.test.ts +27 -0
- package/src/cdk/blocks-defaults.ts +75 -0
- package/src/cdk/blocks-stack.test.ts +160 -110
- package/src/cdk/bundling.test.ts +90 -0
- package/src/cdk/bundling.ts +76 -0
- package/src/cdk/compute/compute.ts +37 -0
- package/src/cdk/compute/default-compute-factory.ts +37 -0
- package/src/cdk/index.ts +178 -27
- package/src/cdk/internal.ts +30 -0
- package/src/cdk/mixins.test.ts +56 -1
- package/src/cdk/mixins.ts +32 -7
- package/src/common/index.ts +9 -0
- package/src/hosting-secrets.test.ts +106 -0
- package/src/hosting-secrets.ts +106 -0
- package/src/hosting.test.ts +244 -63
- package/src/hosting.ts +180 -68
- package/src/index.cdk.ts +79 -36
- package/src/index.ts +35 -16
- package/src/lambda-handler.test.ts +74 -0
- package/src/pipeline/index.ts +64 -11
- package/src/pipeline.test.ts +55 -0
- package/src/rpc.test.ts +66 -1
- package/src/rpc.ts +60 -3
- package/src/scripts/config.ts +35 -0
- package/src/scripts/deploy.ts +5 -0
- package/src/scripts/dev-server.ts +40 -0
- package/src/scripts/generate-client.test.ts +43 -8
- package/src/scripts/generate-client.ts +70 -65
- package/src/scripts/index.ts +20 -17
- package/src/scripts/preflight-credentials.test.ts +110 -0
- package/src/scripts/preflight-credentials.ts +131 -0
- package/src/scripts/sandbox-args.test.ts +92 -0
- package/src/scripts/sandbox.ts +102 -15
- package/src/scripts/secret.test.ts +35 -0
- package/src/scripts/secret.ts +35 -0
- package/src/scripts/telemetry.test.ts +2 -0
- package/src/scripts/typegen.ts +18 -0
- package/src/secret-naming.test.ts +59 -0
- package/src/secret-naming.ts +99 -0
- package/src/telemetry/environment.ts +3 -1
- package/src/telemetry/telemetry.test.ts +12 -0
- package/src/version.ts +1 -1
package/dist/cdk/index.d.ts
CHANGED
|
@@ -1,43 +1,123 @@
|
|
|
1
1
|
import * as cdk from 'aws-cdk-lib';
|
|
2
2
|
import { Construct } from 'constructs';
|
|
3
3
|
import { type BlocksStackProps, type BlocksStack as BaseBlocksStack, type ScopeParent, type ScopeOptions } from '../common/index.js';
|
|
4
|
-
|
|
4
|
+
import { type BlocksDefaults } from './blocks-defaults.js';
|
|
5
|
+
import type { Compute } from './compute/compute.js';
|
|
6
|
+
import type { DefaultComputeFactory } from './compute/default-compute-factory.js';
|
|
7
|
+
export { BlocksBackend, type BlocksBackendProps, type CoreBlocksBackendProps, SHARED_HANDLER_TIMEOUT_SECONDS, } from './blocks-backend.js';
|
|
5
8
|
export { DEFAULT_NODE_RUNTIME } from './node-version.js';
|
|
9
|
+
export { blocksNodejsBundling } from './bundling.js';
|
|
6
10
|
export { SandboxDisableDeletionProtection } from './mixins.js';
|
|
7
11
|
export { registerConfig, finalizeConfigRegistry } from './config-registry.js';
|
|
12
|
+
export { type BlocksDefaults, BlocksPresets, } from './blocks-defaults.js';
|
|
8
13
|
export { synthGuard } from './synth-guard.js';
|
|
9
14
|
export type { ScopeOptions } from '../index.js';
|
|
10
15
|
export { ApiError, isBlocksError, hasAuthError, DEFAULT_API_ERROR_NAME } from '../errors.js';
|
|
16
|
+
/**
|
|
17
|
+
* Core's `create()` props: the public {@link BlocksStackProps} plus the required
|
|
18
|
+
* `defaultComputeFactory`. The umbrella (`@aws-blocks/blocks`) supplies the
|
|
19
|
+
* factory (which builds a `LambdaCompute`) by spreading it onto the customer's
|
|
20
|
+
* props; customers use {@link BlocksStackProps} and never set the factory.
|
|
21
|
+
*
|
|
22
|
+
* Kept separate (rather than a `create()` argument) so the factory travels with
|
|
23
|
+
* the props object and core stays free of any concrete compute class.
|
|
24
|
+
*
|
|
25
|
+
* @internal
|
|
26
|
+
*/
|
|
27
|
+
export interface CoreBlocksStackProps extends BlocksStackProps {
|
|
28
|
+
/** Builds the stack's default compute. Injected by `@aws-blocks/blocks`. */
|
|
29
|
+
defaultComputeFactory: DefaultComputeFactory;
|
|
30
|
+
}
|
|
11
31
|
export declare class BlocksStack extends cdk.Stack implements BaseBlocksStack {
|
|
12
32
|
readonly id: string;
|
|
13
|
-
readonly apiUrl: string;
|
|
14
|
-
readonly gateway: cdk.aws_apigateway.RestApi;
|
|
15
|
-
readonly handler: cdk.aws_lambda_nodejs.NodejsFunction;
|
|
16
33
|
readonly backendHandlerPath: string;
|
|
17
34
|
/** Shared IAM role assumed by all Blocks compute. Building Blocks grant to this role. */
|
|
18
35
|
readonly executionRole: cdk.aws_iam.IRole;
|
|
36
|
+
/** Infrastructure defaults for Building Blocks created under this stack. */
|
|
37
|
+
readonly defaults: BlocksDefaults;
|
|
38
|
+
/** The default compute (owns the Lambda function + API Gateway); set in `create()`. @internal */
|
|
39
|
+
_defaultCompute?: Compute;
|
|
40
|
+
/** The default compute's Lambda function. To be removed once consumers move to the multi-compute model. */
|
|
41
|
+
get handler(): cdk.aws_lambda_nodejs.NodejsFunction;
|
|
42
|
+
/** The default compute's API Gateway REST API. To be removed once consumers move to the multi-compute model. */
|
|
43
|
+
get gateway(): cdk.aws_apigateway.RestApi;
|
|
44
|
+
/** The default compute's RPC endpoint URL. To be removed once consumers move to the multi-compute model. */
|
|
45
|
+
get apiUrl(): string;
|
|
46
|
+
private requireDefaultCompute;
|
|
19
47
|
private constructor();
|
|
20
|
-
static create(scope: Construct, id: string, props:
|
|
48
|
+
static create(scope: Construct, id: string, props: CoreBlocksStackProps): Promise<BlocksStack>;
|
|
21
49
|
}
|
|
22
50
|
export declare class Scope extends Construct {
|
|
23
51
|
readonly id: string;
|
|
24
52
|
readonly parent: ScopeParent;
|
|
25
53
|
readonly bbName?: string;
|
|
26
54
|
readonly bbVersion?: string;
|
|
55
|
+
/**
|
|
56
|
+
* The owning stack/backend (the root of the Blocks construct tree), resolved
|
|
57
|
+
* once at construction: the nearest BlocksStack/BlocksBackend up the construct
|
|
58
|
+
* tree, or the ambient `globalThis.CURRENT_BLOCKS_STACK` fallback. All
|
|
59
|
+
* root-derived accessors below read from this instead of each repeating the
|
|
60
|
+
* tree walk.
|
|
61
|
+
*/
|
|
62
|
+
private readonly root;
|
|
63
|
+
/**
|
|
64
|
+
* Compute assigned at this node. Applies to this block and is inherited by
|
|
65
|
+
* descendants (a nearer assignment wins). Covers both a handler assigned to a
|
|
66
|
+
* specific compute and a scope-level default for its subtree. Internal until
|
|
67
|
+
* the customer-facing surface exists.
|
|
68
|
+
* @internal
|
|
69
|
+
*/
|
|
70
|
+
_compute?: Compute;
|
|
27
71
|
constructor(id: string, options?: ScopeOptions);
|
|
72
|
+
/**
|
|
73
|
+
* Walk up the construct tree to the nearest owning BlocksStack/BlocksBackend;
|
|
74
|
+
* fall back to the ambient `globalThis.CURRENT_BLOCKS_STACK`. Called once from
|
|
75
|
+
* the constructor; the result is cached in {@link root}.
|
|
76
|
+
*/
|
|
77
|
+
private resolveRoot;
|
|
28
78
|
get handler(): cdk.aws_lambda_nodejs.NodejsFunction;
|
|
29
79
|
/**
|
|
30
80
|
* The shared IAM role assumed by all Blocks compute. Building Blocks grant
|
|
31
|
-
* their permissions to this role
|
|
32
|
-
*
|
|
33
|
-
* to the role's default (inline) policy — exactly where they landed on the
|
|
34
|
-
* auto-generated role before.
|
|
35
|
-
*
|
|
36
|
-
* Resolves the same way as {@link handler}: walk up to the owning
|
|
37
|
-
* BlocksStack/BlocksBackend, falling back to the ambient stack.
|
|
81
|
+
* their permissions to this role; CDK's `grant*()` / `addToPrincipalPolicy()`
|
|
82
|
+
* route those grants to the role's default (inline) policy.
|
|
38
83
|
*/
|
|
39
84
|
get executionRole(): cdk.aws_iam.IRole;
|
|
85
|
+
/**
|
|
86
|
+
* The compute this block runs on: the nearest `_compute` assigned on this
|
|
87
|
+
* block or an ancestor scope, else the owning stack/backend's default compute.
|
|
88
|
+
*
|
|
89
|
+
* For any app that doesn't assign a compute, this always resolves to the
|
|
90
|
+
* default — so reads are a no-op refactor. `_compute` is internal
|
|
91
|
+
* (test/framework) until the customer-facing surface exists; there is no
|
|
92
|
+
* public option to set it yet.
|
|
93
|
+
*/
|
|
94
|
+
get compute(): Compute;
|
|
95
|
+
/**
|
|
96
|
+
* The backend entry file the owning BlocksStack/BlocksBackend runs — the
|
|
97
|
+
* single handler entry shared across the whole app.
|
|
98
|
+
*/
|
|
99
|
+
get backendHandlerPath(): string;
|
|
100
|
+
/**
|
|
101
|
+
* The owning stack/backend's token-free root identity. This is the value the
|
|
102
|
+
* runtime receives as `BLOCKS_STACK_NAME` and rebuilds `fullId` from, so
|
|
103
|
+
* physical resource names (DynamoDB tables, env-var keys, IAM ARNs) derived
|
|
104
|
+
* from `fullId` match byte-for-byte between synth and runtime — otherwise the
|
|
105
|
+
* runtime looks up names that were never created. `BlocksBackend` exposes this
|
|
106
|
+
* as `fullId` ({@link BlocksBackend.fullId}); `BlocksStack` as `id`.
|
|
107
|
+
*/
|
|
108
|
+
get backendStackName(): string;
|
|
40
109
|
get fullId(): string;
|
|
110
|
+
/**
|
|
111
|
+
* The stack-wide infrastructure {@link BlocksDefaults} registered by
|
|
112
|
+
* `BlocksStack.create` / `BlocksBackend.create`. Read these in a Building
|
|
113
|
+
* Block's CDK constructor to resolve a durability value, letting a per-block
|
|
114
|
+
* option override:
|
|
115
|
+
*
|
|
116
|
+
* ```ts
|
|
117
|
+
* const removalPolicy = options?.removalPolicy ?? this.defaults.removalPolicy;
|
|
118
|
+
* ```
|
|
119
|
+
*/
|
|
120
|
+
get defaults(): BlocksDefaults;
|
|
41
121
|
protected buildUserAgentChain(): [string, string][];
|
|
42
122
|
registerClientMiddleware(_packageSpecifier: string): void;
|
|
43
123
|
registerDevAttachment(_packageSpecifier: string): void;
|
package/dist/cdk/index.d.ts.map
CHANGED
|
@@ -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;
|
|
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,M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SAAS,CAAC,mBAAmB,IAAI,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE;IAKnD,wBAAwB,CAAC,iBAAiB,EAAE,MAAM,GAAG,IAAI;IACzD,qBAAqB,CAAC,iBAAiB,EAAE,MAAM,GAAG,IAAI;IACtD,0BAA0B,CAAC,YAAY,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,MAAM,EAAE,GAAG,KAAK,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI;IACrH,IAAI,gBAAgB,IAAI,SAAS,MAAM,EAAE,CAAe;IACxD,IAAI,cAAc,IAAI,SAAS,MAAM,EAAE,CAAe;CACvD"}
|
package/dist/cdk/index.js
CHANGED
|
@@ -8,30 +8,50 @@ import { computeScopeFullId, } from '../common/index.js';
|
|
|
8
8
|
import { setupBlocksInfra, BlocksBackend, assertCdkConditionActive } from './blocks-backend.js';
|
|
9
9
|
import { addBlocksStackMetadata } from './stack-metadata.js';
|
|
10
10
|
import { finalizeConfigRegistry } from './config-registry.js';
|
|
11
|
-
|
|
11
|
+
import { BlocksPresets } from './blocks-defaults.js';
|
|
12
|
+
export { BlocksBackend, SHARED_HANDLER_TIMEOUT_SECONDS, } from './blocks-backend.js';
|
|
12
13
|
export { DEFAULT_NODE_RUNTIME } from './node-version.js';
|
|
14
|
+
export { blocksNodejsBundling } from './bundling.js';
|
|
13
15
|
export { SandboxDisableDeletionProtection } from './mixins.js';
|
|
14
16
|
export { registerConfig, finalizeConfigRegistry } from './config-registry.js';
|
|
17
|
+
export { BlocksPresets, } from './blocks-defaults.js';
|
|
15
18
|
export { synthGuard } from './synth-guard.js';
|
|
16
19
|
export { ApiError, isBlocksError, hasAuthError, DEFAULT_API_ERROR_NAME } from '../errors.js';
|
|
17
20
|
export class BlocksStack extends cdk.Stack {
|
|
18
21
|
id;
|
|
19
|
-
apiUrl;
|
|
20
|
-
gateway;
|
|
21
|
-
handler;
|
|
22
22
|
backendHandlerPath;
|
|
23
23
|
/** Shared IAM role assumed by all Blocks compute. Building Blocks grant to this role. */
|
|
24
24
|
executionRole;
|
|
25
|
+
/** Infrastructure defaults for Building Blocks created under this stack. */
|
|
26
|
+
defaults;
|
|
27
|
+
/** The default compute (owns the Lambda function + API Gateway); set in `create()`. @internal */
|
|
28
|
+
_defaultCompute;
|
|
29
|
+
/** The default compute's Lambda function. To be removed once consumers move to the multi-compute model. */
|
|
30
|
+
get handler() {
|
|
31
|
+
return this.requireDefaultCompute().fn;
|
|
32
|
+
}
|
|
33
|
+
/** The default compute's API Gateway REST API. To be removed once consumers move to the multi-compute model. */
|
|
34
|
+
get gateway() {
|
|
35
|
+
return this.requireDefaultCompute().apiGateway;
|
|
36
|
+
}
|
|
37
|
+
/** The default compute's RPC endpoint URL. To be removed once consumers move to the multi-compute model. */
|
|
38
|
+
get apiUrl() {
|
|
39
|
+
return this.requireDefaultCompute().apiUrl;
|
|
40
|
+
}
|
|
41
|
+
requireDefaultCompute() {
|
|
42
|
+
if (!this._defaultCompute) {
|
|
43
|
+
throw new Error('Blocks stack not fully initialized — access .handler/.gateway/.apiUrl after BlocksStack.create() resolves.');
|
|
44
|
+
}
|
|
45
|
+
return this._defaultCompute;
|
|
46
|
+
}
|
|
25
47
|
constructor(scope, id, props) {
|
|
26
48
|
super(scope, id, props);
|
|
27
49
|
this.id = id;
|
|
28
50
|
this.backendHandlerPath = props.backendHandlerPath;
|
|
51
|
+
this.defaults = props.defaults;
|
|
29
52
|
// Set globalThis so Building Blocks attach directly to this stack
|
|
30
53
|
globalThis.CURRENT_BLOCKS_STACK = this;
|
|
31
54
|
const infra = setupBlocksInfra(this, props, id);
|
|
32
|
-
this.handler = infra.handler;
|
|
33
|
-
this.gateway = infra.gateway;
|
|
34
|
-
this.apiUrl = infra.apiUrl;
|
|
35
55
|
this.executionRole = infra.executionRole;
|
|
36
56
|
}
|
|
37
57
|
static async create(scope, id, props) {
|
|
@@ -40,6 +60,13 @@ export class BlocksStack extends cdk.Stack {
|
|
|
40
60
|
const pipelineScope = globalThis[__PIPELINE_STAGE_SCOPE__];
|
|
41
61
|
const actualScope = pipelineScope || scope;
|
|
42
62
|
const stack = new BlocksStack(actualScope, id, props);
|
|
63
|
+
// Create the default compute before importing the backend: it OWNS the
|
|
64
|
+
// Lambda function + API Gateway (which back .handler/.gateway/.apiUrl), and
|
|
65
|
+
// a block reading `this.compute` in its constructor (during that import)
|
|
66
|
+
// must resolve to it. The factory is supplied by the umbrella
|
|
67
|
+
// @aws-blocks/blocks (which injects LambdaCompute) via props, so core never
|
|
68
|
+
// imports the concrete compute class.
|
|
69
|
+
stack._defaultCompute = props.defaultComputeFactory(stack);
|
|
43
70
|
// file:// URL (not a raw path) so the cache-busting query works on Windows,
|
|
44
71
|
// where an absolute path like `D:\...` is rejected as URL scheme `d:`.
|
|
45
72
|
const backendUrl = pathToFileURL(props.backendCDKPath);
|
|
@@ -65,47 +92,136 @@ export class Scope extends Construct {
|
|
|
65
92
|
parent;
|
|
66
93
|
bbName;
|
|
67
94
|
bbVersion;
|
|
95
|
+
/**
|
|
96
|
+
* The owning stack/backend (the root of the Blocks construct tree), resolved
|
|
97
|
+
* once at construction: the nearest BlocksStack/BlocksBackend up the construct
|
|
98
|
+
* tree, or the ambient `globalThis.CURRENT_BLOCKS_STACK` fallback. All
|
|
99
|
+
* root-derived accessors below read from this instead of each repeating the
|
|
100
|
+
* tree walk.
|
|
101
|
+
*/
|
|
102
|
+
root;
|
|
103
|
+
/**
|
|
104
|
+
* Compute assigned at this node. Applies to this block and is inherited by
|
|
105
|
+
* descendants (a nearer assignment wins). Covers both a handler assigned to a
|
|
106
|
+
* specific compute and a scope-level default for its subtree. Internal until
|
|
107
|
+
* the customer-facing surface exists.
|
|
108
|
+
* @internal
|
|
109
|
+
*/
|
|
110
|
+
_compute;
|
|
68
111
|
constructor(id, options) {
|
|
69
112
|
const parent = options?.parent || globalThis.CURRENT_BLOCKS_STACK;
|
|
70
113
|
super(parent, id);
|
|
71
114
|
this.id = id;
|
|
72
115
|
this.parent = parent;
|
|
116
|
+
this.root = this.resolveRoot();
|
|
73
117
|
}
|
|
74
|
-
|
|
75
|
-
|
|
118
|
+
/**
|
|
119
|
+
* Walk up the construct tree to the nearest owning BlocksStack/BlocksBackend;
|
|
120
|
+
* fall back to the ambient `globalThis.CURRENT_BLOCKS_STACK`. Called once from
|
|
121
|
+
* the constructor; the result is cached in {@link root}.
|
|
122
|
+
*/
|
|
123
|
+
resolveRoot() {
|
|
76
124
|
let current = this;
|
|
77
125
|
while (current.node.scope) {
|
|
78
126
|
current = current.node.scope;
|
|
79
127
|
if (current instanceof BlocksStack || current instanceof BlocksBackend) {
|
|
80
|
-
return current
|
|
128
|
+
return current;
|
|
81
129
|
}
|
|
82
130
|
}
|
|
83
|
-
// Fallback to
|
|
84
|
-
|
|
131
|
+
// Fallback to the ambient stack. In production this is always a real
|
|
132
|
+
// BlocksStack/BlocksBackend; the cast also admits the test doubles that set
|
|
133
|
+
// globalThis.CURRENT_BLOCKS_STACK to a stub exposing the same surface.
|
|
134
|
+
return globalThis.CURRENT_BLOCKS_STACK;
|
|
135
|
+
}
|
|
136
|
+
get handler() {
|
|
137
|
+
return this.root.handler;
|
|
85
138
|
}
|
|
86
139
|
/**
|
|
87
140
|
* The shared IAM role assumed by all Blocks compute. Building Blocks grant
|
|
88
|
-
* their permissions to this role
|
|
89
|
-
*
|
|
90
|
-
* to the role's default (inline) policy — exactly where they landed on the
|
|
91
|
-
* auto-generated role before.
|
|
92
|
-
*
|
|
93
|
-
* Resolves the same way as {@link handler}: walk up to the owning
|
|
94
|
-
* BlocksStack/BlocksBackend, falling back to the ambient stack.
|
|
141
|
+
* their permissions to this role; CDK's `grant*()` / `addToPrincipalPolicy()`
|
|
142
|
+
* route those grants to the role's default (inline) policy.
|
|
95
143
|
*/
|
|
96
144
|
get executionRole() {
|
|
145
|
+
return this.root.executionRole;
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* The compute this block runs on: the nearest `_compute` assigned on this
|
|
149
|
+
* block or an ancestor scope, else the owning stack/backend's default compute.
|
|
150
|
+
*
|
|
151
|
+
* For any app that doesn't assign a compute, this always resolves to the
|
|
152
|
+
* default — so reads are a no-op refactor. `_compute` is internal
|
|
153
|
+
* (test/framework) until the customer-facing surface exists; there is no
|
|
154
|
+
* public option to set it yet.
|
|
155
|
+
*/
|
|
156
|
+
get compute() {
|
|
157
|
+
for (let current = this; current; current = current.parent) {
|
|
158
|
+
const assigned = current._compute;
|
|
159
|
+
if (assigned)
|
|
160
|
+
return assigned;
|
|
161
|
+
}
|
|
162
|
+
const defaultCompute = this.root._defaultCompute;
|
|
163
|
+
if (!defaultCompute) {
|
|
164
|
+
throw new Error('Default compute not initialized — BlocksStack/BlocksBackend.create() must run before resolving `compute`.');
|
|
165
|
+
}
|
|
166
|
+
return defaultCompute;
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* The backend entry file the owning BlocksStack/BlocksBackend runs — the
|
|
170
|
+
* single handler entry shared across the whole app.
|
|
171
|
+
*/
|
|
172
|
+
get backendHandlerPath() {
|
|
173
|
+
return this.root.backendHandlerPath;
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* The owning stack/backend's token-free root identity. This is the value the
|
|
177
|
+
* runtime receives as `BLOCKS_STACK_NAME` and rebuilds `fullId` from, so
|
|
178
|
+
* physical resource names (DynamoDB tables, env-var keys, IAM ARNs) derived
|
|
179
|
+
* from `fullId` match byte-for-byte between synth and runtime — otherwise the
|
|
180
|
+
* runtime looks up names that were never created. `BlocksBackend` exposes this
|
|
181
|
+
* as `fullId` ({@link BlocksBackend.fullId}); `BlocksStack` as `id`.
|
|
182
|
+
*/
|
|
183
|
+
get backendStackName() {
|
|
184
|
+
const name = this.root instanceof BlocksBackend ? this.root.fullId : this.root.id;
|
|
185
|
+
if (!name) {
|
|
186
|
+
throw new Error('Owning Blocks stack/backend has no id to derive BLOCKS_STACK_NAME');
|
|
187
|
+
}
|
|
188
|
+
return name;
|
|
189
|
+
}
|
|
190
|
+
get fullId() {
|
|
191
|
+
return computeScopeFullId(this);
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* The stack-wide infrastructure {@link BlocksDefaults} registered by
|
|
195
|
+
* `BlocksStack.create` / `BlocksBackend.create`. Read these in a Building
|
|
196
|
+
* Block's CDK constructor to resolve a durability value, letting a per-block
|
|
197
|
+
* option override:
|
|
198
|
+
*
|
|
199
|
+
* ```ts
|
|
200
|
+
* const removalPolicy = options?.removalPolicy ?? this.defaults.removalPolicy;
|
|
201
|
+
* ```
|
|
202
|
+
*/
|
|
203
|
+
get defaults() {
|
|
204
|
+
// Resolve the same way as handler/executionRole: walk up to the owning
|
|
205
|
+
// BlocksStack/BlocksBackend and read its defaults, so several backends in
|
|
206
|
+
// one stack each keep their own posture. Falls back to the ambient stack,
|
|
207
|
+
// then to the production preset when none was registered.
|
|
97
208
|
let current = this;
|
|
98
209
|
while (current.node.scope) {
|
|
99
210
|
current = current.node.scope;
|
|
100
211
|
if (current instanceof BlocksStack || current instanceof BlocksBackend) {
|
|
101
|
-
return current.
|
|
212
|
+
return current.defaults;
|
|
102
213
|
}
|
|
103
214
|
}
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
215
|
+
const ambient = globalThis.CURRENT_BLOCKS_STACK?.defaults;
|
|
216
|
+
if (ambient)
|
|
217
|
+
return ambient;
|
|
218
|
+
// No owning BlocksStack/BlocksBackend in the tree and none ambient — this is
|
|
219
|
+
// usually a deliberate test stub, but could be a real misconfiguration (a
|
|
220
|
+
// block built outside any Blocks backend). Fall back to the safe production
|
|
221
|
+
// posture, and log so it's debuggable if it fires unexpectedly.
|
|
222
|
+
console.warn(`[Blocks] Scope "${this.id}" resolved infrastructure defaults with no owning ` +
|
|
223
|
+
'BlocksStack/BlocksBackend in scope; falling back to BlocksPresets.production.');
|
|
224
|
+
return BlocksPresets.production;
|
|
109
225
|
}
|
|
110
226
|
buildUserAgentChain() {
|
|
111
227
|
return [];
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Internal CDK entry point — framework- and test-only surface that is
|
|
3
|
+
* intentionally NOT part of the public API (`@aws-blocks/core` /
|
|
4
|
+
* `@aws-blocks/core/cdk`).
|
|
5
|
+
*
|
|
6
|
+
* The compute abstraction lives behind this path while it has no public,
|
|
7
|
+
* customer-facing surface. Importing from here is a signal that you are inside
|
|
8
|
+
* the framework or a test, not a customer.
|
|
9
|
+
*
|
|
10
|
+
* Planned removal: once a customer can assign a compute and have it actually
|
|
11
|
+
* take effect — i.e. `this.compute` resolution and request routing to the
|
|
12
|
+
* chosen compute both exist, plus a synth-time guard that rejects an assignment
|
|
13
|
+
* with no route — these exports move to the public CDK entry point
|
|
14
|
+
* (`@aws-blocks/core/cdk`, re-exported from `index.cdk.ts`) and this file is
|
|
15
|
+
* deleted. It must NOT be made public before then: a compute a customer can
|
|
16
|
+
* declare but that is silently ignored is a worse experience than not having
|
|
17
|
+
* the feature. Until that flip, treat everything here as unstable — no
|
|
18
|
+
* backward-compatibility guarantee.
|
|
19
|
+
*
|
|
20
|
+
* @internal
|
|
21
|
+
*/
|
|
22
|
+
export { Compute } from './compute/compute.js';
|
|
23
|
+
export type { DefaultComputeFactory } from './compute/default-compute-factory.js';
|
|
24
|
+
export { BLOCKS_NAMESPACE } from '../constants.js';
|
|
25
|
+
//# sourceMappingURL=internal.d.ts.map
|
|
@@ -0,0 +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"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
/**
|
|
4
|
+
* Internal CDK entry point — framework- and test-only surface that is
|
|
5
|
+
* intentionally NOT part of the public API (`@aws-blocks/core` /
|
|
6
|
+
* `@aws-blocks/core/cdk`).
|
|
7
|
+
*
|
|
8
|
+
* The compute abstraction lives behind this path while it has no public,
|
|
9
|
+
* customer-facing surface. Importing from here is a signal that you are inside
|
|
10
|
+
* the framework or a test, not a customer.
|
|
11
|
+
*
|
|
12
|
+
* Planned removal: once a customer can assign a compute and have it actually
|
|
13
|
+
* take effect — i.e. `this.compute` resolution and request routing to the
|
|
14
|
+
* chosen compute both exist, plus a synth-time guard that rejects an assignment
|
|
15
|
+
* with no route — these exports move to the public CDK entry point
|
|
16
|
+
* (`@aws-blocks/core/cdk`, re-exported from `index.cdk.ts`) and this file is
|
|
17
|
+
* deleted. It must NOT be made public before then: a compute a customer can
|
|
18
|
+
* declare but that is silently ignored is a worse experience than not having
|
|
19
|
+
* the feature. Until that flip, treat everything here as unstable — no
|
|
20
|
+
* backward-compatibility guarantee.
|
|
21
|
+
*
|
|
22
|
+
* @internal
|
|
23
|
+
*/
|
|
24
|
+
export { Compute } from './compute/compute.js';
|
|
25
|
+
// Reserved `/aws-blocks` path segment, needed by concrete computes (e.g.
|
|
26
|
+
// LambdaCompute in @aws-blocks/bb-lambda-compute) to build their API route tree.
|
|
27
|
+
export { BLOCKS_NAMESPACE } from '../constants.js';
|
package/dist/cdk/mixins.d.ts
CHANGED
|
@@ -2,13 +2,27 @@ import { Mixin } from 'aws-cdk-lib';
|
|
|
2
2
|
import type { IConstruct } from 'constructs';
|
|
3
3
|
import type { IMixin } from 'constructs';
|
|
4
4
|
/**
|
|
5
|
-
* Disables deletion protection on any construct that
|
|
6
|
-
* property (e.g. RDS clusters, RDS instances).
|
|
7
|
-
* automatically covers current and future resource
|
|
5
|
+
* Disables deletion protection on any construct that exposes a deletion
|
|
6
|
+
* protection property (e.g. RDS clusters, RDS instances, DynamoDB tables).
|
|
7
|
+
* Uses duck-typing so it automatically covers current and future resource
|
|
8
|
+
* types, matching both the `deletionProtection` and
|
|
9
|
+
* `deletionProtectionEnabled` spellings.
|
|
10
|
+
*
|
|
11
|
+
* Note that a DynamoDB L2 `Table` only accepts `deletionProtection` as a prop
|
|
12
|
+
* and does not re-expose it, so tables are matched through their underlying
|
|
13
|
+
* L1 `CfnTable.deletionProtectionEnabled`.
|
|
8
14
|
*
|
|
9
15
|
* Intended for sandbox teardown — use in the CDK layer alongside
|
|
10
16
|
* `RemovalPolicies.of(stack).destroy()` to ensure `sandbox:destroy` can
|
|
11
|
-
* delete the entire stack without manual cleanup.
|
|
17
|
+
* delete the entire stack without manual cleanup. DynamoDB refuses
|
|
18
|
+
* `DeleteTable` while deletion protection is enabled, regardless of the
|
|
19
|
+
* CloudFormation `DeletionPolicy`.
|
|
20
|
+
*
|
|
21
|
+
* @deprecated Prefer the stack-wide `defaults` prop on `BlocksStack`/`BlocksBackend`
|
|
22
|
+
* (`defaults: BlocksPresets.sandbox` / `.production`, or `sandboxMode ? … : …`).
|
|
23
|
+
* Amazon-authored Building Blocks now read removal policy + deletion protection
|
|
24
|
+
* from `defaults`, so this mixin is no longer needed; it is retained only for
|
|
25
|
+
* backward compatibility.
|
|
12
26
|
*
|
|
13
27
|
* @example
|
|
14
28
|
* ```ts
|
package/dist/cdk/mixins.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mixins.d.ts","sourceRoot":"","sources":["../../src/cdk/mixins.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AACpC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"mixins.d.ts","sourceRoot":"","sources":["../../src/cdk/mixins.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AACpC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AAWzC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,qBAAa,gCAAiC,SAAQ,KAAM,YAAW,MAAM;IAC3E,QAAQ,CAAC,SAAS,EAAE,GAAG,GAAG,OAAO;IAGjC,OAAO,CAAC,IAAI,EAAE,UAAU,GAAG,IAAI;CAWhC"}
|
package/dist/cdk/mixins.js
CHANGED
|
@@ -2,13 +2,35 @@
|
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
import { Mixin } from 'aws-cdk-lib';
|
|
4
4
|
/**
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
5
|
+
* Property names used across CloudFormation resources to express deletion
|
|
6
|
+
* protection. L2 constructs and most L1s use `deletionProtection` (e.g. RDS
|
|
7
|
+
* clusters and instances, ELBv2 load balancers), while others spell it
|
|
8
|
+
* `deletionProtectionEnabled` (e.g. the DynamoDB `CfnTable` behind an L2
|
|
9
|
+
* `Table`, Aurora DSQL clusters).
|
|
10
|
+
*/
|
|
11
|
+
const DELETION_PROTECTION_PROPERTIES = ['deletionProtection', 'deletionProtectionEnabled'];
|
|
12
|
+
/**
|
|
13
|
+
* Disables deletion protection on any construct that exposes a deletion
|
|
14
|
+
* protection property (e.g. RDS clusters, RDS instances, DynamoDB tables).
|
|
15
|
+
* Uses duck-typing so it automatically covers current and future resource
|
|
16
|
+
* types, matching both the `deletionProtection` and
|
|
17
|
+
* `deletionProtectionEnabled` spellings.
|
|
18
|
+
*
|
|
19
|
+
* Note that a DynamoDB L2 `Table` only accepts `deletionProtection` as a prop
|
|
20
|
+
* and does not re-expose it, so tables are matched through their underlying
|
|
21
|
+
* L1 `CfnTable.deletionProtectionEnabled`.
|
|
8
22
|
*
|
|
9
23
|
* Intended for sandbox teardown — use in the CDK layer alongside
|
|
10
24
|
* `RemovalPolicies.of(stack).destroy()` to ensure `sandbox:destroy` can
|
|
11
|
-
* delete the entire stack without manual cleanup.
|
|
25
|
+
* delete the entire stack without manual cleanup. DynamoDB refuses
|
|
26
|
+
* `DeleteTable` while deletion protection is enabled, regardless of the
|
|
27
|
+
* CloudFormation `DeletionPolicy`.
|
|
28
|
+
*
|
|
29
|
+
* @deprecated Prefer the stack-wide `defaults` prop on `BlocksStack`/`BlocksBackend`
|
|
30
|
+
* (`defaults: BlocksPresets.sandbox` / `.production`, or `sandboxMode ? … : …`).
|
|
31
|
+
* Amazon-authored Building Blocks now read removal policy + deletion protection
|
|
32
|
+
* from `defaults`, so this mixin is no longer needed; it is retained only for
|
|
33
|
+
* backward compatibility.
|
|
12
34
|
*
|
|
13
35
|
* @example
|
|
14
36
|
* ```ts
|
|
@@ -23,15 +45,17 @@ import { Mixin } from 'aws-cdk-lib';
|
|
|
23
45
|
*/
|
|
24
46
|
export class SandboxDisableDeletionProtection extends Mixin {
|
|
25
47
|
supports(construct) {
|
|
26
|
-
return
|
|
48
|
+
return DELETION_PROTECTION_PROPERTIES.some((property) => property in construct);
|
|
27
49
|
}
|
|
28
50
|
applyTo(node) {
|
|
29
51
|
// Only flip explicitly-enabled protection. When undefined (the default),
|
|
30
52
|
// deletion protection is already off — setting it to false would emit the
|
|
31
53
|
// property in the CloudFormation template, which breaks Aurora DB instances
|
|
32
54
|
// (RDS rejects DeletionProtection on cluster members).
|
|
33
|
-
|
|
34
|
-
node
|
|
55
|
+
for (const property of DELETION_PROTECTION_PROPERTIES) {
|
|
56
|
+
if (node[property] === true) {
|
|
57
|
+
node[property] = false;
|
|
58
|
+
}
|
|
35
59
|
}
|
|
36
60
|
}
|
|
37
61
|
}
|
package/dist/cdk/mixins.test.js
CHANGED
|
@@ -92,6 +92,51 @@ describe('sandbox removal policy', () => {
|
|
|
92
92
|
DeletionProtection: Match.absent(),
|
|
93
93
|
});
|
|
94
94
|
});
|
|
95
|
+
test('SandboxDisableDeletionProtection mixin: deletionProtection disabled on DynamoDB table', () => {
|
|
96
|
+
const app = new cdk.App({ context: { sandboxMode: 'true' } });
|
|
97
|
+
const stack = new cdk.Stack(app, 'TestStack');
|
|
98
|
+
new Table(stack, 'MyTable', {
|
|
99
|
+
partitionKey: { name: 'pk', type: AttributeType.STRING },
|
|
100
|
+
billingMode: BillingMode.PAY_PER_REQUEST,
|
|
101
|
+
deletionProtection: true,
|
|
102
|
+
});
|
|
103
|
+
RemovalPolicies.of(stack).destroy();
|
|
104
|
+
Mixins.of(stack).apply(new SandboxDisableDeletionProtection());
|
|
105
|
+
const template = Template.fromStack(stack);
|
|
106
|
+
// DynamoDB refuses DeleteTable while protection is on, regardless of DeletionPolicy
|
|
107
|
+
template.hasResourceProperties('AWS::DynamoDB::Table', {
|
|
108
|
+
DeletionProtectionEnabled: false,
|
|
109
|
+
});
|
|
110
|
+
template.hasResource('AWS::DynamoDB::Table', {
|
|
111
|
+
DeletionPolicy: 'Delete',
|
|
112
|
+
});
|
|
113
|
+
});
|
|
114
|
+
test('production mode: deletionProtection stays enabled on DynamoDB table when mixin is not applied', () => {
|
|
115
|
+
const app = new cdk.App();
|
|
116
|
+
const stack = new cdk.Stack(app, 'TestStack');
|
|
117
|
+
new Table(stack, 'MyTable', {
|
|
118
|
+
partitionKey: { name: 'pk', type: AttributeType.STRING },
|
|
119
|
+
billingMode: BillingMode.PAY_PER_REQUEST,
|
|
120
|
+
deletionProtection: true,
|
|
121
|
+
});
|
|
122
|
+
const template = Template.fromStack(stack);
|
|
123
|
+
template.hasResourceProperties('AWS::DynamoDB::Table', {
|
|
124
|
+
DeletionProtectionEnabled: true,
|
|
125
|
+
});
|
|
126
|
+
});
|
|
127
|
+
test('SandboxDisableDeletionProtection mixin: does not set DeletionProtectionEnabled on unprotected tables', () => {
|
|
128
|
+
const app = new cdk.App({ context: { sandboxMode: 'true' } });
|
|
129
|
+
const stack = new cdk.Stack(app, 'TestStack');
|
|
130
|
+
new Table(stack, 'MyTable', {
|
|
131
|
+
partitionKey: { name: 'pk', type: AttributeType.STRING },
|
|
132
|
+
billingMode: BillingMode.PAY_PER_REQUEST,
|
|
133
|
+
});
|
|
134
|
+
Mixins.of(stack).apply(new SandboxDisableDeletionProtection());
|
|
135
|
+
const template = Template.fromStack(stack);
|
|
136
|
+
template.hasResourceProperties('AWS::DynamoDB::Table', {
|
|
137
|
+
DeletionProtectionEnabled: Match.absent(),
|
|
138
|
+
});
|
|
139
|
+
});
|
|
95
140
|
test('SandboxDisableDeletionProtection mixin: skips constructs without deletionProtection', () => {
|
|
96
141
|
const app = new cdk.App();
|
|
97
142
|
const stack = new cdk.Stack(app, 'TestStack');
|
package/dist/common/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { StackProps } from 'aws-cdk-lib';
|
|
2
2
|
import type { Construct } from 'constructs';
|
|
3
|
+
import type { BlocksDefaults } from '../cdk/blocks-defaults.js';
|
|
3
4
|
export { OFFICIAL_BB_NAMES } from './official-bb-names.generated.js';
|
|
4
5
|
export interface ScopeOptions {
|
|
5
6
|
parent?: ScopeParent;
|
|
@@ -212,6 +213,14 @@ export declare function computeScopeFullId(scope: {
|
|
|
212
213
|
export interface BlocksStackProps extends StackProps {
|
|
213
214
|
backendHandlerPath: string;
|
|
214
215
|
backendCDKPath: string;
|
|
216
|
+
/**
|
|
217
|
+
* Stack-wide infrastructure defaults applied to every Building Block (removal
|
|
218
|
+
* policy, deletion protection, …). Start from `BlocksPresets.sandbox` or
|
|
219
|
+
* `BlocksPresets.production` and override individual fields as needed. Any
|
|
220
|
+
* field a block also exposes as a per-block option is overridden by that
|
|
221
|
+
* option. See `BlocksDefaults` in `@aws-blocks/core/cdk`.
|
|
222
|
+
*/
|
|
223
|
+
defaults: BlocksDefaults;
|
|
215
224
|
}
|
|
216
225
|
export declare class BlocksStack {
|
|
217
226
|
readonly id: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/common/index.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/common/index.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAC5C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAGhE,OAAO,EAAE,iBAAiB,EAAE,MAAM,kCAAkC,CAAC;AAErE,MAAM,WAAW,YAAY;IAC3B,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,MAAM,WAAW,GAAG,KAAK,GAAG;IAAE,EAAE,EAAE,MAAM,CAAA;CAAE,CAAC;AAEjD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsGG;AAEH;;;GAGG;AACH,MAAM,WAAW,iBAAiB;IACjC,8EAA8E;IAC9E,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,4EAA4E;IAC5E,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;CAC3B;AAED,qBAAa,KAAK;IAChB,SAAgB,EAAE,EAAE,MAAM,CAAC;IAC3B,SAAgB,MAAM,EAAE,WAAW,CAAC;IAEpC,qEAAqE;IACrE,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IACzB,2EAA2E;IAC3E,QA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