@lambda-kata/cdk 0.1.3-rc.28 → 0.1.3-rc.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.
@@ -15,8 +15,7 @@
15
15
  * @module aws-layer-manager
16
16
  */
17
17
  import { LambdaClientConfig } from '@aws-sdk/client-lambda';
18
- import { S3ClientConfig } from '@aws-sdk/client-s3';
19
- import { LayerCreationOptions, LayerInfo, LayerManager, LayerRequirements, LayerSearchOptions, Logger, MultiArchitectureDeploymentResult, NodejsLayerDeploymentOptions, NodejsLayerDeploymentResult } from './nodejs-layer-manager';
18
+ import { LayerManager, LayerInfo, LayerSearchOptions, LayerRequirements, LayerCreationOptions, Logger } from './nodejs-layer-manager';
20
19
  /**
21
20
  * Configuration options for AWSLayerManager.
22
21
  */
@@ -26,11 +25,6 @@ export interface AWSLayerManagerOptions {
26
25
  * If not provided, uses default AWS SDK configuration.
27
26
  */
28
27
  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;
34
28
  /**
35
29
  * Logger for debugging and monitoring.
36
30
  * If not provided, uses createDefaultLogger().
@@ -70,12 +64,6 @@ export interface AWSLayerManagerOptions {
70
64
  * Default: 2
71
65
  */
72
66
  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;
79
67
  }
80
68
  /**
81
69
  * AWS Lambda Layer Manager implementation using AWS SDK v3.
@@ -103,10 +91,9 @@ export interface AWSLayerManagerOptions {
103
91
  * }
104
92
  * });
105
93
  * ```
106
- */
94
+ */
107
95
  export declare class AWSLayerManager implements LayerManager {
108
96
  private readonly lambdaClient;
109
- private readonly s3Client;
110
97
  private readonly logger;
111
98
  private readonly maxLayerAge;
112
99
  private readonly maxRetries;
@@ -183,103 +170,6 @@ export declare class AWSLayerManager implements LayerManager {
183
170
  * @throws NodeRuntimeLayerError if creation fails
184
171
  */
185
172
  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;
283
173
  /**
284
174
  * Validates whether a layer meets the specified requirements.
285
175
  *
@@ -409,15 +299,11 @@ export declare class AWSLayerManager implements LayerManager {
409
299
  */
410
300
  private createTempDirectory;
411
301
  /**
412
- * Extracts Node.js binary from AWS Lambda Docker image with resource tracking.
413
- *
414
- * Uses ONLY AWS Lambda Docker images to extract the Node.js binary from the
415
- * official Lambda runtime environment. This ensures compatibility with the
416
- * Lambda execution environment while extracting only the minimal binary needed.
302
+ * Extracts Node.js binary from AWS Lambda Docker container with resource tracking.
417
303
  *
418
- * CRITICAL: Uses ONLY AWS Lambda Docker images as required by user specifications.
419
- * Docker image format: public.ecr.aws/lambda/nodejs:{version}-{arch}
420
- * Extracts ONLY: /var/lang/bin/node
304
+ * Enhanced version that tracks Docker containers for cleanup on failure.
305
+ * Uses Docker to run the AWS Lambda runtime image and copy the Node.js
306
+ * binary to the local filesystem for packaging in the layer.
421
307
  *
422
308
  * @param nodeVersion - The Node.js version (e.g., "20.10.0")
423
309
  * @param architecture - The target architecture
@@ -427,75 +313,14 @@ export declare class AWSLayerManager implements LayerManager {
427
313
  * @throws NodeRuntimeLayerError if extraction fails
428
314
  */
429
315
  private extractNodeBinaryFromDockerWithTracking;
430
- /**
431
- * Optimizes Node.js binary to reduce size while preserving functionality.
432
- *
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 250MB limit
439
- *
440
- * @param originalBinaryPath - Path to the original Node.js binary
441
- * @param tempDir - Temporary directory for optimization work
442
- * @returns Promise resolving to path of optimized binary
443
- * @throws Error if optimization fails and original exceeds 250MB limit
444
- */
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;
469
- /**
470
- * Verifies that a Node.js binary is functional after optimization.
471
- *
472
- * Runs basic Node.js commands to ensure the binary works correctly.
473
- * This prevents shipping broken binaries after optimization.
474
- *
475
- * @param binaryPath - Path to the Node.js binary to verify
476
- * @throws Error if verification fails
477
- */
478
- private verifyNodeBinary;
479
- /**
480
- * Verifies Node.js binary with graceful fallback for spawn errors.
481
- *
482
- * This method attempts full verification but falls back to basic checks
483
- * if spawn fails (e.g., error -8). This prevents blocking deployment for
484
- * binaries that are valid but fail verification due to system issues.
485
- *
486
- * @param binaryPath - Path to the Node.js binary to verify
487
- * @returns Promise resolving to verification result with success flag and optional error
488
- */
489
- private verifyNodeBinaryWithFallback;
490
316
  /**
491
317
  * Creates the proper Lambda Layer directory structure.
492
318
  *
493
- * Lambda Layers for Node.js binary should use minimal structure:
494
- * - bin/node (uncompressed binary)
495
- * - bin/node.gz (compressed binary with decompression script)
319
+ * Lambda Layers must follow a specific directory structure:
320
+ * - /opt/nodejs/bin/ for Node.js binaries
496
321
  *
497
322
  * @param tempDir - Base temporary directory
498
- * @param nodeBinaryPath - Path to the Node.js binary (may be compressed)
323
+ * @param nodeBinaryPath - Path to the Node.js binary
499
324
  * @returns Promise resolving to the layer directory path
500
325
  * @throws Error if directory creation fails
501
326
  */
@@ -521,10 +346,7 @@ export declare class AWSLayerManager implements LayerManager {
521
346
  */
522
347
  private calculateDirectorySize;
523
348
  /**
524
- * Fallback ZIP creation using system zip command with streaming.
525
- *
526
- * This method uses the system 'zip' command which handles large files
527
- * efficiently without loading them into memory.
349
+ * Fallback ZIP creation using system zip command.
528
350
  *
529
351
  * @param layerDir - Directory containing the layer contents
530
352
  * @param zipFilePath - Target ZIP file path
@@ -597,9 +419,6 @@ export declare class AWSLayerManager implements LayerManager {
597
419
  /**
598
420
  * Executes a system command with timeout and error handling.
599
421
  *
600
- * Enhanced with EPIPE error handling to prevent broken pipe errors
601
- * when child process terminates unexpectedly.
602
- *
603
422
  * @param command - Command to execute
604
423
  * @param args - Command arguments
605
424
  * @param options - Execution options including working directory
@@ -1,4 +1,4 @@
1
- import { Logger, NodeVersionInfo, RuntimeDetector } from './nodejs-layer-manager';
1
+ import { RuntimeDetector, NodeVersionInfo, Logger } from './nodejs-layer-manager';
2
2
  /**
3
3
  * Configuration options for DockerRuntimeDetector.
4
4
  */
@@ -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, NodejsLayerDeploymentOptions, NodejsLayerDeploymentResult, MultiArchitectureDeploymentResult, } from './nodejs-layer-manager';
26
+ export { EnsureNodeRuntimeLayerOptions, EnsureNodeRuntimeLayerResult, NodeVersionInfo, LayerInfo, LayerSearchOptions, LayerRequirements, LayerCreationOptions, Logger, RuntimeDetector, LayerManager, ErrorCodes, NodeRuntimeLayerError, VersionCacheEntry, LayerMetadata, } 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';
@@ -110,13 +110,12 @@ export declare function kata<T extends NodejsFunction | LambdaFunction>(lambda:
110
110
  *
111
111
  * @param lambda - The Node.js Lambda function to transform
112
112
  * @param accountId - The AWS account ID to use for licensing check
113
- * @param region - The AWS region for deployment (from Stack.of(lambda).region)
114
113
  * @param props - Optional configuration for the transformation
115
114
  * @returns Promise resolving to the transformation result
116
115
  *
117
116
  * @internal
118
117
  */
119
- export declare function kataWithAccountId<T extends NodejsFunction | LambdaFunction>(lambda: T, accountId: string, region: string, props?: KataWrapperOptions): Promise<KataResult>;
118
+ export declare function kataWithAccountId<T extends NodejsFunction | LambdaFunction>(lambda: T, accountId: string, props?: KataWrapperOptions): Promise<KataResult>;
120
119
  /**
121
120
  * Gets the original runtime from a Lambda function before transformation.
122
121
  *
@@ -275,27 +275,6 @@ 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>;
299
278
  /**
300
279
  * Validates whether a layer meets the specified requirements.
301
280
  *
@@ -438,110 +417,3 @@ export interface LayerMetadata {
438
417
  */
439
418
  licenseInfo?: string;
440
419
  }
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.28",
3
+ "version": "0.1.3-rc.4",
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": "yarn run build && npm publish --access public"
21
+ "npm:publish": "npm publish --access public"
22
22
  },
23
23
  "files": [
24
24
  "out/dist/**/*",
@@ -54,7 +54,6 @@
54
54
  },
55
55
  "dependencies": {
56
56
  "@aws-sdk/client-lambda": "^3.500.0",
57
- "@aws-sdk/client-s3": "^3.500.0",
58
57
  "@aws-sdk/client-sts": "^3.500.0",
59
58
  "dotenv": "^17.2.3",
60
59
  "reflect-metadata": "^0.2.2"
@@ -75,4 +74,4 @@
75
74
  "tsc-alias": "^1.8.16",
76
75
  "typescript": "^5.3.3"
77
76
  }
78
- }
77
+ }