@lambda-kata/cdk 0.1.3-rc.2 → 0.1.3-rc.21
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 +203 -57
- package/out/tsc/src/aws-layer-manager.d.ts +640 -0
- package/out/tsc/src/docker-runtime-detector.d.ts +168 -0
- package/out/tsc/src/ensure-node-runtime-layer.d.ts +42 -0
- package/out/tsc/src/index.d.ts +5 -0
- package/out/tsc/src/kata-wrapper.d.ts +27 -14
- package/out/tsc/src/logger.d.ts +88 -0
- package/out/tsc/src/nodejs-layer-manager.d.ts +547 -0
- package/package.json +8 -6
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
import { Logger, NodeVersionInfo, RuntimeDetector } from './nodejs-layer-manager';
|
|
2
|
+
/**
|
|
3
|
+
* Configuration options for DockerRuntimeDetector.
|
|
4
|
+
*/
|
|
5
|
+
export interface DockerRuntimeDetectorOptions {
|
|
6
|
+
/**
|
|
7
|
+
* Cache TTL in milliseconds. Default: 1 hour (3600000ms)
|
|
8
|
+
*/
|
|
9
|
+
cacheTtl?: number;
|
|
10
|
+
/**
|
|
11
|
+
* Docker command timeout in milliseconds. Default: 60 seconds (60000ms)
|
|
12
|
+
*/
|
|
13
|
+
dockerTimeout?: number;
|
|
14
|
+
/**
|
|
15
|
+
* Logger for debugging and monitoring. Default: createDefaultLogger()
|
|
16
|
+
*/
|
|
17
|
+
logger?: Logger;
|
|
18
|
+
/**
|
|
19
|
+
* Whether to enable fallback to known version mappings when Docker fails.
|
|
20
|
+
* Default: true
|
|
21
|
+
*/
|
|
22
|
+
enableFallback?: boolean;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Docker-based implementation of RuntimeDetector.
|
|
26
|
+
*
|
|
27
|
+
* Uses official AWS Lambda runtime Docker images to detect exact Node.js versions.
|
|
28
|
+
* Implements caching to avoid repeated Docker operations and provides fallback
|
|
29
|
+
* version mappings when Docker is unavailable.
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* ```typescript
|
|
33
|
+
* const detector = new DockerRuntimeDetector();
|
|
34
|
+
* const versionInfo = await detector.detectNodeVersion('nodejs20.x', 'x86_64');
|
|
35
|
+
* console.log(`Node.js version: ${versionInfo.version}`);
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
export declare class DockerRuntimeDetector implements RuntimeDetector {
|
|
39
|
+
private readonly versionCache;
|
|
40
|
+
private readonly cacheTtl;
|
|
41
|
+
private readonly dockerTimeout;
|
|
42
|
+
private readonly logger;
|
|
43
|
+
private readonly enableFallback;
|
|
44
|
+
/**
|
|
45
|
+
* Known fallback version mappings for when Docker is unavailable.
|
|
46
|
+
* These are based on AWS Lambda runtime documentation and should be
|
|
47
|
+
* updated when AWS releases new runtime versions.
|
|
48
|
+
*/
|
|
49
|
+
private static readonly FALLBACK_VERSIONS;
|
|
50
|
+
/**
|
|
51
|
+
* Supported AWS Lambda Node.js runtimes.
|
|
52
|
+
*/
|
|
53
|
+
private static readonly SUPPORTED_RUNTIMES;
|
|
54
|
+
/**
|
|
55
|
+
* Supported architectures.
|
|
56
|
+
*/
|
|
57
|
+
private static readonly SUPPORTED_ARCHITECTURES;
|
|
58
|
+
constructor(options?: DockerRuntimeDetectorOptions);
|
|
59
|
+
/**
|
|
60
|
+
* Detects the exact Node.js version for a given runtime and architecture.
|
|
61
|
+
*
|
|
62
|
+
* First checks the cache for existing version information. If not cached or expired,
|
|
63
|
+
* attempts to detect the version using Docker. Falls back to known version mappings
|
|
64
|
+
* if Docker operations fail and fallback is enabled.
|
|
65
|
+
*
|
|
66
|
+
* @param runtimeName - The AWS Lambda runtime (e.g., "nodejs20.x")
|
|
67
|
+
* @param architecture - The target architecture ("x86_64" or "arm64")
|
|
68
|
+
* @returns Promise resolving to Node.js version information
|
|
69
|
+
* @throws NodeRuntimeLayerError if detection fails
|
|
70
|
+
*/
|
|
71
|
+
detectNodeVersion(runtimeName: string, architecture: string): Promise<NodeVersionInfo>;
|
|
72
|
+
/**
|
|
73
|
+
* Validates input parameters for runtime name and architecture.
|
|
74
|
+
*
|
|
75
|
+
* @param runtimeName - The runtime name to validate
|
|
76
|
+
* @param architecture - The architecture to validate
|
|
77
|
+
* @throws NodeRuntimeLayerError if inputs are invalid
|
|
78
|
+
*/
|
|
79
|
+
private validateInputs;
|
|
80
|
+
/**
|
|
81
|
+
* Retrieves cached version information if available and not expired.
|
|
82
|
+
*
|
|
83
|
+
* @param cacheKey - The cache key to look up
|
|
84
|
+
* @returns Cached version entry if valid, null otherwise
|
|
85
|
+
*/
|
|
86
|
+
private getCachedVersion;
|
|
87
|
+
/**
|
|
88
|
+
* Caches version information with TTL.
|
|
89
|
+
*
|
|
90
|
+
* @param cacheKey - The cache key to store under
|
|
91
|
+
* @param versionInfo - The version information to cache
|
|
92
|
+
*/
|
|
93
|
+
private cacheVersion;
|
|
94
|
+
/**
|
|
95
|
+
* Detects Node.js version using Docker by pulling AWS Lambda runtime image
|
|
96
|
+
* and executing `node --version` within a container.
|
|
97
|
+
*
|
|
98
|
+
* @param runtimeName - The AWS Lambda runtime name
|
|
99
|
+
* @param architecture - The target architecture
|
|
100
|
+
* @returns Promise resolving to version information
|
|
101
|
+
* @throws NodeRuntimeLayerError if Docker operations fail
|
|
102
|
+
*/
|
|
103
|
+
private detectVersionFromDocker;
|
|
104
|
+
/**
|
|
105
|
+
* Builds the Docker image name for AWS Lambda runtime.
|
|
106
|
+
*
|
|
107
|
+
* @param runtimeName - The AWS Lambda runtime name (e.g., "nodejs20.x")
|
|
108
|
+
* @param architecture - The target architecture
|
|
109
|
+
* @returns Docker image name (e.g., "public.ecr.aws/lambda/nodejs:20-x86_64")
|
|
110
|
+
*/
|
|
111
|
+
private buildDockerImageName;
|
|
112
|
+
/**
|
|
113
|
+
* Checks if Docker image exists locally before pulling.
|
|
114
|
+
*
|
|
115
|
+
* @param dockerImage - The Docker image to check
|
|
116
|
+
* @returns Promise<boolean> - true if image exists locally
|
|
117
|
+
*/
|
|
118
|
+
private checkDockerImageExists;
|
|
119
|
+
/**
|
|
120
|
+
* Pulls a Docker image using the docker pull command.
|
|
121
|
+
* Optimized to skip pull if image already exists locally.
|
|
122
|
+
*
|
|
123
|
+
* @param dockerImage - The Docker image to pull
|
|
124
|
+
* @returns Promise that resolves when the image is pulled
|
|
125
|
+
* @throws Error if docker pull fails
|
|
126
|
+
*/
|
|
127
|
+
private pullDockerImage;
|
|
128
|
+
/**
|
|
129
|
+
* Extracts Node.js version by running `node --version` in a Docker container.
|
|
130
|
+
*
|
|
131
|
+
* @param dockerImage - The Docker image to run
|
|
132
|
+
* @returns Promise resolving to the Node.js version string
|
|
133
|
+
* @throws Error if container execution fails
|
|
134
|
+
*/
|
|
135
|
+
private extractNodeVersionFromContainer;
|
|
136
|
+
/**
|
|
137
|
+
* Validates that a version string follows semantic versioning format.
|
|
138
|
+
*
|
|
139
|
+
* @param version - The version string to validate
|
|
140
|
+
* @returns true if the version is valid, false otherwise
|
|
141
|
+
*/
|
|
142
|
+
private isValidSemanticVersion;
|
|
143
|
+
/**
|
|
144
|
+
* Provides fallback version information when Docker detection fails.
|
|
145
|
+
*
|
|
146
|
+
* @param runtimeName - The AWS Lambda runtime name
|
|
147
|
+
* @param architecture - The target architecture
|
|
148
|
+
* @returns NodeVersionInfo with fallback version
|
|
149
|
+
* @throws NodeRuntimeLayerError if no fallback is available
|
|
150
|
+
*/
|
|
151
|
+
private getFallbackVersion;
|
|
152
|
+
/**
|
|
153
|
+
* Clears the version cache.
|
|
154
|
+
* Useful for testing or when cache invalidation is needed.
|
|
155
|
+
*/
|
|
156
|
+
clearCache(): void;
|
|
157
|
+
/**
|
|
158
|
+
* Gets the current cache size.
|
|
159
|
+
* Useful for monitoring and debugging.
|
|
160
|
+
*/
|
|
161
|
+
getCacheSize(): number;
|
|
162
|
+
/**
|
|
163
|
+
* Checks if Docker is available on the system.
|
|
164
|
+
*
|
|
165
|
+
* @returns Promise resolving to true if Docker is available, false otherwise
|
|
166
|
+
*/
|
|
167
|
+
isDockerAvailable(): Promise<boolean>;
|
|
168
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Main API function for Node.js runtime layer management
|
|
3
|
+
*
|
|
4
|
+
* This module provides the primary entry point for ensuring Node.js runtime layers
|
|
5
|
+
* exist in AWS Lambda. It coordinates between runtime detection and layer management
|
|
6
|
+
* components to provide a seamless experience for CDK integration.
|
|
7
|
+
*
|
|
8
|
+
* @module ensure-node-runtime-layer
|
|
9
|
+
*/
|
|
10
|
+
import { EnsureNodeRuntimeLayerOptions, EnsureNodeRuntimeLayerResult } from './nodejs-layer-manager';
|
|
11
|
+
/**
|
|
12
|
+
* Ensures a Node.js runtime layer exists for the specified configuration.
|
|
13
|
+
*
|
|
14
|
+
* This is the main API function that coordinates runtime detection and layer management
|
|
15
|
+
* to ensure the correct Node.js binaries are available for Lambda Kata execution.
|
|
16
|
+
*
|
|
17
|
+
* The function performs the following operations:
|
|
18
|
+
* 1. Validates all input parameters
|
|
19
|
+
* 2. Detects the exact Node.js version for the runtime
|
|
20
|
+
* 3. Searches for existing compatible layers
|
|
21
|
+
* 4. Creates a new layer if none exists or is compatible
|
|
22
|
+
* 5. Returns comprehensive result information
|
|
23
|
+
*
|
|
24
|
+
* @param options - Configuration options for layer management
|
|
25
|
+
* @returns Promise resolving to layer information and metadata
|
|
26
|
+
* @throws NodeRuntimeLayerError for validation failures or operational errors
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* ```typescript
|
|
30
|
+
* const result = await ensureNodeRuntimeLayer({
|
|
31
|
+
* runtimeName: 'nodejs20.x',
|
|
32
|
+
* architecture: 'x86_64',
|
|
33
|
+
* region: 'us-east-1',
|
|
34
|
+
* accountId: '123456789012'
|
|
35
|
+
* });
|
|
36
|
+
*
|
|
37
|
+
* console.log(`Layer ARN: ${result.layerArn}`);
|
|
38
|
+
* console.log(`Node.js version: ${result.nodeVersion}`);
|
|
39
|
+
* console.log(`Created new layer: ${result.created}`);
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
42
|
+
export declare function ensureNodeRuntimeLayer(options: EnsureNodeRuntimeLayerOptions): Promise<EnsureNodeRuntimeLayerResult>;
|
package/out/tsc/src/index.d.ts
CHANGED
|
@@ -23,3 +23,8 @@ 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';
|
|
27
|
+
export { DockerRuntimeDetector, DockerRuntimeDetectorOptions, } from './docker-runtime-detector';
|
|
28
|
+
export { AWSLayerManager, AWSLayerManagerOptions, } from './aws-layer-manager';
|
|
29
|
+
export { NoOpLogger, ConsoleLogger, createDefaultLogger, OperationTimer, } from './logger';
|
|
30
|
+
export { ensureNodeRuntimeLayer } from './ensure-node-runtime-layer';
|
|
@@ -1,17 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Kata Wrapper for Lambda Kata CDK Integration
|
|
3
|
-
*
|
|
4
|
-
* This module provides the main `kata()` function that transforms Node.js Lambda
|
|
5
|
-
* functions to run via the Lambda Kata runtime. The transformation includes:
|
|
6
|
-
* - Changing the runtime to Python 3.12
|
|
7
|
-
* - Setting the handler to the Lambda Kata handler
|
|
8
|
-
* - Attaching the customer-specific Lambda Layer
|
|
9
|
-
* - Preserving the original handler path in a config layer
|
|
10
|
-
*
|
|
11
|
-
* Licensing is validated at CDK synthesis/deploy time only—no runtime network calls.
|
|
12
|
-
*
|
|
13
|
-
* @module kata-wrapper
|
|
14
|
-
*/
|
|
15
1
|
import { Function as LambdaFunction } from 'aws-cdk-lib/aws-lambda';
|
|
16
2
|
import { NodejsFunction } from 'aws-cdk-lib/aws-lambda-nodejs';
|
|
17
3
|
import { KataProps, LicensingResponse, TransformationConfig } from './types';
|
|
@@ -130,6 +116,33 @@ export declare function kata<T extends NodejsFunction | LambdaFunction>(lambda:
|
|
|
130
116
|
* @internal
|
|
131
117
|
*/
|
|
132
118
|
export declare function kataWithAccountId<T extends NodejsFunction | LambdaFunction>(lambda: T, accountId: string, props?: KataWrapperOptions): Promise<KataResult>;
|
|
119
|
+
/**
|
|
120
|
+
* Gets the original runtime from a Lambda function before transformation.
|
|
121
|
+
*
|
|
122
|
+
* @param lambda - The Lambda function
|
|
123
|
+
* @returns The original runtime name (e.g., "nodejs20.x")
|
|
124
|
+
*
|
|
125
|
+
* @internal
|
|
126
|
+
*/
|
|
127
|
+
export declare function getOriginalRuntime(lambda: NodejsFunction | LambdaFunction): string;
|
|
128
|
+
/**
|
|
129
|
+
* Detects if a Lambda function uses a Node.js runtime.
|
|
130
|
+
*
|
|
131
|
+
* @param lambda - The Lambda function to check
|
|
132
|
+
* @returns true if the function uses a supported Node.js runtime
|
|
133
|
+
*
|
|
134
|
+
* @internal
|
|
135
|
+
*/
|
|
136
|
+
export declare function isNodejsRuntime(lambda: NodejsFunction | LambdaFunction): boolean;
|
|
137
|
+
/**
|
|
138
|
+
* Gets the architecture of a Lambda function.
|
|
139
|
+
*
|
|
140
|
+
* @param lambda - The Lambda function
|
|
141
|
+
* @returns The architecture ("x86_64" or "arm64")
|
|
142
|
+
*
|
|
143
|
+
* @internal
|
|
144
|
+
*/
|
|
145
|
+
export declare function getLambdaArchitecture(lambda: NodejsFunction | LambdaFunction): 'x86_64' | 'arm64';
|
|
133
146
|
/**
|
|
134
147
|
* Applies the Lambda Kata transformation to a Lambda function.
|
|
135
148
|
*
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Logger implementations for Node.js Layer Management
|
|
3
|
+
*
|
|
4
|
+
* Provides different logger implementations for various use cases:
|
|
5
|
+
* - NoOpLogger: Silent logger for production use
|
|
6
|
+
* - ConsoleLogger: Console-based logger for development and debugging
|
|
7
|
+
*
|
|
8
|
+
* @module logger
|
|
9
|
+
*/
|
|
10
|
+
import { Logger } from './nodejs-layer-manager';
|
|
11
|
+
/**
|
|
12
|
+
* No-operation logger that silently discards all log messages.
|
|
13
|
+
*
|
|
14
|
+
* This is the default logger used when no custom logger is provided.
|
|
15
|
+
* Useful for production environments where logging overhead should be minimized.
|
|
16
|
+
*/
|
|
17
|
+
export declare class NoOpLogger implements Logger {
|
|
18
|
+
debug(_message: string, _meta?: Record<string, unknown>): void;
|
|
19
|
+
info(_message: string, _meta?: Record<string, unknown>): void;
|
|
20
|
+
warn(_message: string, _meta?: Record<string, unknown>): void;
|
|
21
|
+
error(_message: string, _meta?: Record<string, unknown>): void;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Console-based logger for development and debugging.
|
|
25
|
+
*
|
|
26
|
+
* Outputs structured log messages to the console with timestamps and metadata.
|
|
27
|
+
* Useful for development environments and troubleshooting.
|
|
28
|
+
*/
|
|
29
|
+
export declare class ConsoleLogger implements Logger {
|
|
30
|
+
private readonly prefix;
|
|
31
|
+
private readonly logLevel;
|
|
32
|
+
constructor(prefix?: string, logLevel?: 'debug' | 'info' | 'warn' | 'error');
|
|
33
|
+
debug(message: string, meta?: Record<string, unknown>): void;
|
|
34
|
+
info(message: string, meta?: Record<string, unknown>): void;
|
|
35
|
+
warn(message: string, meta?: Record<string, unknown>): void;
|
|
36
|
+
error(message: string, meta?: Record<string, unknown>): void;
|
|
37
|
+
private shouldLog;
|
|
38
|
+
private log;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Creates a default logger instance.
|
|
42
|
+
*
|
|
43
|
+
* Returns a NoOpLogger by default, but can be configured to return
|
|
44
|
+
* a ConsoleLogger based on environment variables or other configuration.
|
|
45
|
+
*
|
|
46
|
+
* @returns A logger instance
|
|
47
|
+
*/
|
|
48
|
+
export declare function createDefaultLogger(): Logger;
|
|
49
|
+
/**
|
|
50
|
+
* Utility class for measuring operation timing with structured logging.
|
|
51
|
+
*
|
|
52
|
+
* Provides consistent timing measurement and logging across all operations.
|
|
53
|
+
* Ensures operation start/completion logging with timing information.
|
|
54
|
+
*/
|
|
55
|
+
export declare class OperationTimer {
|
|
56
|
+
private readonly startTime;
|
|
57
|
+
private readonly logger;
|
|
58
|
+
private readonly operationType;
|
|
59
|
+
private readonly operationMetadata;
|
|
60
|
+
constructor(logger: Logger, operationType: string, operationMetadata?: Record<string, unknown>);
|
|
61
|
+
/**
|
|
62
|
+
* Completes the operation timing and logs success.
|
|
63
|
+
*
|
|
64
|
+
* @param resultMetadata - Additional metadata about the operation result
|
|
65
|
+
*/
|
|
66
|
+
complete(resultMetadata?: Record<string, unknown>): void;
|
|
67
|
+
/**
|
|
68
|
+
* Completes the operation timing and logs failure.
|
|
69
|
+
*
|
|
70
|
+
* @param error - The error that caused the operation to fail
|
|
71
|
+
* @param errorMetadata - Additional metadata about the error
|
|
72
|
+
*/
|
|
73
|
+
fail(error: unknown, errorMetadata?: Record<string, unknown>): void;
|
|
74
|
+
/**
|
|
75
|
+
* Extracts AWS request ID from error objects.
|
|
76
|
+
*
|
|
77
|
+
* @param error - The error to extract request ID from
|
|
78
|
+
* @returns AWS request ID if found, undefined otherwise
|
|
79
|
+
*/
|
|
80
|
+
private extractAwsRequestId;
|
|
81
|
+
/**
|
|
82
|
+
* Generates troubleshooting context based on error type.
|
|
83
|
+
*
|
|
84
|
+
* @param error - The error to generate context for
|
|
85
|
+
* @returns Troubleshooting guidance
|
|
86
|
+
*/
|
|
87
|
+
private generateTroubleshootingContext;
|
|
88
|
+
}
|