@lambda-kata/cdk 0.1.3-rc.15 → 0.1.3-rc.17
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/out/dist/index.js +148 -61
- package/out/tsc/src/aws-layer-manager.d.ts +141 -6
- package/out/tsc/src/index.d.ts +1 -1
- package/out/tsc/src/nodejs-layer-manager.d.ts +128 -0
- package/package.json +3 -2
|
@@ -15,7 +15,8 @@
|
|
|
15
15
|
* @module aws-layer-manager
|
|
16
16
|
*/
|
|
17
17
|
import { LambdaClientConfig } from '@aws-sdk/client-lambda';
|
|
18
|
-
import {
|
|
18
|
+
import { S3ClientConfig } from '@aws-sdk/client-s3';
|
|
19
|
+
import { LayerCreationOptions, LayerInfo, LayerManager, LayerRequirements, LayerSearchOptions, Logger, NodejsLayerDeploymentOptions, NodejsLayerDeploymentResult, MultiArchitectureDeploymentResult } from './nodejs-layer-manager';
|
|
19
20
|
/**
|
|
20
21
|
* Configuration options for AWSLayerManager.
|
|
21
22
|
*/
|
|
@@ -25,6 +26,11 @@ export interface AWSLayerManagerOptions {
|
|
|
25
26
|
* If not provided, uses default AWS SDK configuration.
|
|
26
27
|
*/
|
|
27
28
|
awsSdkConfig?: LambdaClientConfig;
|
|
29
|
+
/**
|
|
30
|
+
* AWS SDK configuration for S3 client.
|
|
31
|
+
* If not provided, uses the same configuration as Lambda client.
|
|
32
|
+
*/
|
|
33
|
+
s3SdkConfig?: S3ClientConfig;
|
|
28
34
|
/**
|
|
29
35
|
* Logger for debugging and monitoring.
|
|
30
36
|
* If not provided, uses createDefaultLogger().
|
|
@@ -64,6 +70,12 @@ export interface AWSLayerManagerOptions {
|
|
|
64
70
|
* Default: 2
|
|
65
71
|
*/
|
|
66
72
|
circuitBreakerSuccessThreshold?: number;
|
|
73
|
+
/**
|
|
74
|
+
* Enable S3 support for large layer uploads.
|
|
75
|
+
* If true, creates S3Client for handling layers >50MB.
|
|
76
|
+
* Default: true
|
|
77
|
+
*/
|
|
78
|
+
enableS3Support?: boolean;
|
|
67
79
|
}
|
|
68
80
|
/**
|
|
69
81
|
* AWS Lambda Layer Manager implementation using AWS SDK v3.
|
|
@@ -94,6 +106,7 @@ export interface AWSLayerManagerOptions {
|
|
|
94
106
|
*/
|
|
95
107
|
export declare class AWSLayerManager implements LayerManager {
|
|
96
108
|
private readonly lambdaClient;
|
|
109
|
+
private readonly s3Client;
|
|
97
110
|
private readonly logger;
|
|
98
111
|
private readonly maxLayerAge;
|
|
99
112
|
private readonly maxRetries;
|
|
@@ -170,6 +183,103 @@ export declare class AWSLayerManager implements LayerManager {
|
|
|
170
183
|
* @throws NodeRuntimeLayerError if creation fails
|
|
171
184
|
*/
|
|
172
185
|
private performLayerCreation;
|
|
186
|
+
/**
|
|
187
|
+
* Deploys a pre-built Node.js Lambda Layer from ZIP file.
|
|
188
|
+
*
|
|
189
|
+
* This method bypasses Docker binary extraction and deploys existing
|
|
190
|
+
* layer ZIP files directly to AWS Lambda. Handles large layers via S3
|
|
191
|
+
* temporary bucket upload with automatic cleanup.
|
|
192
|
+
*
|
|
193
|
+
* Process:
|
|
194
|
+
* 1. Validate input parameters and architecture
|
|
195
|
+
* 2. Search for existing layer ZIP files with fallback naming patterns
|
|
196
|
+
* 3. Read and validate layer ZIP file size
|
|
197
|
+
* 4. Deploy via direct upload (<50MB) or S3 upload (≥50MB)
|
|
198
|
+
* 5. Clean up temporary S3 resources if used
|
|
199
|
+
* 6. Return deployment result with layer ARN and metadata
|
|
200
|
+
*
|
|
201
|
+
* @param options - Deployment configuration
|
|
202
|
+
* @returns Promise resolving to deployment result
|
|
203
|
+
* @throws NodeRuntimeLayerError if deployment fails
|
|
204
|
+
*/
|
|
205
|
+
deployNodejsLayer(options: NodejsLayerDeploymentOptions): Promise<NodejsLayerDeploymentResult>;
|
|
206
|
+
/**
|
|
207
|
+
* Deploys Node.js layers for all supported architectures.
|
|
208
|
+
*
|
|
209
|
+
* Attempts to deploy layers for both arm64 and x86_64 architectures,
|
|
210
|
+
* continuing on individual failures to maximize successful deployments.
|
|
211
|
+
* This matches the behavior of the Python deployment script.
|
|
212
|
+
*
|
|
213
|
+
* @param options - Base deployment configuration (architecture will be overridden)
|
|
214
|
+
* @returns Promise resolving to multi-architecture deployment results
|
|
215
|
+
*/
|
|
216
|
+
deployAllArchitectures(options: Omit<NodejsLayerDeploymentOptions, 'architecture'>): Promise<MultiArchitectureDeploymentResult>;
|
|
217
|
+
/**
|
|
218
|
+
* Generates a standard layer name for the given architecture.
|
|
219
|
+
*
|
|
220
|
+
* @param architecture - Target architecture
|
|
221
|
+
* @returns Standard layer name following the pattern: nodejs-18-{architecture}
|
|
222
|
+
*/
|
|
223
|
+
private generateLayerName;
|
|
224
|
+
/**
|
|
225
|
+
* Searches for layer ZIP files with fallback naming patterns.
|
|
226
|
+
*
|
|
227
|
+
* Implements the same search logic as the Python script with multiple
|
|
228
|
+
* naming conventions for maximum compatibility.
|
|
229
|
+
*
|
|
230
|
+
* @param architecture - Target architecture
|
|
231
|
+
* @param baseDirectory - Directory to search in
|
|
232
|
+
* @returns Promise resolving to ZIP file path or null if not found
|
|
233
|
+
*/
|
|
234
|
+
private findLayerZipFile;
|
|
235
|
+
/**
|
|
236
|
+
* Deploys a large layer (>50MB) via S3 temporary bucket.
|
|
237
|
+
*
|
|
238
|
+
* Creates a temporary S3 bucket, uploads the layer, publishes from S3,
|
|
239
|
+
* and cleans up the bucket. Implements the same logic as the Python script.
|
|
240
|
+
*
|
|
241
|
+
* @param layerName - Name of the layer
|
|
242
|
+
* @param layerContent - ZIP file content
|
|
243
|
+
* @param architecture - Target architecture
|
|
244
|
+
* @param region - AWS region
|
|
245
|
+
* @param description - Optional layer description
|
|
246
|
+
* @param zipFilePath - Original ZIP file path for metadata
|
|
247
|
+
* @returns Promise resolving to deployment result
|
|
248
|
+
*/
|
|
249
|
+
private deployLargeLayerViaS3;
|
|
250
|
+
/**
|
|
251
|
+
* Deploys a layer directly to Lambda (for layers <50MB).
|
|
252
|
+
*
|
|
253
|
+
* @param layerName - Name of the layer
|
|
254
|
+
* @param layerContent - ZIP file content
|
|
255
|
+
* @param architecture - Target architecture
|
|
256
|
+
* @param description - Optional layer description
|
|
257
|
+
* @param zipFilePath - Original ZIP file path for metadata
|
|
258
|
+
* @returns Promise resolving to deployment result
|
|
259
|
+
*/
|
|
260
|
+
private deployLayerDirect;
|
|
261
|
+
/**
|
|
262
|
+
* Creates an S3 bucket for temporary layer storage.
|
|
263
|
+
*
|
|
264
|
+
* @param bucketName - Name of the bucket to create
|
|
265
|
+
* @param region - AWS region
|
|
266
|
+
*/
|
|
267
|
+
private createS3Bucket;
|
|
268
|
+
/**
|
|
269
|
+
* Uploads layer content to S3.
|
|
270
|
+
*
|
|
271
|
+
* @param bucketName - S3 bucket name
|
|
272
|
+
* @param keyName - S3 object key
|
|
273
|
+
* @param layerContent - Layer ZIP content
|
|
274
|
+
*/
|
|
275
|
+
private uploadLayerToS3;
|
|
276
|
+
/**
|
|
277
|
+
* Cleans up S3 resources (bucket and objects).
|
|
278
|
+
*
|
|
279
|
+
* @param bucketName - S3 bucket name
|
|
280
|
+
* @param keyName - S3 object key
|
|
281
|
+
*/
|
|
282
|
+
private cleanupS3Resources;
|
|
173
283
|
/**
|
|
174
284
|
* Validates whether a layer meets the specified requirements.
|
|
175
285
|
*
|
|
@@ -320,17 +430,42 @@ export declare class AWSLayerManager implements LayerManager {
|
|
|
320
430
|
/**
|
|
321
431
|
* Optimizes Node.js binary to reduce size while preserving functionality.
|
|
322
432
|
*
|
|
323
|
-
*
|
|
324
|
-
* 1. Strip debug symbols using 'strip' command (
|
|
325
|
-
* 2.
|
|
326
|
-
* 3.
|
|
433
|
+
* Multi-stage optimization approach:
|
|
434
|
+
* 1. Strip debug symbols using 'strip' command (30-50% reduction)
|
|
435
|
+
* 2. UPX compression if still >50MB (50-70% additional reduction)
|
|
436
|
+
* 3. System Node.js replacement if still >60MB
|
|
437
|
+
* 4. Verify binary functionality after each stage
|
|
438
|
+
* 5. Fallback to original if within 80MB limit
|
|
327
439
|
*
|
|
328
440
|
* @param originalBinaryPath - Path to the original Node.js binary
|
|
329
441
|
* @param tempDir - Temporary directory for optimization work
|
|
330
442
|
* @returns Promise resolving to path of optimized binary
|
|
331
|
-
* @throws Error if optimization fails and
|
|
443
|
+
* @throws Error if optimization fails and original exceeds 80MB limit
|
|
332
444
|
*/
|
|
333
445
|
private optimizeNodeBinary;
|
|
446
|
+
/**
|
|
447
|
+
* Attempts strip-based optimization with progressive aggressiveness.
|
|
448
|
+
*
|
|
449
|
+
* @param originalBinaryPath - Path to original binary
|
|
450
|
+
* @param tempDir - Working directory
|
|
451
|
+
* @returns Path to stripped binary or original if stripping fails
|
|
452
|
+
*/
|
|
453
|
+
private tryStripOptimization;
|
|
454
|
+
/**
|
|
455
|
+
* Attempts UPX compression optimization.
|
|
456
|
+
*
|
|
457
|
+
* @param binaryPath - Path to binary to compress
|
|
458
|
+
* @param tempDir - Working directory
|
|
459
|
+
* @returns Path to compressed binary or null if UPX unavailable/fails
|
|
460
|
+
*/
|
|
461
|
+
private tryUPXOptimization;
|
|
462
|
+
/**
|
|
463
|
+
* Attempts to use system Node.js binary as replacement.
|
|
464
|
+
*
|
|
465
|
+
* @param tempDir - Working directory
|
|
466
|
+
* @returns Path to system Node.js copy or null if unavailable/unsuitable
|
|
467
|
+
*/
|
|
468
|
+
private trySystemNodeReplacement;
|
|
334
469
|
/**
|
|
335
470
|
* Verifies that a Node.js binary is functional after optimization.
|
|
336
471
|
*
|
package/out/tsc/src/index.d.ts
CHANGED
|
@@ -23,7 +23,7 @@ export { MockLicensingService, createMockLicensingService, } from './mock-licens
|
|
|
23
23
|
export { resolveAccountId, resolveAccountIdWithSource, isValidAccountIdFormat, AccountResolutionError, AccountResolutionResult, AccountResolverOptions, } from './account-resolver';
|
|
24
24
|
export { kata, kataWithAccountId, applyTransformation, handleUnlicensed, isKataTransformed, getKataPromise, KataWrapperOptions, KataResult, } from './kata-wrapper';
|
|
25
25
|
export { createKataConfigLayer, generateConfigContent, KataConfigLayerProps, CONFIG_DIR_NAME, CONFIG_FILE_NAME, HANDLER_CONFIG_KEY, } from './config-layer';
|
|
26
|
-
export { EnsureNodeRuntimeLayerOptions, EnsureNodeRuntimeLayerResult, NodeVersionInfo, LayerInfo, LayerSearchOptions, LayerRequirements, LayerCreationOptions, Logger, RuntimeDetector, LayerManager, ErrorCodes, NodeRuntimeLayerError, VersionCacheEntry, LayerMetadata, } from './nodejs-layer-manager';
|
|
26
|
+
export { EnsureNodeRuntimeLayerOptions, EnsureNodeRuntimeLayerResult, NodeVersionInfo, LayerInfo, LayerSearchOptions, LayerRequirements, LayerCreationOptions, Logger, RuntimeDetector, LayerManager, ErrorCodes, NodeRuntimeLayerError, VersionCacheEntry, LayerMetadata, NodejsLayerDeploymentOptions, NodejsLayerDeploymentResult, MultiArchitectureDeploymentResult, } from './nodejs-layer-manager';
|
|
27
27
|
export { DockerRuntimeDetector, DockerRuntimeDetectorOptions, } from './docker-runtime-detector';
|
|
28
28
|
export { AWSLayerManager, AWSLayerManagerOptions, } from './aws-layer-manager';
|
|
29
29
|
export { NoOpLogger, ConsoleLogger, createDefaultLogger, OperationTimer, } from './logger';
|
|
@@ -275,6 +275,27 @@ export interface LayerManager {
|
|
|
275
275
|
* @throws NodeRuntimeLayerError if creation fails
|
|
276
276
|
*/
|
|
277
277
|
createNodeLayer(options: LayerCreationOptions): Promise<LayerInfo>;
|
|
278
|
+
/**
|
|
279
|
+
* Deploys a pre-built Node.js Lambda Layer from ZIP file.
|
|
280
|
+
*
|
|
281
|
+
* This method bypasses Docker binary extraction and deploys existing
|
|
282
|
+
* layer ZIP files directly to AWS Lambda. Handles large layers via S3.
|
|
283
|
+
*
|
|
284
|
+
* @param options - Deployment configuration
|
|
285
|
+
* @returns Promise resolving to deployment result
|
|
286
|
+
* @throws NodeRuntimeLayerError if deployment fails
|
|
287
|
+
*/
|
|
288
|
+
deployNodejsLayer(options: NodejsLayerDeploymentOptions): Promise<NodejsLayerDeploymentResult>;
|
|
289
|
+
/**
|
|
290
|
+
* Deploys Node.js layers for all supported architectures.
|
|
291
|
+
*
|
|
292
|
+
* Attempts to deploy layers for both arm64 and x86_64 architectures,
|
|
293
|
+
* continuing on individual failures to maximize successful deployments.
|
|
294
|
+
*
|
|
295
|
+
* @param options - Base deployment configuration (architecture will be overridden)
|
|
296
|
+
* @returns Promise resolving to multi-architecture deployment results
|
|
297
|
+
*/
|
|
298
|
+
deployAllArchitectures(options: Omit<NodejsLayerDeploymentOptions, 'architecture'>): Promise<MultiArchitectureDeploymentResult>;
|
|
278
299
|
/**
|
|
279
300
|
* Validates whether a layer meets the specified requirements.
|
|
280
301
|
*
|
|
@@ -417,3 +438,110 @@ export interface LayerMetadata {
|
|
|
417
438
|
*/
|
|
418
439
|
licenseInfo?: string;
|
|
419
440
|
}
|
|
441
|
+
/**
|
|
442
|
+
* Configuration options for deploying pre-built Node.js Lambda Layers.
|
|
443
|
+
*
|
|
444
|
+
* Used to deploy existing layer ZIP files instead of creating layers from Docker images.
|
|
445
|
+
* This bypasses the binary extraction process that can fail with large Node.js binaries.
|
|
446
|
+
*/
|
|
447
|
+
export interface NodejsLayerDeploymentOptions {
|
|
448
|
+
/**
|
|
449
|
+
* The AWS region where the layer should be deployed.
|
|
450
|
+
*/
|
|
451
|
+
region: string;
|
|
452
|
+
/**
|
|
453
|
+
* Optional AWS profile name for authentication.
|
|
454
|
+
* If not provided, uses default AWS credentials.
|
|
455
|
+
*/
|
|
456
|
+
profile?: string;
|
|
457
|
+
/**
|
|
458
|
+
* The target architecture for deployment.
|
|
459
|
+
* If not specified, defaults to 'arm64'.
|
|
460
|
+
*/
|
|
461
|
+
architecture?: 'arm64' | 'x86_64';
|
|
462
|
+
/**
|
|
463
|
+
* Base directory to search for layer ZIP files.
|
|
464
|
+
* Defaults to current working directory.
|
|
465
|
+
*/
|
|
466
|
+
baseDirectory?: string;
|
|
467
|
+
/**
|
|
468
|
+
* Custom layer name override.
|
|
469
|
+
* If not provided, uses standard naming: nodejs-18-{architecture}
|
|
470
|
+
*/
|
|
471
|
+
layerName?: string;
|
|
472
|
+
/**
|
|
473
|
+
* Custom layer description.
|
|
474
|
+
* If not provided, generates standard description.
|
|
475
|
+
*/
|
|
476
|
+
description?: string;
|
|
477
|
+
}
|
|
478
|
+
/**
|
|
479
|
+
* Result of Node.js layer deployment operation.
|
|
480
|
+
*
|
|
481
|
+
* Contains information about the deployed layer and deployment metadata.
|
|
482
|
+
*/
|
|
483
|
+
export interface NodejsLayerDeploymentResult {
|
|
484
|
+
/**
|
|
485
|
+
* The full ARN of the deployed layer version.
|
|
486
|
+
*/
|
|
487
|
+
layerVersionArn: string;
|
|
488
|
+
/**
|
|
489
|
+
* The base ARN of the layer (without version).
|
|
490
|
+
*/
|
|
491
|
+
layerArn: string;
|
|
492
|
+
/**
|
|
493
|
+
* The name of the deployed layer.
|
|
494
|
+
*/
|
|
495
|
+
layerName: string;
|
|
496
|
+
/**
|
|
497
|
+
* The version number of the deployed layer.
|
|
498
|
+
*/
|
|
499
|
+
version: number;
|
|
500
|
+
/**
|
|
501
|
+
* The architecture of the deployed layer.
|
|
502
|
+
*/
|
|
503
|
+
architecture: 'arm64' | 'x86_64';
|
|
504
|
+
/**
|
|
505
|
+
* The size of the deployed layer ZIP file in bytes.
|
|
506
|
+
*/
|
|
507
|
+
layerSize: number;
|
|
508
|
+
/**
|
|
509
|
+
* The path to the ZIP file that was deployed.
|
|
510
|
+
*/
|
|
511
|
+
zipFilePath: string;
|
|
512
|
+
/**
|
|
513
|
+
* Whether the layer was uploaded via S3 (true) or direct upload (false).
|
|
514
|
+
*/
|
|
515
|
+
uploadedViaS3: boolean;
|
|
516
|
+
}
|
|
517
|
+
/**
|
|
518
|
+
* Result of deploying layers for all architectures.
|
|
519
|
+
*
|
|
520
|
+
* Contains deployment results for each architecture attempted.
|
|
521
|
+
*/
|
|
522
|
+
export interface MultiArchitectureDeploymentResult {
|
|
523
|
+
/**
|
|
524
|
+
* Deployment results by architecture.
|
|
525
|
+
* Key is architecture name, value is result or null if deployment failed.
|
|
526
|
+
*/
|
|
527
|
+
results: Record<'arm64' | 'x86_64', NodejsLayerDeploymentResult | null>;
|
|
528
|
+
/**
|
|
529
|
+
* Overall success status.
|
|
530
|
+
* True if at least one architecture deployed successfully.
|
|
531
|
+
*/
|
|
532
|
+
success: boolean;
|
|
533
|
+
/**
|
|
534
|
+
* Summary of successful deployments.
|
|
535
|
+
*/
|
|
536
|
+
successful: Array<{
|
|
537
|
+
architecture: 'arm64' | 'x86_64';
|
|
538
|
+
layerVersionArn: string;
|
|
539
|
+
}>;
|
|
540
|
+
/**
|
|
541
|
+
* Summary of failed deployments.
|
|
542
|
+
*/
|
|
543
|
+
failed: Array<{
|
|
544
|
+
architecture: 'arm64' | 'x86_64';
|
|
545
|
+
error: string;
|
|
546
|
+
}>;
|
|
547
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lambda-kata/cdk",
|
|
3
|
-
"version": "0.1.3-rc.
|
|
3
|
+
"version": "0.1.3-rc.17",
|
|
4
4
|
"description": "AWS CDK integration for Lambda Kata - Node.js Lambdas running via Lambda Kata runtime",
|
|
5
5
|
"main": "out/dist/index.js",
|
|
6
6
|
"types": "out/tsc/src/index.d.ts",
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
"docs": "yarn run docs:md && yarn run docs:html",
|
|
19
19
|
"docs:md": "typedoc --options ./docs/docs.config/typedoc.md.json",
|
|
20
20
|
"docs:html": "typedoc --options ./docs/docs.config/typedoc.html.json",
|
|
21
|
-
"npm:publish": "npm publish --access public"
|
|
21
|
+
"npm:publish": "yarn run build && npm publish --access public"
|
|
22
22
|
},
|
|
23
23
|
"files": [
|
|
24
24
|
"out/dist/**/*",
|
|
@@ -54,6 +54,7 @@
|
|
|
54
54
|
},
|
|
55
55
|
"dependencies": {
|
|
56
56
|
"@aws-sdk/client-lambda": "^3.500.0",
|
|
57
|
+
"@aws-sdk/client-s3": "^3.500.0",
|
|
57
58
|
"@aws-sdk/client-sts": "^3.500.0",
|
|
58
59
|
"dotenv": "^17.2.3",
|
|
59
60
|
"reflect-metadata": "^0.2.2"
|