@aws-blocks/core 0.2.0 → 0.4.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/README.md +13 -0
- package/dist/api.d.ts.map +1 -1
- package/dist/api.js +32 -0
- package/dist/api.test.js +22 -0
- package/dist/bb-utils.d.ts +1 -0
- package/dist/bb-utils.d.ts.map +1 -1
- package/dist/bb-utils.js +3 -0
- package/dist/cdk/apigateway-account.d.ts +33 -0
- package/dist/cdk/apigateway-account.d.ts.map +1 -0
- package/dist/cdk/apigateway-account.js +60 -0
- package/dist/cdk/blocks-backend.d.ts +43 -9
- package/dist/cdk/blocks-backend.d.ts.map +1 -1
- package/dist/cdk/blocks-backend.js +69 -73
- package/dist/cdk/blocks-backend.test.js +78 -69
- package/dist/cdk/blocks-defaults.d.ts +92 -2
- package/dist/cdk/blocks-defaults.d.ts.map +1 -1
- package/dist/cdk/blocks-defaults.js +22 -2
- package/dist/cdk/blocks-defaults.test.js +21 -2
- package/dist/cdk/blocks-stack.test.js +94 -37
- package/dist/cdk/compute/compute-registry.d.ts +19 -0
- package/dist/cdk/compute/compute-registry.d.ts.map +1 -0
- package/dist/cdk/compute/compute-registry.js +38 -0
- package/dist/cdk/compute/compute.d.ts +2 -0
- package/dist/cdk/compute/compute.d.ts.map +1 -1
- package/dist/cdk/compute/compute.js +8 -0
- package/dist/cdk/compute/default-compute-factory.d.ts +34 -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/config-registry.d.ts +34 -4
- package/dist/cdk/config-registry.d.ts.map +1 -1
- package/dist/cdk/config-registry.js +83 -25
- package/dist/cdk/config-registry.test.d.ts +2 -0
- package/dist/cdk/config-registry.test.d.ts.map +1 -0
- package/dist/cdk/config-registry.test.js +115 -0
- package/dist/cdk/index.d.ts +76 -7
- package/dist/cdk/index.d.ts.map +1 -1
- package/dist/cdk/index.js +99 -9
- package/dist/cdk/internal.d.ts +1 -0
- package/dist/cdk/internal.d.ts.map +1 -1
- package/dist/client/index.d.ts +1 -1
- package/dist/client/index.d.ts.map +1 -1
- package/dist/client/index.js +1 -1
- package/dist/common/config.d.ts +34 -0
- package/dist/common/config.d.ts.map +1 -1
- package/dist/common/config.js +45 -3
- package/dist/common/config.test.js +19 -0
- package/dist/common/index.d.ts +8 -0
- package/dist/common/index.d.ts.map +1 -1
- package/dist/errors.d.ts +16 -0
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +20 -0
- 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 +97 -6
- package/dist/hosting.d.ts.map +1 -1
- package/dist/hosting.js +91 -23
- package/dist/hosting.test.js +182 -10
- package/dist/index.cdk.d.ts +13 -12
- package/dist/index.cdk.d.ts.map +1 -1
- package/dist/index.cdk.js +13 -9
- 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.d.ts +17 -0
- package/dist/lambda-handler.d.ts.map +1 -1
- package/dist/lambda-handler.js +52 -3
- package/dist/lambda-handler.test.js +196 -1
- 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 +34 -0
- package/dist/rpc.test.js +38 -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-empty-buckets.test.d.ts +2 -0
- package/dist/scripts/sandbox-empty-buckets.test.d.ts.map +1 -0
- package/dist/scripts/sandbox-empty-buckets.test.js +171 -0
- package/dist/scripts/sandbox.d.ts +106 -0
- package/dist/scripts/sandbox.d.ts.map +1 -1
- package/dist/scripts/sandbox.js +255 -40
- 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/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/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +4 -1
- package/src/api.test.ts +25 -0
- package/src/api.ts +39 -0
- package/src/bb-utils.ts +3 -0
- package/src/cdk/apigateway-account.ts +66 -0
- package/src/cdk/blocks-backend.test.ts +291 -272
- package/src/cdk/blocks-backend.ts +88 -83
- package/src/cdk/blocks-defaults.test.ts +25 -2
- package/src/cdk/blocks-defaults.ts +94 -2
- package/src/cdk/blocks-stack.test.ts +186 -118
- package/src/cdk/compute/compute-registry.ts +45 -0
- package/src/cdk/compute/compute.ts +10 -0
- package/src/cdk/compute/default-compute-factory.ts +38 -0
- package/src/cdk/config-registry.test.ts +135 -0
- package/src/cdk/config-registry.ts +92 -34
- package/src/cdk/index.ts +129 -10
- package/src/cdk/internal.ts +1 -0
- package/src/client/index.ts +1 -1
- package/src/common/config.test.ts +21 -0
- package/src/common/config.ts +47 -3
- package/src/common/index.ts +8 -0
- package/src/errors.ts +21 -0
- package/src/hosting-secrets.test.ts +106 -0
- package/src/hosting-secrets.ts +106 -0
- package/src/hosting.test.ts +272 -63
- package/src/hosting.ts +200 -68
- package/src/index.cdk.ts +80 -38
- package/src/index.ts +35 -16
- package/src/lambda-handler.test.ts +215 -1
- package/src/lambda-handler.ts +54 -2
- package/src/pipeline/index.ts +64 -11
- package/src/pipeline.test.ts +55 -0
- package/src/rpc.test.ts +44 -1
- package/src/rpc.ts +41 -0
- 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-empty-buckets.test.ts +191 -0
- package/src/scripts/sandbox.ts +287 -39
- package/src/scripts/secret.test.ts +35 -0
- package/src/scripts/secret.ts +35 -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/version.ts +1 -1
|
@@ -3,10 +3,11 @@
|
|
|
3
3
|
|
|
4
4
|
import { describe, it, beforeEach } from 'node:test';
|
|
5
5
|
import assert from 'node:assert';
|
|
6
|
-
import { createLambdaHandler, _resetCorsPatterns, requestCookies, isApiGatewayHttpEvent, computeHttpDeadlineMs, classifyEvent, buildEventUrl, isLoopbackForwardedHost } from './lambda-handler.js';
|
|
6
|
+
import { createLambdaHandler, _resetCorsPatterns, requestCookies, isApiGatewayHttpEvent, computeHttpDeadlineMs, classifyEvent, buildEventUrl, isLoopbackForwardedHost, TransientConfigError } from './lambda-handler.js';
|
|
7
7
|
import type { LambdaContext } from './lambda-handler.js';
|
|
8
8
|
import { registerRoute, clearRouteRegistry } from './raw-route.js';
|
|
9
9
|
import { decodeRpcResponse } from './rpc.js';
|
|
10
|
+
import { _resetConfigCache, _setS3Fetcher } from './common/config.js';
|
|
10
11
|
import type { BlocksContext } from './api.js';
|
|
11
12
|
|
|
12
13
|
beforeEach(() => {
|
|
@@ -29,6 +30,145 @@ async function invoke(backend: any, event: any): Promise<any> {
|
|
|
29
30
|
return handler(event) as any;
|
|
30
31
|
}
|
|
31
32
|
|
|
33
|
+
// ── init self-heal (retry on failed initialization) ─────────────────────────
|
|
34
|
+
|
|
35
|
+
describe('createLambdaHandler — init self-heal', () => {
|
|
36
|
+
it('retries initialize() on a later request instead of caching a failed init', async () => {
|
|
37
|
+
let initCalls = 0;
|
|
38
|
+
const backend = {
|
|
39
|
+
api: (_ctx: BlocksContext) => ({
|
|
40
|
+
async echo(msg: string) {
|
|
41
|
+
return { msg };
|
|
42
|
+
},
|
|
43
|
+
}),
|
|
44
|
+
};
|
|
45
|
+
// Fail the first initialization (e.g. config not readable yet in the brief post-deploy
|
|
46
|
+
// window), then succeed. The SAME handler instance must recover — a cached rejected
|
|
47
|
+
// initPromise would poison the container and fail every subsequent request.
|
|
48
|
+
const backendFactory = async () => {
|
|
49
|
+
initCalls++;
|
|
50
|
+
if (initCalls === 1) throw new Error('transient init failure');
|
|
51
|
+
return backend;
|
|
52
|
+
};
|
|
53
|
+
const handler = createLambdaHandler(backendFactory);
|
|
54
|
+
|
|
55
|
+
// 1st request: init fails, so the handler rejects.
|
|
56
|
+
await assert.rejects(() => handler(makeEvent()) as any, /transient init failure/);
|
|
57
|
+
|
|
58
|
+
// 2nd request: init is retried and succeeds → 200 (not a re-thrown cached rejection).
|
|
59
|
+
const res = (await handler(makeEvent())) as any;
|
|
60
|
+
assert.strictEqual(res.statusCode, 200);
|
|
61
|
+
assert.strictEqual(initCalls, 2, 'initialize() must be retried on the next request, not cached');
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it('recovers from a transient-empty (post-deploy 404) config load on the next request', async () => {
|
|
65
|
+
// Reproduces the poisoned-container bug: the first S3 load hits the transient
|
|
66
|
+
// post-deploy window (NoSuchKey), so config resolves empty; the handler must
|
|
67
|
+
// NOT lock in that empty config, and the NEXT request must re-fetch and pick
|
|
68
|
+
// up the now-present config.
|
|
69
|
+
_resetConfigCache();
|
|
70
|
+
process.env.BLOCKS_CONFIG_BUCKET = 'test-bucket';
|
|
71
|
+
process.env.BLOCKS_CONFIG_KEY = 'blocks-config.json';
|
|
72
|
+
delete process.env.SELFHEAL_KEY;
|
|
73
|
+
|
|
74
|
+
let fetchCall = 0;
|
|
75
|
+
const notFound = new Error('The specified key does not exist.');
|
|
76
|
+
(notFound as any).name = 'NoSuchKey';
|
|
77
|
+
_setS3Fetcher(async () => {
|
|
78
|
+
fetchCall++;
|
|
79
|
+
if (fetchCall === 1) throw notFound; // config not readable yet
|
|
80
|
+
return JSON.stringify({ SELFHEAL_KEY: 'ready' });
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
let backendImports = 0;
|
|
84
|
+
const handler = createLambdaHandler(async () => {
|
|
85
|
+
backendImports++;
|
|
86
|
+
return {
|
|
87
|
+
api: (_ctx: BlocksContext) => ({
|
|
88
|
+
async echo(msg: string) { return { msg, cfg: process.env.SELFHEAL_KEY }; },
|
|
89
|
+
}),
|
|
90
|
+
};
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
try {
|
|
94
|
+
// 1st request: transient-empty load → initialize() throws TransientConfigError
|
|
95
|
+
// BEFORE importing the backend (so we never lock in empty config), and the
|
|
96
|
+
// request rejects.
|
|
97
|
+
await assert.rejects(() => handler(makeEvent()) as any, TransientConfigError);
|
|
98
|
+
assert.strictEqual(backendImports, 0, 'backend must NOT be imported while config is unresolved');
|
|
99
|
+
|
|
100
|
+
// 2nd request: config now present → initialize() re-runs, re-fetches, and
|
|
101
|
+
// injects the config into process.env before importing the backend.
|
|
102
|
+
const res = (await handler(makeEvent())) as any;
|
|
103
|
+
assert.strictEqual(res.statusCode, 200);
|
|
104
|
+
const body = JSON.parse(res.body);
|
|
105
|
+
assert.strictEqual(body.result.cfg, 'ready', 'now-present config was injected on the retry');
|
|
106
|
+
assert.strictEqual(backendImports, 1, 'backend imported exactly once, on the successful retry');
|
|
107
|
+
assert.strictEqual(fetchCall, 2, 'S3 was re-fetched on the retry (transient miss is not cached)');
|
|
108
|
+
} finally {
|
|
109
|
+
_resetConfigCache();
|
|
110
|
+
delete process.env.BLOCKS_CONFIG_BUCKET;
|
|
111
|
+
delete process.env.BLOCKS_CONFIG_KEY;
|
|
112
|
+
delete process.env.SELFHEAL_KEY;
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
it('does NOT re-init for a config-less app (no bucket, local dev) — initialize runs once', async () => {
|
|
117
|
+
_resetConfigCache();
|
|
118
|
+
delete process.env.BLOCKS_CONFIG_BUCKET;
|
|
119
|
+
delete process.env.BLOCKS_CONFIG_KEY;
|
|
120
|
+
|
|
121
|
+
let backendImports = 0;
|
|
122
|
+
const handler = createLambdaHandler(async () => {
|
|
123
|
+
backendImports++;
|
|
124
|
+
return { api: (_ctx: BlocksContext) => ({ async echo(msg: string) { return { msg }; } }) };
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
try {
|
|
128
|
+
const r1 = (await handler(makeEvent())) as any;
|
|
129
|
+
const r2 = (await handler(makeEvent())) as any;
|
|
130
|
+
assert.strictEqual(r1.statusCode, 200);
|
|
131
|
+
assert.strictEqual(r2.statusCode, 200);
|
|
132
|
+
assert.strictEqual(backendImports, 1, 'no re-init for a genuinely config-less (local dev) app');
|
|
133
|
+
} finally {
|
|
134
|
+
_resetConfigCache();
|
|
135
|
+
}
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
it('does NOT re-init or spin for a genuinely-empty ({}) S3 config', async () => {
|
|
139
|
+
// A real, readable empty config must be treated as resolved — distinct from
|
|
140
|
+
// the transient 404 miss — so the container does not throw/retry forever nor
|
|
141
|
+
// re-fetch S3 on every request.
|
|
142
|
+
_resetConfigCache();
|
|
143
|
+
process.env.BLOCKS_CONFIG_BUCKET = 'test-bucket';
|
|
144
|
+
process.env.BLOCKS_CONFIG_KEY = 'blocks-config.json';
|
|
145
|
+
|
|
146
|
+
let fetchCall = 0;
|
|
147
|
+
_setS3Fetcher(async () => { fetchCall++; return JSON.stringify({}); });
|
|
148
|
+
|
|
149
|
+
let backendImports = 0;
|
|
150
|
+
const handler = createLambdaHandler(async () => {
|
|
151
|
+
backendImports++;
|
|
152
|
+
return { api: (_ctx: BlocksContext) => ({ async echo(msg: string) { return { msg }; } }) };
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
try {
|
|
156
|
+
const r1 = (await handler(makeEvent())) as any;
|
|
157
|
+
const r2 = (await handler(makeEvent())) as any;
|
|
158
|
+
const r3 = (await handler(makeEvent())) as any;
|
|
159
|
+
assert.strictEqual(r1.statusCode, 200);
|
|
160
|
+
assert.strictEqual(r2.statusCode, 200);
|
|
161
|
+
assert.strictEqual(r3.statusCode, 200);
|
|
162
|
+
assert.strictEqual(backendImports, 1, 'genuinely-empty config resolves; no re-init');
|
|
163
|
+
assert.strictEqual(fetchCall, 1, 'S3 fetched once and cached — no per-request re-fetch spin');
|
|
164
|
+
} finally {
|
|
165
|
+
_resetConfigCache();
|
|
166
|
+
delete process.env.BLOCKS_CONFIG_BUCKET;
|
|
167
|
+
delete process.env.BLOCKS_CONFIG_KEY;
|
|
168
|
+
}
|
|
169
|
+
});
|
|
170
|
+
});
|
|
171
|
+
|
|
32
172
|
// ── RPC body tests ──────────────────────────────────────────────────────────
|
|
33
173
|
|
|
34
174
|
describe('createLambdaHandler — RPC body handling', () => {
|
|
@@ -1072,3 +1212,77 @@ describe('createLambdaHandler — sandbox forwarded-host reaches the route', ()
|
|
|
1072
1212
|
assert.strictEqual(capturedHost, 'abc123.execute-api.us-east-1.amazonaws.com');
|
|
1073
1213
|
});
|
|
1074
1214
|
});
|
|
1215
|
+
|
|
1216
|
+
// ── SQS partial batch failure tests ─────────────────────────────────────────
|
|
1217
|
+
|
|
1218
|
+
/**
|
|
1219
|
+
* These pin the runtime half of the bb-async-job BatchSize fix: with a batch
|
|
1220
|
+
* larger than 1, failing records must be reported individually via
|
|
1221
|
+
* `batchItemFailures` so SQS retries only those messages. If this response
|
|
1222
|
+
* shape regresses, every successful sibling message in a partially-failing
|
|
1223
|
+
* batch would be redelivered (or, worse, the failures silently dropped).
|
|
1224
|
+
*/
|
|
1225
|
+
function makeSqsBatchEvent(count: number) {
|
|
1226
|
+
return {
|
|
1227
|
+
Records: Array.from({ length: count }, (_, i) => ({
|
|
1228
|
+
eventSource: 'aws:sqs',
|
|
1229
|
+
eventSourceARN: 'arn:aws:sqs:us-east-1:123456789012:my-queue',
|
|
1230
|
+
messageId: `msg-${i}`,
|
|
1231
|
+
body: JSON.stringify({ n: i }),
|
|
1232
|
+
})),
|
|
1233
|
+
};
|
|
1234
|
+
}
|
|
1235
|
+
|
|
1236
|
+
describe('handleEventSourceRecords — SQS partial batch responses', () => {
|
|
1237
|
+
it('reports only the failed records of a mixed-success 10-record batch', async () => {
|
|
1238
|
+
const processed: number[] = [];
|
|
1239
|
+
const handlers = new Map<string, (record: any) => Promise<void>>();
|
|
1240
|
+
handlers.set('aws:sqs:my-queue', async (record: any) => {
|
|
1241
|
+
const { n } = JSON.parse(record.body);
|
|
1242
|
+
if (n % 3 === 0) throw new Error(`boom on ${n}`);
|
|
1243
|
+
processed.push(n);
|
|
1244
|
+
});
|
|
1245
|
+
(globalThis as any).__BLOCKS_LAMBDA_EVENT_HANDLERS__ = handlers;
|
|
1246
|
+
|
|
1247
|
+
try {
|
|
1248
|
+
const handler = createLambdaHandler(async () => ({}));
|
|
1249
|
+
const result: any = await handler(makeSqsBatchEvent(10));
|
|
1250
|
+
|
|
1251
|
+
assert.deepStrictEqual(
|
|
1252
|
+
result.batchItemFailures.map((f: any) => f.itemIdentifier).sort(),
|
|
1253
|
+
['msg-0', 'msg-3', 'msg-6', 'msg-9']
|
|
1254
|
+
);
|
|
1255
|
+
assert.deepStrictEqual(processed.sort((a, b) => a - b), [1, 2, 4, 5, 7, 8]);
|
|
1256
|
+
} finally {
|
|
1257
|
+
delete (globalThis as any).__BLOCKS_LAMBDA_EVENT_HANDLERS__;
|
|
1258
|
+
}
|
|
1259
|
+
});
|
|
1260
|
+
|
|
1261
|
+
it('returns no batchItemFailures when every record in the batch succeeds', async () => {
|
|
1262
|
+
const handlers = new Map<string, (record: any) => Promise<void>>();
|
|
1263
|
+
handlers.set('aws:sqs:my-queue', async () => {});
|
|
1264
|
+
(globalThis as any).__BLOCKS_LAMBDA_EVENT_HANDLERS__ = handlers;
|
|
1265
|
+
|
|
1266
|
+
try {
|
|
1267
|
+
const handler = createLambdaHandler(async () => ({}));
|
|
1268
|
+
const result: any = await handler(makeSqsBatchEvent(10));
|
|
1269
|
+
assert.deepStrictEqual(result, {});
|
|
1270
|
+
} finally {
|
|
1271
|
+
delete (globalThis as any).__BLOCKS_LAMBDA_EVENT_HANDLERS__;
|
|
1272
|
+
}
|
|
1273
|
+
});
|
|
1274
|
+
|
|
1275
|
+
it('reports all records when the whole batch fails (no silent drop)', async () => {
|
|
1276
|
+
const handlers = new Map<string, (record: any) => Promise<void>>();
|
|
1277
|
+
handlers.set('aws:sqs:my-queue', async () => { throw new Error('always'); });
|
|
1278
|
+
(globalThis as any).__BLOCKS_LAMBDA_EVENT_HANDLERS__ = handlers;
|
|
1279
|
+
|
|
1280
|
+
try {
|
|
1281
|
+
const handler = createLambdaHandler(async () => ({}));
|
|
1282
|
+
const result: any = await handler(makeSqsBatchEvent(10));
|
|
1283
|
+
assert.strictEqual(result.batchItemFailures.length, 10);
|
|
1284
|
+
} finally {
|
|
1285
|
+
delete (globalThis as any).__BLOCKS_LAMBDA_EVENT_HANDLERS__;
|
|
1286
|
+
}
|
|
1287
|
+
});
|
|
1288
|
+
});
|
package/src/lambda-handler.ts
CHANGED
|
@@ -7,7 +7,7 @@ import { ApiError } from './errors.js';
|
|
|
7
7
|
import { BLOCKS_RPC_PREFIX } from './constants.js';
|
|
8
8
|
import { matchRoute, lockRouteRegistry } from './raw-route.js';
|
|
9
9
|
import { registerBuiltinRoutes } from './builtin-routes.js';
|
|
10
|
-
import { loadConfigToProcessEnv } from './common/config.js';
|
|
10
|
+
import { loadConfigToProcessEnv, isConfigResolved } from './common/config.js';
|
|
11
11
|
import {
|
|
12
12
|
parseRpcRequest,
|
|
13
13
|
successResponse,
|
|
@@ -297,6 +297,26 @@ export function createLambdaHandler(backendFactory: () => Promise<any>) {
|
|
|
297
297
|
async function initialize() {
|
|
298
298
|
await loadConfigToProcessEnv();
|
|
299
299
|
|
|
300
|
+
// If the app has config coordinates (BLOCKS_CONFIG_BUCKET/KEY set) but the
|
|
301
|
+
// load didn't actually resolve the config, we're in the transient post-deploy
|
|
302
|
+
// S3 window where blocks-config.json isn't readable yet. loadConfigFromS3()
|
|
303
|
+
// deliberately does NOT cache that empty result, so throw a typed transient
|
|
304
|
+
// error here — BEFORE importing the backend — so the createLambdaHandler()
|
|
305
|
+
// catch resets initPromise and the next request re-runs initialize(), which
|
|
306
|
+
// re-fetches from S3 and picks up the now-present config. Without this throw,
|
|
307
|
+
// initialize() would succeed with empty config, `handler` would be assigned,
|
|
308
|
+
// and the `if (!handler)` guard below would never fire again, poisoning the
|
|
309
|
+
// container for its whole life (it would import the backend against empty
|
|
310
|
+
// process.env and serve "not configured" 500s forever).
|
|
311
|
+
//
|
|
312
|
+
// A genuinely config-less app does NOT throw: the no-bucket local-dev path
|
|
313
|
+
// and a real empty `{}` config both cache their result, so isConfigResolved()
|
|
314
|
+
// is true and the retry never spins. Once the blob is readable the successful
|
|
315
|
+
// load caches, so there is no unbounded per-request S3 re-fetch either.
|
|
316
|
+
if (process.env.BLOCKS_CONFIG_BUCKET && process.env.BLOCKS_CONFIG_KEY && !isConfigResolved()) {
|
|
317
|
+
throw new TransientConfigError();
|
|
318
|
+
}
|
|
319
|
+
|
|
300
320
|
// Merge hosting-provided CORS origins into the main env var so the lazy
|
|
301
321
|
// getCorsPatterns() sees a combined value on first access.
|
|
302
322
|
// loadConfigToProcessEnv() won't override CORS_ALLOWED_ORIGINS if it's
|
|
@@ -318,7 +338,18 @@ export function createLambdaHandler(backendFactory: () => Promise<any>) {
|
|
|
318
338
|
|
|
319
339
|
return async (event: any, context?: LambdaContext) => {
|
|
320
340
|
if (!handler) {
|
|
321
|
-
|
|
341
|
+
// Retry init on failure instead of caching the rejection. If initialize() throws (most often
|
|
342
|
+
// because loadConfigToProcessEnv() couldn't read blocks-config.json during the brief
|
|
343
|
+
// post-deploy window before it's readable), a memoized rejected promise would poison this
|
|
344
|
+
// container for its whole lifetime — every later request re-awaits the same rejection and 500s.
|
|
345
|
+
// Resetting initPromise lets the next invocation re-run initialize() (config.ts re-fetches,
|
|
346
|
+
// since it doesn't cache failures), so the handler self-heals once config is available.
|
|
347
|
+
if (!initPromise) {
|
|
348
|
+
initPromise = initialize().catch((err) => {
|
|
349
|
+
initPromise = null;
|
|
350
|
+
throw err;
|
|
351
|
+
});
|
|
352
|
+
}
|
|
322
353
|
await initPromise;
|
|
323
354
|
}
|
|
324
355
|
|
|
@@ -390,6 +421,27 @@ class HandlerTimeoutError extends Error {
|
|
|
390
421
|
}
|
|
391
422
|
}
|
|
392
423
|
|
|
424
|
+
/**
|
|
425
|
+
* Thrown by `initialize()` when the app has config coordinates
|
|
426
|
+
* (BLOCKS_CONFIG_BUCKET/KEY) but the S3 config load resolved empty because
|
|
427
|
+
* blocks-config.json wasn't readable yet — the transient window right after a
|
|
428
|
+
* deploy, before the BucketDeployment settles.
|
|
429
|
+
*
|
|
430
|
+
* It flows through the `createLambdaHandler()` init catch, which resets
|
|
431
|
+
* `initPromise` so the NEXT request re-runs `initialize()` and picks up the
|
|
432
|
+
* now-present config (config.ts does not cache a not-found result, so the retry
|
|
433
|
+
* re-fetches). A distinct type keeps the recovery path greppable and testable
|
|
434
|
+
* and separates it from real init failures, which surface with their own error.
|
|
435
|
+
*
|
|
436
|
+
* @internal Exported for testing only.
|
|
437
|
+
*/
|
|
438
|
+
export class TransientConfigError extends Error {
|
|
439
|
+
constructor() {
|
|
440
|
+
super('[Blocks] Config not readable yet (transient post-deploy S3 window); will retry on next request');
|
|
441
|
+
this.name = 'TransientConfigError';
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
|
|
393
445
|
/**
|
|
394
446
|
* Extract the request path from a Lambda event, normalizing between
|
|
395
447
|
* API Gateway v1 (REST) and v2 (HTTP API) event shapes.
|
package/src/pipeline/index.ts
CHANGED
|
@@ -1,16 +1,69 @@
|
|
|
1
1
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
import { __PIPELINE_STAGE_SCOPE__, DeployStage, Pipeline as LeafPipeline } from '@aws-blocks/pipeline';
|
|
5
|
+
import type {
|
|
6
|
+
BranchConfig,
|
|
7
|
+
DeployStageProps,
|
|
8
|
+
PipelineProps,
|
|
9
|
+
PipelineSourceConfig,
|
|
10
|
+
PipelineStageConfig,
|
|
11
|
+
PipelineSynthConfig,
|
|
8
12
|
} from '@aws-blocks/pipeline';
|
|
13
|
+
import type { Construct } from 'constructs';
|
|
14
|
+
import { blocksStoreConfig } from '../secret-naming.js';
|
|
15
|
+
|
|
16
|
+
export { __PIPELINE_STAGE_SCOPE__, DeployStage };
|
|
9
17
|
export type {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
}
|
|
18
|
+
BranchConfig,
|
|
19
|
+
DeployStageProps,
|
|
20
|
+
PipelineProps,
|
|
21
|
+
PipelineSourceConfig,
|
|
22
|
+
PipelineStageConfig,
|
|
23
|
+
PipelineSynthConfig,
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Merge the Blocks `/blocks/*` namespace as the DEFAULT store config, so a
|
|
28
|
+
* Blocks pipeline resolves `connectionArn` / `buildSecrets` from the same place
|
|
29
|
+
* the Blocks CLI (`npm run secret` / `npm run config`) writes. Per-kind and
|
|
30
|
+
* shallow: any field the caller sets (a custom `prefix`, a `stage`, a
|
|
31
|
+
* `cacheTtlSeconds`) wins over the Blocks default.
|
|
32
|
+
*/
|
|
33
|
+
function withBlocksDefaults<TConfig>(props: PipelineProps<TConfig>): PipelineProps<TConfig> {
|
|
34
|
+
const blocks = blocksStoreConfig();
|
|
35
|
+
return {
|
|
36
|
+
...props,
|
|
37
|
+
secretStore: { ...blocks.secretStore, ...props.secretStore },
|
|
38
|
+
configStore: { ...blocks.configStore, ...props.configStore },
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Blocks `Pipeline` — the framework-neutral `@aws-blocks/pipeline` construct with
|
|
44
|
+
* the Blocks value namespace pinned. It defaults `secretStore` / `configStore` to
|
|
45
|
+
* `/blocks/secrets` and `/blocks/config` (the prefixes the Blocks `secret` /
|
|
46
|
+
* `config` CLIs write), mirroring how the Blocks `Hosting` block pins the same
|
|
47
|
+
* namespace — so a value set with `npm run secret`/`config` is the value the
|
|
48
|
+
* pipeline reads. Pass `secretStore` / `configStore` to override.
|
|
49
|
+
*
|
|
50
|
+
* @see {@link https://github.com/aws-devtools-labs/aws-blocks/blob/main/packages/pipeline/README.md}
|
|
51
|
+
*/
|
|
52
|
+
export class Pipeline<TConfig = Record<string, unknown>> extends LeafPipeline<TConfig> {
|
|
53
|
+
constructor(scope: Construct, id: string, props: PipelineProps<TConfig>) {
|
|
54
|
+
super(scope, id, withBlocksDefaults(props));
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Async constructor — required when `source.connectionArn` is a `config()`
|
|
59
|
+
* marker (resolved at synth time). Pins the Blocks namespace, then delegates to
|
|
60
|
+
* the leaf {@link LeafPipeline.create}.
|
|
61
|
+
*/
|
|
62
|
+
static async create<TConfig = Record<string, unknown>>(
|
|
63
|
+
scope: Construct,
|
|
64
|
+
id: string,
|
|
65
|
+
props: PipelineProps<TConfig>,
|
|
66
|
+
): Promise<LeafPipeline<TConfig>> {
|
|
67
|
+
return LeafPipeline.create(scope, id, withBlocksDefaults(props));
|
|
68
|
+
}
|
|
69
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import assert from 'node:assert';
|
|
5
|
+
import { afterEach, describe, it } from 'node:test';
|
|
6
|
+
import { _setSynthSecretFetcher } from '@aws-blocks/hosting/constructs';
|
|
7
|
+
import { config } from '@aws-blocks/hosting';
|
|
8
|
+
import type * as cdk from 'aws-cdk-lib';
|
|
9
|
+
import { App, Stack } from 'aws-cdk-lib';
|
|
10
|
+
import { Pipeline } from './pipeline/index.js';
|
|
11
|
+
import type { PipelineStageConfig } from './pipeline/index.js';
|
|
12
|
+
|
|
13
|
+
const MOCK_CONNECTION_ARN = 'arn:aws:codeconnections:us-east-1:123456789012:connection/test-connection-id';
|
|
14
|
+
|
|
15
|
+
function minimalStageFactory(scope: cdk.Stage, stageConfig: PipelineStageConfig): void {
|
|
16
|
+
new Stack(scope, 'AppStack', { env: stageConfig.env });
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// B2: the core Pipeline wrapper must resolve values from the SAME namespace the
|
|
20
|
+
// Blocks CLI writes (`/blocks/*`), not the leaf-neutral `/hosting/*` — otherwise
|
|
21
|
+
// `npm run config -- set CONNECTION_ARN` writes one name and the deploy reads
|
|
22
|
+
// another. The leaf default is `/hosting/config`; the wrapper must pin `/blocks/config`.
|
|
23
|
+
void describe('core Pipeline pins the Blocks namespace', () => {
|
|
24
|
+
afterEach(() => _setSynthSecretFetcher(null));
|
|
25
|
+
|
|
26
|
+
void it('resolves a config() connectionArn under /blocks/config by default', async () => {
|
|
27
|
+
const seen: string[] = [];
|
|
28
|
+
_setSynthSecretFetcher(async (locator: string) => {
|
|
29
|
+
seen.push(locator);
|
|
30
|
+
return MOCK_CONNECTION_ARN;
|
|
31
|
+
});
|
|
32
|
+
await Pipeline.create(new App(), 'BlocksPipeline', {
|
|
33
|
+
source: { repo: 'my-org/my-app', connectionArn: config('CONNECTION_ARN') },
|
|
34
|
+
branches: [{ branch: 'main', stages: [{ name: 'prod' }] }],
|
|
35
|
+
stageFactory: minimalStageFactory,
|
|
36
|
+
});
|
|
37
|
+
// The Blocks CLI writes /blocks/config/CONNECTION_ARN; the wrapper must read it there.
|
|
38
|
+
assert.deepStrictEqual(seen, ['/blocks/config/CONNECTION_ARN']);
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
void it('lets the caller override the pinned prefix', async () => {
|
|
42
|
+
const seen: string[] = [];
|
|
43
|
+
_setSynthSecretFetcher(async (locator: string) => {
|
|
44
|
+
seen.push(locator);
|
|
45
|
+
return MOCK_CONNECTION_ARN;
|
|
46
|
+
});
|
|
47
|
+
await Pipeline.create(new App(), 'OverridePipeline', {
|
|
48
|
+
source: { repo: 'my-org/my-app', connectionArn: config('CONNECTION_ARN') },
|
|
49
|
+
branches: [{ branch: 'main', stages: [{ name: 'prod' }] }],
|
|
50
|
+
stageFactory: minimalStageFactory,
|
|
51
|
+
configStore: { prefix: '/myapp/config' },
|
|
52
|
+
});
|
|
53
|
+
assert.deepStrictEqual(seen, ['/myapp/config/CONNECTION_ARN']);
|
|
54
|
+
});
|
|
55
|
+
});
|
package/src/rpc.test.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
import { describe, it } from 'node:test';
|
|
5
5
|
import assert from 'node:assert';
|
|
6
|
-
import { decodeRpcResponse, errorResponseFromCatch, parseRpcRequest, RpcErrorCode } from './rpc.js';
|
|
6
|
+
import { decodeRpcResponse, errorResponseFromCatch, parseRpcRequest, RpcErrorCode, MAX_RPC_BODY_BYTES } from './rpc.js';
|
|
7
7
|
import { ApiError, isBlocksError } from './errors.js';
|
|
8
8
|
|
|
9
9
|
describe('-32600 Invalid Request error shape', () => {
|
|
@@ -188,3 +188,46 @@ describe('ApiError status ↔ JSON-RPC error code', () => {
|
|
|
188
188
|
);
|
|
189
189
|
});
|
|
190
190
|
});
|
|
191
|
+
|
|
192
|
+
describe('request body size limit', () => {
|
|
193
|
+
it('accepts a normal-sized body', () => {
|
|
194
|
+
const result = parseRpcRequest(JSON.stringify({ jsonrpc: '2.0', method: 'ns.method', params: [], id: 1 }));
|
|
195
|
+
assert.strictEqual(result.ok, true);
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
it('rejects a body larger than MAX_RPC_BODY_BYTES with a PayloadTooLarge error', () => {
|
|
199
|
+
// A JSON string just over the limit (a single huge param value).
|
|
200
|
+
const huge = 'x'.repeat(MAX_RPC_BODY_BYTES + 1);
|
|
201
|
+
const body = JSON.stringify({ jsonrpc: '2.0', method: 'ns.method', params: [huge], id: 1 });
|
|
202
|
+
assert.ok(Buffer.byteLength(body, 'utf8') > MAX_RPC_BODY_BYTES);
|
|
203
|
+
|
|
204
|
+
const result = parseRpcRequest(body);
|
|
205
|
+
assert.strictEqual(result.ok, false);
|
|
206
|
+
if (result.ok) return; // narrow
|
|
207
|
+
const parsed = JSON.parse(result.response);
|
|
208
|
+
// Positive HTTP status (413), not a reserved -32xxx — so decodeRpcResponse
|
|
209
|
+
// surfaces it to the client as ApiError.status === 413.
|
|
210
|
+
assert.strictEqual(parsed.error.code, 413);
|
|
211
|
+
assert.strictEqual(parsed.error.data?.name, 'PayloadTooLarge');
|
|
212
|
+
assert.match(parsed.error.message, /exceeds/);
|
|
213
|
+
assert.match(parsed.error.message, /10 MiB/); // human-readable size crosses the wire
|
|
214
|
+
|
|
215
|
+
// Client round-trip: decodeRpcResponse surfaces it as ApiError.status 413
|
|
216
|
+
// (not 500), so consumer `e.status === 413` handling works.
|
|
217
|
+
assert.throws(
|
|
218
|
+
() => decodeRpcResponse(parsed),
|
|
219
|
+
(e: unknown) => e instanceof ApiError && e.status === 413 && isBlocksError(e, 'PayloadTooLarge'),
|
|
220
|
+
);
|
|
221
|
+
});
|
|
222
|
+
|
|
223
|
+
it('rejects an oversized body before attempting to parse it (invalid JSON still 413s, not a ParseError)', () => {
|
|
224
|
+
// Oversized AND not valid JSON — the size guard must win, proving the body
|
|
225
|
+
// is rejected before the (expensive) parse + before any handler/DB touch.
|
|
226
|
+
const oversizedGarbage = 'x'.repeat(MAX_RPC_BODY_BYTES + 1);
|
|
227
|
+
const result = parseRpcRequest(oversizedGarbage);
|
|
228
|
+
assert.strictEqual(result.ok, false);
|
|
229
|
+
if (result.ok) return;
|
|
230
|
+
const parsed = JSON.parse(result.response);
|
|
231
|
+
assert.strictEqual(parsed.error.data?.name, 'PayloadTooLarge');
|
|
232
|
+
});
|
|
233
|
+
});
|
package/src/rpc.ts
CHANGED
|
@@ -32,6 +32,28 @@ export type RpcParseResult =
|
|
|
32
32
|
|
|
33
33
|
const VERSION = '2.0' as const;
|
|
34
34
|
|
|
35
|
+
/**
|
|
36
|
+
* Maximum accepted request-body size, in bytes (10 MiB).
|
|
37
|
+
*
|
|
38
|
+
* Matches the payload limit API Gateway enforces in production (~10 MB for a
|
|
39
|
+
* REST API). In prod an oversized body is rejected by API Gateway at the edge —
|
|
40
|
+
* before the Lambda is invoked — so this guard's rejection path effectively
|
|
41
|
+
* runs on the dev/mock server, where there is no edge to stop it: an oversized
|
|
42
|
+
* body would otherwise buffer and wedge the local database (e.g. PGlite). By
|
|
43
|
+
* enforcing the *same* limit locally, the dev server rejects the same oversized
|
|
44
|
+
* body prod would 413 at the edge, instead of failing only in one environment.
|
|
45
|
+
* Enforced in `parseRpcRequest`, the single choke point both the Lambda handler
|
|
46
|
+
* and the dev server route through.
|
|
47
|
+
*
|
|
48
|
+
* Note: this value is the Lambda + API Gateway limit. It lives here (in the
|
|
49
|
+
* compute-agnostic parser) because Lambda is the only compute path today. When
|
|
50
|
+
* a non-API-Gateway compute (e.g. container/ALB) is introduced, this should
|
|
51
|
+
* become compute-aware — sourced from / overridden by the compute layer (via
|
|
52
|
+
* the Compute `setEnv` config hook) rather than a fixed constant in `core` —
|
|
53
|
+
* since an ALB has a different payload limit. Tracked with the multi-compute work.
|
|
54
|
+
*/
|
|
55
|
+
export const MAX_RPC_BODY_BYTES = 10 * 1024 * 1024;
|
|
56
|
+
|
|
35
57
|
/** Reserved JSON-RPC error codes. */
|
|
36
58
|
export const RpcErrorCode = {
|
|
37
59
|
ParseError: -32700,
|
|
@@ -89,6 +111,25 @@ export function decodeRpcResponse(body: unknown): unknown {
|
|
|
89
111
|
* anything about the JSON-RPC spec.
|
|
90
112
|
*/
|
|
91
113
|
export function parseRpcRequest(bodyText: string): RpcParseResult {
|
|
114
|
+
// Reject oversized bodies before parsing or dispatch. See MAX_RPC_BODY_BYTES
|
|
115
|
+
// for the limit and its rationale.
|
|
116
|
+
if (Buffer.byteLength(bodyText, 'utf8') > MAX_RPC_BODY_BYTES) {
|
|
117
|
+
// Emit the real HTTP status (413) as the error code, not a reserved -32xxx:
|
|
118
|
+
// `decodeRpcResponse` maps a positive code straight to `ApiError.status`
|
|
119
|
+
// (reserved codes collapse to 500), mirroring the 504 handler-timeout path,
|
|
120
|
+
// so a caller's `e.status === 413` works. `name` (which crosses the wire,
|
|
121
|
+
// not the code) lets callers match with `isBlocksError(e, 'PayloadTooLarge')`.
|
|
122
|
+
return {
|
|
123
|
+
ok: false,
|
|
124
|
+
response: errorResponse(
|
|
125
|
+
413,
|
|
126
|
+
`Request body exceeds the ${MAX_RPC_BODY_BYTES} byte (${MAX_RPC_BODY_BYTES / (1024 * 1024)} MiB) limit`,
|
|
127
|
+
null,
|
|
128
|
+
{ name: 'PayloadTooLarge' },
|
|
129
|
+
),
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
|
|
92
133
|
let parsed: any;
|
|
93
134
|
try {
|
|
94
135
|
parsed = JSON.parse(bodyText || '{}');
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* `blocks config` — manage a Blocks app's non-sensitive **config** values (SSM
|
|
6
|
+
* Parameter Store), pinned to the Blocks `/blocks/<stackId>/config` namespace
|
|
7
|
+
* (scoped to the app's stable `stackId` from `.blocks/config.json`). Thin wrapper
|
|
8
|
+
* over the shared `@aws-blocks/hosting` CLI with the kind fixed to `config`. The
|
|
9
|
+
* `secret` counterpart is `./secret.ts`.
|
|
10
|
+
*
|
|
11
|
+
* @module
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import { listValues, removeValue, runValueCli, setValue } from '@aws-blocks/hosting/scripts';
|
|
15
|
+
import { blocksConfigPrefix } from '../secret-naming.js';
|
|
16
|
+
|
|
17
|
+
/** Set (create or overwrite) a Blocks config value. */
|
|
18
|
+
export function setConfig(key: string, value: string, opts: { stage?: string } = {}): Promise<void> {
|
|
19
|
+
return setValue('config', key, value, { prefix: blocksConfigPrefix(), ...opts });
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** List Blocks config keys (names only). */
|
|
23
|
+
export function listConfig(opts: { stage?: string } = {}): Promise<string[]> {
|
|
24
|
+
return listValues('config', { prefix: blocksConfigPrefix(), ...opts });
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** Remove a Blocks config value. */
|
|
28
|
+
export function removeConfig(key: string, opts: { stage?: string } = {}): Promise<boolean> {
|
|
29
|
+
return removeValue('config', key, { prefix: blocksConfigPrefix(), ...opts });
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** CLI dispatcher for `blocks config <set|list|remove> …`. */
|
|
33
|
+
export function runConfigCli(argv: string[]): Promise<void> {
|
|
34
|
+
return runValueCli(argv, { kind: 'config', prefix: blocksConfigPrefix(), label: 'blocks config' });
|
|
35
|
+
}
|
package/src/scripts/deploy.ts
CHANGED
|
@@ -6,6 +6,7 @@ import { readFileSync, writeFileSync, mkdirSync } from 'node:fs';
|
|
|
6
6
|
import { join, resolve, dirname } from 'node:path';
|
|
7
7
|
import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
8
8
|
import { ensureSecrets, loadProductionEnv } from './ensure-secrets.js';
|
|
9
|
+
import { assertAwsCredentials } from './preflight-credentials.js';
|
|
9
10
|
import { applyExternalMigrations } from './external-migrations-step.js';
|
|
10
11
|
import { trackCommand } from '../telemetry/trackCommand.js';
|
|
11
12
|
import { getCdkTelemetryEnv } from './cdk-telemetry-env.js';
|
|
@@ -25,6 +26,10 @@ export async function deploy(options: DeployOptions) {
|
|
|
25
26
|
|
|
26
27
|
process.env.BLOCKS_STAGE = 'production';
|
|
27
28
|
|
|
29
|
+
// Fail fast if AWS credentials are missing/expired, before generating the
|
|
30
|
+
// client and spending time in synth only to hit an opaque CDK credential error.
|
|
31
|
+
await assertAwsCredentials('deploy');
|
|
32
|
+
|
|
28
33
|
// Provision secrets for production. projectRoot must match the root cdk
|
|
29
34
|
// synth uses (passed as --context below) so the written parameter name
|
|
30
35
|
// equals the one the app resolves at synth.
|