@beesolve/cdk-constructs 0.1.2 → 0.1.4
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/index.d.ts +28 -5
- package/dist/index.js +108 -39
- package/package.json +4 -3
package/dist/index.d.ts
CHANGED
|
@@ -210,12 +210,35 @@ interface SqsWithDlqLambdaInputProps extends SqsWithDlqProps {
|
|
|
210
210
|
readonly disabled?: boolean;
|
|
211
211
|
}
|
|
212
212
|
type BatchingConfig = Pick<SqsEventSourceProps, "batchSize" | "maxBatchingWindow" | "reportBatchItemFailures" | "maxConcurrency">;
|
|
213
|
+
import { Architecture, Function as Function3, LoggingFormat, Runtime } from "aws-cdk-lib/aws-lambda";
|
|
213
214
|
import { NodejsFunctionProps } from "aws-cdk-lib/aws-lambda-nodejs";
|
|
214
215
|
import { LogGroupProps } from "aws-cdk-lib/aws-logs";
|
|
215
216
|
import { Construct as Construct4 } from "constructs";
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
217
|
+
type Nodejs24FunctionProps = Omit<NodejsFunctionProps, "runtime" | "architecture" | "logGroup" | "entry" | "handler" | "code" | "bundling" | "awsSdkConnectionReuse"> & {
|
|
218
|
+
entry: `${string}.ts`;
|
|
219
|
+
logGroupProps?: LogGroupProps;
|
|
220
|
+
loggingFormat?: LoggingFormat;
|
|
221
|
+
runtime?: typeof Runtime.NODEJS_24_X;
|
|
222
|
+
architecture?: typeof Architecture.ARM_64;
|
|
223
|
+
handler?: string;
|
|
224
|
+
/**
|
|
225
|
+
* When function is being built the source maps are bundled without content for better performance.
|
|
226
|
+
* You should provide revision which is added to the description automatically for easier debugging.
|
|
227
|
+
*
|
|
228
|
+
* You can use cached `getRevision()` function which is exported in this file in order to get git commit id.
|
|
229
|
+
*/
|
|
230
|
+
revision: string;
|
|
220
231
|
};
|
|
221
|
-
|
|
232
|
+
/**
|
|
233
|
+
* This construct provides easy way of deploying Node.js function with opinionated defaults.
|
|
234
|
+
*
|
|
235
|
+
* You need to provide `entry` - TypeScript file which exports `handler` function.
|
|
236
|
+
*
|
|
237
|
+
* Entry file is being transpiled by `esbuild` to ESM format compatible with Node.js 24.
|
|
238
|
+
*
|
|
239
|
+
*/
|
|
240
|
+
declare class Nodejs24Function extends Function3 {
|
|
241
|
+
constructor(scope: Construct4, id: string, props: Nodejs24FunctionProps);
|
|
242
|
+
}
|
|
243
|
+
declare function getRevision(enforceGit: boolean): string;
|
|
244
|
+
export { getRevision, SqsWithDlqProps, SqsWithDlqLambdaInputProps, SqsWithDlq, Nodejs24Function, EmailAlarms, CloudFrontAccessLoggingSettingsProps, CloudFrontAccessLoggingSettings };
|
package/dist/index.js
CHANGED
|
@@ -242,54 +242,123 @@ class SqsWithDlq extends Construct3 {
|
|
|
242
242
|
}
|
|
243
243
|
// packages/cdk-constructs/src/nodejsFunction.ts
|
|
244
244
|
import { RemovalPolicy } from "aws-cdk-lib";
|
|
245
|
-
import { Architecture, LoggingFormat, Runtime } from "aws-cdk-lib/aws-lambda";
|
|
246
245
|
import {
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
246
|
+
Architecture,
|
|
247
|
+
Code,
|
|
248
|
+
Function,
|
|
249
|
+
LoggingFormat,
|
|
250
|
+
Runtime
|
|
251
|
+
} from "aws-cdk-lib/aws-lambda";
|
|
252
|
+
import {
|
|
253
|
+
Charset
|
|
250
254
|
} from "aws-cdk-lib/aws-lambda-nodejs";
|
|
251
255
|
import {
|
|
252
256
|
LogGroup,
|
|
253
257
|
RetentionDays
|
|
254
258
|
} from "aws-cdk-lib/aws-logs";
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
259
|
+
import { buildSync } from "esbuild";
|
|
260
|
+
import { execSync } from "node:child_process";
|
|
261
|
+
var __dirname = "/Users/ivan/data/work/github.com/beesolve/p/packages/packages/cdk-constructs/src";
|
|
262
|
+
|
|
263
|
+
class Nodejs24Function extends Function {
|
|
264
|
+
constructor(scope, id, props) {
|
|
265
|
+
const {
|
|
266
|
+
entry,
|
|
267
|
+
handler,
|
|
268
|
+
description = "",
|
|
269
|
+
logGroupProps = {
|
|
270
|
+
retention: RetentionDays.TWO_WEEKS,
|
|
271
|
+
removalPolicy: RemovalPolicy.DESTROY
|
|
272
|
+
},
|
|
273
|
+
loggingFormat = LoggingFormat.JSON,
|
|
274
|
+
revision = true,
|
|
275
|
+
...rest
|
|
276
|
+
} = props;
|
|
277
|
+
const outDir = `${__dirname}/cdk.out/bundling.${id}.beesolve-nodejs.${Date.now()}`;
|
|
278
|
+
const buildResult = buildSync({
|
|
279
|
+
entryPoints: [entry],
|
|
280
|
+
banner: {
|
|
281
|
+
js: `/* CommonJS polyfills */import { fileURLToPath } from 'node:url';import { createRequire } from 'node:module';const __filename = fileURLToPath(import.meta.url);const __dirname = fileURLToPath(new URL('.', import.meta.url));const require = createRequire(import.meta.url);/* end of CommonJS polyfills */`
|
|
282
|
+
},
|
|
283
|
+
charset: Charset.UTF8,
|
|
284
|
+
bundle: true,
|
|
285
|
+
external: [],
|
|
286
|
+
format: "esm",
|
|
287
|
+
keepNames: true,
|
|
288
|
+
mainFields: ["module", "main"],
|
|
289
|
+
minify: true,
|
|
290
|
+
sourcemap: "external",
|
|
291
|
+
target: "node24",
|
|
292
|
+
platform: "node",
|
|
293
|
+
resolveExtensions: [".ts", ".js", ".mjs", ".json"],
|
|
294
|
+
legalComments: "none",
|
|
295
|
+
splitting: true,
|
|
296
|
+
treeShaking: true,
|
|
297
|
+
outdir: outDir
|
|
298
|
+
});
|
|
299
|
+
if (buildResult.errors.length !== 0) {
|
|
300
|
+
throw new BuildError(buildResult.errors);
|
|
279
301
|
}
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
302
|
+
const fileName = entry.split("/").at(-1)?.replace(".ts", "");
|
|
303
|
+
const handlerName = `${fileName}.${handler ?? "handler"}`;
|
|
304
|
+
super(scope, id, {
|
|
305
|
+
...rest,
|
|
306
|
+
code: Code.fromAsset(outDir),
|
|
307
|
+
architecture: Architecture.ARM_64,
|
|
308
|
+
runtime: Runtime.NODEJS_24_X,
|
|
309
|
+
handler: handlerName,
|
|
310
|
+
logGroup: new LogGroup(scope, `${id}LogGroup`, logGroupProps),
|
|
311
|
+
loggingFormat,
|
|
312
|
+
description: `${description} (${revision})`
|
|
313
|
+
});
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
class BuildError extends Error {
|
|
318
|
+
constructor(messages) {
|
|
319
|
+
super(`Couldn't build the code.
|
|
320
|
+
|
|
321
|
+
${messages.map((message) => message.text).join(`
|
|
322
|
+
`)}`);
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
var revisionCache;
|
|
326
|
+
function getRevision(enforceGit) {
|
|
327
|
+
if (revisionCache == null) {
|
|
328
|
+
revisionCache = _getRevision();
|
|
329
|
+
}
|
|
330
|
+
return revisionCache;
|
|
331
|
+
function _getRevision() {
|
|
332
|
+
try {
|
|
333
|
+
const buffer = execSync("git rev-parse --short HEAD");
|
|
334
|
+
const shortCommitId = buffer.toString("utf-8").trim();
|
|
335
|
+
return `${shortCommitId}${isDirty() ? " - dirty" : ""}`;
|
|
336
|
+
} catch (error) {
|
|
337
|
+
if (enforceGit) {
|
|
338
|
+
throw new NotAGitRepositoryError;
|
|
339
|
+
}
|
|
340
|
+
return "cannot parse revision";
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
function isDirty() {
|
|
344
|
+
try {
|
|
345
|
+
execSync("git diff --quiet && git diff --cached --quiet");
|
|
346
|
+
return false;
|
|
347
|
+
} catch (error) {
|
|
348
|
+
return true;
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
class NotAGitRepositoryError extends Error {
|
|
354
|
+
constructor() {
|
|
355
|
+
super(`Cannot deploy without using git.`);
|
|
356
|
+
}
|
|
357
|
+
}
|
|
290
358
|
export {
|
|
291
|
-
|
|
359
|
+
getRevision,
|
|
292
360
|
SqsWithDlq,
|
|
361
|
+
Nodejs24Function,
|
|
293
362
|
EmailAlarms,
|
|
294
363
|
CloudFrontAccessLoggingSettings
|
|
295
364
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@beesolve/cdk-constructs",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.4",
|
|
4
4
|
"description": "",
|
|
5
5
|
"homepage": "https://github.com/beesolve/packages/tree/main/packages/cdk-constructs#readme",
|
|
6
6
|
"license": "MIT",
|
|
@@ -23,9 +23,10 @@
|
|
|
23
23
|
}
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"
|
|
26
|
+
"@beesolve/helpers": "0.1.4",
|
|
27
|
+
"aws-cdk-lib": "^2.238.0",
|
|
27
28
|
"constructs": "^10.4.5",
|
|
28
|
-
"
|
|
29
|
+
"esbuild": "^0.27.3"
|
|
29
30
|
},
|
|
30
31
|
"type": "module",
|
|
31
32
|
"exports": {
|