@lambda-kata/cdk 0.1.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/LICENSE +201 -0
- package/README.md +169 -0
- package/lib/account-resolver.d.ts +103 -0
- package/lib/config-layer.d.ts +168 -0
- package/lib/index.d.ts +25 -0
- package/lib/kata-wrapper.d.ts +219 -0
- package/lib/licensing.d.ts +113 -0
- package/lib/mock-licensing.d.ts +200 -0
- package/lib/types.d.ts +113 -0
- package/out/dist/index.js +60 -0
- package/package.json +75 -0
|
@@ -0,0 +1,219 @@
|
|
|
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
|
+
import { Function as LambdaFunction } from 'aws-cdk-lib/aws-lambda';
|
|
16
|
+
import { NodejsFunction } from 'aws-cdk-lib/aws-lambda-nodejs';
|
|
17
|
+
import { KataProps, LicensingResponse, TransformationConfig } from './types';
|
|
18
|
+
import { LicensingService } from './licensing';
|
|
19
|
+
/**
|
|
20
|
+
* Options for the kata wrapper, extending KataProps with internal options.
|
|
21
|
+
*/
|
|
22
|
+
export interface KataWrapperOptions extends KataProps {
|
|
23
|
+
/**
|
|
24
|
+
* Optional: Custom licensing service for testing.
|
|
25
|
+
* If not provided, the default HTTP licensing service will be used.
|
|
26
|
+
* @internal
|
|
27
|
+
*/
|
|
28
|
+
licensingService?: LicensingService;
|
|
29
|
+
/**
|
|
30
|
+
* Custom bundle path.
|
|
31
|
+
* If not specified, uses the default /opt/js_runtime/bundle.js
|
|
32
|
+
*/
|
|
33
|
+
bundlePath?: string;
|
|
34
|
+
/**
|
|
35
|
+
* Path to middleware TypeScript/JavaScript file.
|
|
36
|
+
* The file will be compiled with esbuild and included in the config layer.
|
|
37
|
+
* The middleware must export a function: (bundle, context) => handler
|
|
38
|
+
*/
|
|
39
|
+
middlewarePath?: string;
|
|
40
|
+
/**
|
|
41
|
+
* Inline handler resolver function.
|
|
42
|
+
* This TypeScript function will be serialized, compiled with esbuild,
|
|
43
|
+
* and included in the config layer as middleware.js
|
|
44
|
+
*
|
|
45
|
+
* The function receives the loaded bundle and context with originalHandler,
|
|
46
|
+
* and must return the handler function.
|
|
47
|
+
*
|
|
48
|
+
* Note: The function must be pure (no closures over external variables)
|
|
49
|
+
* because it will be serialized via .toString()
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* ```typescript
|
|
53
|
+
* kata(myFunction, {
|
|
54
|
+
* handlerResolver: (bundle, ctx) => {
|
|
55
|
+
* const handlerName = ctx.originalHandler.split('.').pop();
|
|
56
|
+
* return bundle[handlerName];
|
|
57
|
+
* }
|
|
58
|
+
* });
|
|
59
|
+
* ```
|
|
60
|
+
*/
|
|
61
|
+
handlerResolver?: (bundle: unknown, context: {
|
|
62
|
+
originalHandler: string;
|
|
63
|
+
}) => Function;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Result of the kata transformation.
|
|
67
|
+
*/
|
|
68
|
+
export interface KataResult {
|
|
69
|
+
/**
|
|
70
|
+
* Whether the Lambda was transformed.
|
|
71
|
+
*/
|
|
72
|
+
transformed: boolean;
|
|
73
|
+
/**
|
|
74
|
+
* The licensing response from the licensing service.
|
|
75
|
+
*/
|
|
76
|
+
licensingResponse: LicensingResponse;
|
|
77
|
+
/**
|
|
78
|
+
* The resolved AWS account ID.
|
|
79
|
+
*/
|
|
80
|
+
accountId: string;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Transforms a Node.js Lambda function to run via the Lambda Kata runtime.
|
|
84
|
+
*
|
|
85
|
+
* This function performs the following steps:
|
|
86
|
+
* 1. Resolves the target AWS account ID
|
|
87
|
+
* 2. Calls the licensing service to validate entitlement
|
|
88
|
+
* 3. If entitled, applies transformations (runtime, handler, layer, env vars)
|
|
89
|
+
* 4. If not entitled, handles according to unlicensedBehavior option
|
|
90
|
+
*
|
|
91
|
+
* @param lambda - The Node.js Lambda function to transform (NodejsFunction or Function)
|
|
92
|
+
* @param props - Optional configuration for the transformation
|
|
93
|
+
* @returns The same Lambda construct (modified if licensed)
|
|
94
|
+
*
|
|
95
|
+
* @example
|
|
96
|
+
* ```typescript
|
|
97
|
+
* import { kata } from '@lambda-kata/cdk';
|
|
98
|
+
* import { NodejsFunction } from 'aws-cdk-lib/aws-lambda-nodejs';
|
|
99
|
+
*
|
|
100
|
+
* const myFunction = new NodejsFunction(this, 'MyFunction', {
|
|
101
|
+
* entry: 'src/handler.ts',
|
|
102
|
+
* });
|
|
103
|
+
*
|
|
104
|
+
* // Transform to use Lambda Kata runtime
|
|
105
|
+
* kata(myFunction);
|
|
106
|
+
*
|
|
107
|
+
* // With options
|
|
108
|
+
* kata(myFunction, {
|
|
109
|
+
* unlicensedBehavior: 'fail',
|
|
110
|
+
* });
|
|
111
|
+
* ```
|
|
112
|
+
*
|
|
113
|
+
* @remarks
|
|
114
|
+
* Validates: Requirements 2.1, 3.2
|
|
115
|
+
* - 2.1: WHEN a developer wraps a Node.js Lambda with `kata(lambda)`, THE kata_Wrapper SHALL return a modified Lambda construct
|
|
116
|
+
* - 3.2: THE kata_Wrapper SHALL call the Licensing_Service to validate the account's entitlement
|
|
117
|
+
*/
|
|
118
|
+
export declare function kata<T extends NodejsFunction | LambdaFunction>(lambda: T, props?: KataWrapperOptions): T;
|
|
119
|
+
/**
|
|
120
|
+
* Synchronous version of kata for use when account ID is already known.
|
|
121
|
+
*
|
|
122
|
+
* This is useful for testing or when the account ID can be determined
|
|
123
|
+
* without async operations.
|
|
124
|
+
*
|
|
125
|
+
* @param lambda - The Node.js Lambda function to transform
|
|
126
|
+
* @param accountId - The AWS account ID to use for licensing check
|
|
127
|
+
* @param props - Optional configuration for the transformation
|
|
128
|
+
* @returns Promise resolving to the transformation result
|
|
129
|
+
*
|
|
130
|
+
* @internal
|
|
131
|
+
*/
|
|
132
|
+
export declare function kataWithAccountId<T extends NodejsFunction | LambdaFunction>(lambda: T, accountId: string, props?: KataWrapperOptions): Promise<KataResult>;
|
|
133
|
+
/**
|
|
134
|
+
* Applies the Lambda Kata transformation to a Lambda function.
|
|
135
|
+
*
|
|
136
|
+
* This function modifies the Lambda construct in-place to:
|
|
137
|
+
* 1. Create and attach a config layer with the original handler path
|
|
138
|
+
* 2. Change the runtime to Python 3.12
|
|
139
|
+
* 3. Set the handler to the Lambda Kata handler
|
|
140
|
+
* 4. Attach the customer-specific Lambda Layer
|
|
141
|
+
* 5. Add additional environment variables for the Lambda Kata runtime
|
|
142
|
+
*
|
|
143
|
+
* @param lambda - The Lambda function to transform
|
|
144
|
+
* @param config - The transformation configuration
|
|
145
|
+
*
|
|
146
|
+
* @remarks
|
|
147
|
+
* Validates: Requirements 2.2, 2.3, 2.4, 3.3, 3.4, 4.1, 4.2, 5.4
|
|
148
|
+
* - 2.2: THE kata_Wrapper SHALL change the Lambda runtime from Node.js to Python 3.12
|
|
149
|
+
* - 2.3: THE kata_Wrapper SHALL set the Lambda handler to `lambdakata.optimized_handler.lambda_handler`
|
|
150
|
+
* - 2.4: THE kata_Wrapper SHALL attach the customer-specific Lambda_Layer ARN to the Lambda
|
|
151
|
+
* - 3.3: THE kata_Wrapper SHALL attach the Config_Layer to the transformed Lambda
|
|
152
|
+
* - 3.4: THE kata_Wrapper SHALL NOT set the `JS_HANDLER_PATH` environment variable
|
|
153
|
+
* - 4.1: THE kata_Wrapper SHALL NOT add the `JS_HANDLER_PATH` environment variable to transformed Lambdas
|
|
154
|
+
* - 4.2: WHEN `bundlePath` is specified, THE kata_Wrapper SHALL write it to the Config_Layer JSON as `bundle_path`
|
|
155
|
+
* - 5.4: THE compiled middleware SHALL be included in the Config_Layer at `/opt/.kata/middleware.js`
|
|
156
|
+
*
|
|
157
|
+
* @internal
|
|
158
|
+
*/
|
|
159
|
+
export declare function applyTransformation(lambda: NodejsFunction | LambdaFunction, config: TransformationConfig): void;
|
|
160
|
+
/**
|
|
161
|
+
* Handles the case when an account is not licensed.
|
|
162
|
+
*
|
|
163
|
+
* Depending on the unlicensedBehavior option:
|
|
164
|
+
* - 'warn' (default): Emit a warning and keep the original Lambda unchanged
|
|
165
|
+
* - 'fail': Throw an error to fail CDK synthesis
|
|
166
|
+
*
|
|
167
|
+
* @param lambda - The Lambda function
|
|
168
|
+
* @param props - The kata wrapper options
|
|
169
|
+
* @param licensingResponse - The licensing response
|
|
170
|
+
*
|
|
171
|
+
* @remarks
|
|
172
|
+
* Validates: Requirements 3.5, 3.6, 6.1, 6.2, 6.3, 6.4
|
|
173
|
+
* - 3.5: IF the account is NOT entitled, THEN THE kata_Wrapper SHALL NOT apply any transformations
|
|
174
|
+
* - 3.6: IF the account is NOT entitled, THEN THE kata_Wrapper SHALL emit a clear warning message
|
|
175
|
+
* - 6.1: IF the Licensing_Service returns an unlicensed status, THEN THE kata_Wrapper SHALL keep the original Node.js runtime unchanged
|
|
176
|
+
* - 6.2: IF the Licensing_Service returns an unlicensed status, THEN THE kata_Wrapper SHALL keep the original handler unchanged
|
|
177
|
+
* - 6.3: IF the Licensing_Service returns an unlicensed status, THEN THE kata_Wrapper SHALL NOT attach any Lambda_Layer
|
|
178
|
+
* - 6.4: IF the Licensing_Service returns an unlicensed status, THEN THE kata_Wrapper SHALL emit a warning message
|
|
179
|
+
*
|
|
180
|
+
* @internal
|
|
181
|
+
*/
|
|
182
|
+
export declare function handleUnlicensed(lambda: NodejsFunction | LambdaFunction, props: KataWrapperOptions | undefined, licensingResponse: LicensingResponse): void;
|
|
183
|
+
/**
|
|
184
|
+
* Checks if a Lambda function has been transformed by kata().
|
|
185
|
+
*
|
|
186
|
+
* @param lambda - The Lambda function to check
|
|
187
|
+
* @returns true if the Lambda has been transformed
|
|
188
|
+
*
|
|
189
|
+
* @example
|
|
190
|
+
* ```typescript
|
|
191
|
+
* const myFunction = new NodejsFunction(this, 'MyFunction', { ... });
|
|
192
|
+
* kata(myFunction);
|
|
193
|
+
*
|
|
194
|
+
* if (isKataTransformed(myFunction)) {
|
|
195
|
+
* console.log('Function is using Lambda Kata runtime');
|
|
196
|
+
* }
|
|
197
|
+
* ```
|
|
198
|
+
*/
|
|
199
|
+
export declare function isKataTransformed(lambda: NodejsFunction | LambdaFunction): boolean;
|
|
200
|
+
/**
|
|
201
|
+
* Gets the kata transformation promise for a Lambda function.
|
|
202
|
+
*
|
|
203
|
+
* This is useful for testing or when you need to await the transformation result.
|
|
204
|
+
*
|
|
205
|
+
* @param lambda - The Lambda function
|
|
206
|
+
* @returns The transformation promise, or undefined if kata() was not called
|
|
207
|
+
*
|
|
208
|
+
* @example
|
|
209
|
+
* ```typescript
|
|
210
|
+
* const myFunction = new NodejsFunction(this, 'MyFunction', { ... });
|
|
211
|
+
* kata(myFunction);
|
|
212
|
+
*
|
|
213
|
+
* const result = await getKataPromise(myFunction);
|
|
214
|
+
* if (result?.transformed) {
|
|
215
|
+
* console.log(`Transformed with layer: ${result.licensingResponse.layerArn}`);
|
|
216
|
+
* }
|
|
217
|
+
* ```
|
|
218
|
+
*/
|
|
219
|
+
export declare function getKataPromise(lambda: NodejsFunction | LambdaFunction): Promise<KataResult> | undefined;
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Licensing Service for Lambda Kata CDK Integration
|
|
3
|
+
*
|
|
4
|
+
* This module provides the interface and implementation for validating
|
|
5
|
+
* AWS Marketplace entitlements at CDK synthesis/deploy time.
|
|
6
|
+
*
|
|
7
|
+
* @module licensing
|
|
8
|
+
*/
|
|
9
|
+
import { LicensingResponse } from './types';
|
|
10
|
+
/**
|
|
11
|
+
* Interface for the Lambda Kata licensing service.
|
|
12
|
+
*
|
|
13
|
+
* Implementations of this interface are responsible for validating
|
|
14
|
+
* AWS account entitlements and returning customer-specific Layer ARNs.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```typescript
|
|
18
|
+
* const licensingService = new HttpLicensingService();
|
|
19
|
+
* const response = await licensingService.checkEntitlement('123456789012');
|
|
20
|
+
* if (response.entitled) {
|
|
21
|
+
* console.log(`Layer ARN: ${response.layerArn}`);
|
|
22
|
+
* }
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
export interface LicensingService {
|
|
26
|
+
/**
|
|
27
|
+
* Check if an AWS account is entitled to use Lambda Kata.
|
|
28
|
+
*
|
|
29
|
+
* @param accountId - The AWS account ID to check (12-digit string)
|
|
30
|
+
* @returns Promise resolving to entitlement status and Layer ARN if entitled
|
|
31
|
+
*
|
|
32
|
+
* @remarks
|
|
33
|
+
* - If the account is entitled, the response will include the customer-specific Layer ARN
|
|
34
|
+
* - If the account is not entitled, the response will have `entitled: false`
|
|
35
|
+
* - Network errors are handled gracefully and treated as unlicensed (Requirement 6.5)
|
|
36
|
+
*/
|
|
37
|
+
checkEntitlement(accountId: string): Promise<LicensingResponse>;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* HTTP-based implementation of the LicensingService interface.
|
|
41
|
+
*
|
|
42
|
+
* This implementation calls the Lambda Kata licensing backend to validate
|
|
43
|
+
* AWS Marketplace entitlements. Network errors are handled gracefully
|
|
44
|
+
* by treating unreachable services as unlicensed (per Requirement 6.5).
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* ```typescript
|
|
48
|
+
* // Use default endpoint
|
|
49
|
+
* const service = new HttpLicensingService();
|
|
50
|
+
*
|
|
51
|
+
* // Use custom endpoint
|
|
52
|
+
* const customService = new HttpLicensingService('https://custom.endpoint.com');
|
|
53
|
+
* ```
|
|
54
|
+
*/
|
|
55
|
+
export declare class HttpLicensingService implements LicensingService {
|
|
56
|
+
private readonly endpoint;
|
|
57
|
+
private readonly timeoutMs;
|
|
58
|
+
/**
|
|
59
|
+
* Creates a new HttpLicensingService instance.
|
|
60
|
+
*
|
|
61
|
+
* @param endpoint - Optional custom licensing endpoint URL
|
|
62
|
+
* @param timeoutMs - Optional request timeout in milliseconds (default: 5000)
|
|
63
|
+
*/
|
|
64
|
+
constructor(endpoint?: string, timeoutMs?: number);
|
|
65
|
+
/**
|
|
66
|
+
* Check if an AWS account is entitled to use Lambda Kata.
|
|
67
|
+
*
|
|
68
|
+
* Makes an HTTP request to the licensing service to validate the account's
|
|
69
|
+
* AWS Marketplace entitlement. If the service is unreachable or returns
|
|
70
|
+
* an error, the account is treated as unlicensed (Requirement 6.5).
|
|
71
|
+
*
|
|
72
|
+
* @param accountId - The AWS account ID to check (12-digit string)
|
|
73
|
+
* @returns Promise resolving to entitlement status and Layer ARN if entitled
|
|
74
|
+
*
|
|
75
|
+
* @remarks
|
|
76
|
+
* Validates: Requirements 3.2, 3.3, 6.5
|
|
77
|
+
* - 3.2: Calls the Licensing_Service to validate the account's entitlement
|
|
78
|
+
* - 3.3: Returns the customer-specific Layer_ARN if entitled
|
|
79
|
+
* - 6.5: Treats unreachable service as unlicensed with appropriate warning
|
|
80
|
+
*/
|
|
81
|
+
checkEntitlement(accountId: string): Promise<LicensingResponse>;
|
|
82
|
+
/**
|
|
83
|
+
* Makes the HTTP request to the licensing service.
|
|
84
|
+
*
|
|
85
|
+
* @param accountId - The AWS account ID to check
|
|
86
|
+
* @returns Promise resolving to the licensing response
|
|
87
|
+
* @throws Error if the request fails or times out
|
|
88
|
+
*/
|
|
89
|
+
private makeRequest;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Validates that an AWS account ID is in the correct format.
|
|
93
|
+
*
|
|
94
|
+
* @param accountId - The account ID to validate
|
|
95
|
+
* @returns true if the account ID is a valid 12-digit string
|
|
96
|
+
*/
|
|
97
|
+
export declare function isValidAccountId(accountId: string): boolean;
|
|
98
|
+
/**
|
|
99
|
+
* Creates a default LicensingService instance.
|
|
100
|
+
*
|
|
101
|
+
* This factory function provides a convenient way to create a licensing
|
|
102
|
+
* service with default configuration.
|
|
103
|
+
*
|
|
104
|
+
* @param endpoint - Optional custom licensing endpoint URL
|
|
105
|
+
* @returns A new LicensingService instance
|
|
106
|
+
*
|
|
107
|
+
* @example
|
|
108
|
+
* ```typescript
|
|
109
|
+
* const service = createLicensingService();
|
|
110
|
+
* const response = await service.checkEntitlement('123456789012');
|
|
111
|
+
* ```
|
|
112
|
+
*/
|
|
113
|
+
export declare function createLicensingService(endpoint?: string): LicensingService;
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Mock Licensing Service for Lambda Kata CDK Integration Testing
|
|
3
|
+
*
|
|
4
|
+
* This module provides a mock implementation of the LicensingService interface
|
|
5
|
+
* for testing the kata() wrapper without making real network calls.
|
|
6
|
+
*
|
|
7
|
+
* @module mock-licensing
|
|
8
|
+
*/
|
|
9
|
+
import { LicensingService } from './licensing';
|
|
10
|
+
import { LicensingResponse } from './types';
|
|
11
|
+
/**
|
|
12
|
+
* Mock implementation of the LicensingService interface for testing.
|
|
13
|
+
*
|
|
14
|
+
* This class allows programmatic control over entitlement status,
|
|
15
|
+
* enabling comprehensive testing of the kata() wrapper behavior
|
|
16
|
+
* for both entitled and non-entitled accounts.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```typescript
|
|
20
|
+
* const mockService = new MockLicensingService();
|
|
21
|
+
*
|
|
22
|
+
* // Set up an entitled account
|
|
23
|
+
* mockService.setEntitled('123456789012', 'arn:aws:lambda:us-east-1:999999999999:layer:LambdaKata:1');
|
|
24
|
+
*
|
|
25
|
+
* // Check entitlement
|
|
26
|
+
* const response = await mockService.checkEntitlement('123456789012');
|
|
27
|
+
* console.log(response.entitled); // true
|
|
28
|
+
* console.log(response.layerArn); // 'arn:aws:lambda:us-east-1:999999999999:layer:LambdaKata:1'
|
|
29
|
+
*
|
|
30
|
+
* // Non-entitled account
|
|
31
|
+
* const response2 = await mockService.checkEntitlement('000000000000');
|
|
32
|
+
* console.log(response2.entitled); // false
|
|
33
|
+
* ```
|
|
34
|
+
*
|
|
35
|
+
* @remarks
|
|
36
|
+
* Validates: Requirements 3.2, 3.3
|
|
37
|
+
* - 3.2: Provides mock validation of account entitlements
|
|
38
|
+
* - 3.3: Returns customer-specific Layer_ARN for entitled accounts
|
|
39
|
+
*/
|
|
40
|
+
export declare class MockLicensingService implements LicensingService {
|
|
41
|
+
/**
|
|
42
|
+
* Map of AWS account IDs to their entitled Layer ARNs.
|
|
43
|
+
* Accounts not in this map are considered non-entitled.
|
|
44
|
+
*/
|
|
45
|
+
private entitlements;
|
|
46
|
+
/**
|
|
47
|
+
* Map of AWS account IDs to custom messages (for non-entitled accounts).
|
|
48
|
+
*/
|
|
49
|
+
private customMessages;
|
|
50
|
+
/**
|
|
51
|
+
* Optional custom message to return for entitled accounts.
|
|
52
|
+
*/
|
|
53
|
+
private entitledMessage;
|
|
54
|
+
/**
|
|
55
|
+
* Optional custom message to return for non-entitled accounts.
|
|
56
|
+
* Default matches the expected warning message from Requirement 6.4.
|
|
57
|
+
*/
|
|
58
|
+
private notEntitledMessage;
|
|
59
|
+
/**
|
|
60
|
+
* Optional expiration date for entitlements.
|
|
61
|
+
*/
|
|
62
|
+
private expiresAt?;
|
|
63
|
+
/**
|
|
64
|
+
* Flag to simulate service unavailability.
|
|
65
|
+
*/
|
|
66
|
+
private simulateServiceError;
|
|
67
|
+
/**
|
|
68
|
+
* Custom error message when simulating service errors.
|
|
69
|
+
*/
|
|
70
|
+
private serviceErrorMessage;
|
|
71
|
+
/**
|
|
72
|
+
* Sets an account as entitled with a specific Layer ARN.
|
|
73
|
+
*
|
|
74
|
+
* @param accountId - The AWS account ID (12-digit string)
|
|
75
|
+
* @param layerArn - The customer-specific Lambda Layer ARN
|
|
76
|
+
*
|
|
77
|
+
* @example
|
|
78
|
+
* ```typescript
|
|
79
|
+
* mockService.setEntitled('123456789012', 'arn:aws:lambda:us-east-1:999999999999:layer:LambdaKata:1');
|
|
80
|
+
* ```
|
|
81
|
+
*/
|
|
82
|
+
setEntitled(accountId: string, layerArn: string): void;
|
|
83
|
+
/**
|
|
84
|
+
* Removes entitlement for an account.
|
|
85
|
+
*
|
|
86
|
+
* @param accountId - The AWS account ID to remove entitlement for
|
|
87
|
+
*
|
|
88
|
+
* @example
|
|
89
|
+
* ```typescript
|
|
90
|
+
* mockService.removeEntitlement('123456789012');
|
|
91
|
+
* ```
|
|
92
|
+
*/
|
|
93
|
+
removeEntitlement(accountId: string): void;
|
|
94
|
+
/**
|
|
95
|
+
* Clears all entitlements.
|
|
96
|
+
*
|
|
97
|
+
* @example
|
|
98
|
+
* ```typescript
|
|
99
|
+
* mockService.clearEntitlements();
|
|
100
|
+
* ```
|
|
101
|
+
*/
|
|
102
|
+
clearEntitlements(): void;
|
|
103
|
+
/**
|
|
104
|
+
* Sets a custom message for entitled accounts.
|
|
105
|
+
*
|
|
106
|
+
* @param message - The message to return for entitled accounts
|
|
107
|
+
*/
|
|
108
|
+
setEntitledMessage(message: string): void;
|
|
109
|
+
/**
|
|
110
|
+
* Sets a custom message for non-entitled accounts.
|
|
111
|
+
*
|
|
112
|
+
* @param message - The message to return for non-entitled accounts
|
|
113
|
+
*/
|
|
114
|
+
setNotEntitledMessage(message: string): void;
|
|
115
|
+
/**
|
|
116
|
+
* Sets a custom message for a specific non-entitled account.
|
|
117
|
+
* This allows testing per-account custom error messages from the licensing service.
|
|
118
|
+
*
|
|
119
|
+
* @param accountId - The AWS account ID
|
|
120
|
+
* @param message - The custom message to return for this account
|
|
121
|
+
*
|
|
122
|
+
* @example
|
|
123
|
+
* ```typescript
|
|
124
|
+
* mockService.setCustomMessage('123456789012', 'Custom licensing error: Account suspended');
|
|
125
|
+
* ```
|
|
126
|
+
*/
|
|
127
|
+
setCustomMessage(accountId: string, message: string): void;
|
|
128
|
+
/**
|
|
129
|
+
* Sets the expiration date for entitlements.
|
|
130
|
+
*
|
|
131
|
+
* @param expiresAt - ISO 8601 formatted expiration date
|
|
132
|
+
*/
|
|
133
|
+
setExpiresAt(expiresAt: string): void;
|
|
134
|
+
/**
|
|
135
|
+
* Configures the mock to simulate service unavailability.
|
|
136
|
+
*
|
|
137
|
+
* @param simulate - Whether to simulate service errors
|
|
138
|
+
* @param errorMessage - Optional custom error message
|
|
139
|
+
*
|
|
140
|
+
* @example
|
|
141
|
+
* ```typescript
|
|
142
|
+
* // Simulate service being down
|
|
143
|
+
* mockService.setSimulateServiceError(true);
|
|
144
|
+
*
|
|
145
|
+
* // With custom error message
|
|
146
|
+
* mockService.setSimulateServiceError(true, 'Connection refused');
|
|
147
|
+
* ```
|
|
148
|
+
*/
|
|
149
|
+
setSimulateServiceError(simulate: boolean, errorMessage?: string): void;
|
|
150
|
+
/**
|
|
151
|
+
* Check if an AWS account is entitled to use Lambda Kata.
|
|
152
|
+
*
|
|
153
|
+
* This mock implementation returns entitlement status based on
|
|
154
|
+
* accounts configured via setEntitled().
|
|
155
|
+
*
|
|
156
|
+
* @param accountId - The AWS account ID to check (12-digit string)
|
|
157
|
+
* @returns Promise resolving to entitlement status and Layer ARN if entitled
|
|
158
|
+
*
|
|
159
|
+
* @remarks
|
|
160
|
+
* Validates: Requirements 3.2, 3.3
|
|
161
|
+
* - 3.2: Validates the account's entitlement based on configured entitlements
|
|
162
|
+
* - 3.3: Returns the customer-specific Layer_ARN if entitled
|
|
163
|
+
*/
|
|
164
|
+
checkEntitlement(accountId: string): Promise<LicensingResponse>;
|
|
165
|
+
/**
|
|
166
|
+
* Returns the number of entitled accounts.
|
|
167
|
+
*
|
|
168
|
+
* @returns The count of entitled accounts
|
|
169
|
+
*/
|
|
170
|
+
getEntitlementCount(): number;
|
|
171
|
+
/**
|
|
172
|
+
* Checks if a specific account is entitled (without async).
|
|
173
|
+
*
|
|
174
|
+
* @param accountId - The AWS account ID to check
|
|
175
|
+
* @returns true if the account is entitled
|
|
176
|
+
*/
|
|
177
|
+
isEntitled(accountId: string): boolean;
|
|
178
|
+
/**
|
|
179
|
+
* Gets the Layer ARN for an entitled account (without async).
|
|
180
|
+
*
|
|
181
|
+
* @param accountId - The AWS account ID
|
|
182
|
+
* @returns The Layer ARN if entitled, undefined otherwise
|
|
183
|
+
*/
|
|
184
|
+
getLayerArn(accountId: string): string | undefined;
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Creates a MockLicensingService with pre-configured entitlements.
|
|
188
|
+
*
|
|
189
|
+
* @param entitlements - Map of account IDs to Layer ARNs
|
|
190
|
+
* @returns A new MockLicensingService instance with the specified entitlements
|
|
191
|
+
*
|
|
192
|
+
* @example
|
|
193
|
+
* ```typescript
|
|
194
|
+
* const mockService = createMockLicensingService({
|
|
195
|
+
* '123456789012': 'arn:aws:lambda:us-east-1:999999999999:layer:LambdaKata:1',
|
|
196
|
+
* '987654321098': 'arn:aws:lambda:us-west-2:999999999999:layer:LambdaKata:2',
|
|
197
|
+
* });
|
|
198
|
+
* ```
|
|
199
|
+
*/
|
|
200
|
+
export declare function createMockLicensingService(entitlements?: Record<string, string>): MockLicensingService;
|
package/lib/types.d.ts
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type definitions for @lambda-kata/cdk
|
|
3
|
+
*
|
|
4
|
+
* These interfaces define the core data structures used by the kata() wrapper
|
|
5
|
+
* for transforming Node.js Lambda functions to use the Lambda Kata runtime.
|
|
6
|
+
*/
|
|
7
|
+
import { Runtime } from 'aws-cdk-lib/aws-lambda';
|
|
8
|
+
/**
|
|
9
|
+
* Configuration options for the kata() wrapper function.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* kata(myFunction, {
|
|
14
|
+
* unlicensedBehavior: 'fail',
|
|
15
|
+
* licensingEndpoint: 'https://custom-endpoint.example.com'
|
|
16
|
+
* });
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
export interface KataProps {
|
|
20
|
+
/**
|
|
21
|
+
* Optional: Override the licensing service endpoint
|
|
22
|
+
* Default: Lambda Kata production licensing endpoint
|
|
23
|
+
*/
|
|
24
|
+
licensingEndpoint?: string;
|
|
25
|
+
/**
|
|
26
|
+
* Optional: Behavior when account is not licensed
|
|
27
|
+
* 'warn' - Keep original Lambda, emit warning (default)
|
|
28
|
+
* 'fail' - Throw error and fail synthesis
|
|
29
|
+
*/
|
|
30
|
+
unlicensedBehavior?: 'warn' | 'fail';
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Response from the Lambda Kata licensing service.
|
|
34
|
+
*
|
|
35
|
+
* This interface represents the response returned when checking
|
|
36
|
+
* an AWS account's entitlement to use Lambda Kata.
|
|
37
|
+
*/
|
|
38
|
+
export interface LicensingResponse {
|
|
39
|
+
/**
|
|
40
|
+
* Whether the AWS account is entitled to use Lambda Kata
|
|
41
|
+
*/
|
|
42
|
+
entitled: boolean;
|
|
43
|
+
/**
|
|
44
|
+
* Customer-specific Lambda Layer ARN containing the Lambda Kata runtime.
|
|
45
|
+
* Only present if the account is entitled.
|
|
46
|
+
*/
|
|
47
|
+
layerArn?: string;
|
|
48
|
+
/**
|
|
49
|
+
* Human-readable status message
|
|
50
|
+
*/
|
|
51
|
+
message?: string;
|
|
52
|
+
/**
|
|
53
|
+
* Entitlement expiration date in ISO 8601 format.
|
|
54
|
+
* Only present if the account is entitled.
|
|
55
|
+
*/
|
|
56
|
+
expiresAt?: string;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Configuration for transforming a Lambda function to use Lambda Kata.
|
|
60
|
+
*
|
|
61
|
+
* This interface defines the transformation parameters applied to
|
|
62
|
+
* an entitled Lambda function.
|
|
63
|
+
*/
|
|
64
|
+
export interface TransformationConfig {
|
|
65
|
+
/**
|
|
66
|
+
* The original Node.js handler path (e.g., "index.handler")
|
|
67
|
+
* This will be stored in the config layer.
|
|
68
|
+
*/
|
|
69
|
+
originalHandler: string;
|
|
70
|
+
/**
|
|
71
|
+
* The target runtime for the transformed Lambda.
|
|
72
|
+
* Always Runtime.PYTHON_3_12 for Lambda Kata.
|
|
73
|
+
*/
|
|
74
|
+
targetRuntime: Runtime;
|
|
75
|
+
/**
|
|
76
|
+
* The handler path for the Lambda Kata runtime.
|
|
77
|
+
* Always "lambdakata.optimized_handler.lambda_handler"
|
|
78
|
+
*/
|
|
79
|
+
targetHandler: string;
|
|
80
|
+
/**
|
|
81
|
+
* Customer-specific Lambda Layer ARN containing the Lambda Kata runtime.
|
|
82
|
+
* Retrieved from the licensing service.
|
|
83
|
+
*/
|
|
84
|
+
layerArn: string;
|
|
85
|
+
/**
|
|
86
|
+
* Custom bundle path.
|
|
87
|
+
* If not specified, uses the default /opt/js_runtime/bundle.js
|
|
88
|
+
*
|
|
89
|
+
* @remarks
|
|
90
|
+
* Validates: Requirement 4.2
|
|
91
|
+
*/
|
|
92
|
+
bundlePath?: string;
|
|
93
|
+
/**
|
|
94
|
+
* Path to middleware TypeScript/JavaScript file.
|
|
95
|
+
* The file will be compiled with esbuild and included in the config layer.
|
|
96
|
+
* The middleware must export a function: (bundle, context) => handler
|
|
97
|
+
*
|
|
98
|
+
* @remarks
|
|
99
|
+
* Validates: Requirement 5.4
|
|
100
|
+
*/
|
|
101
|
+
middlewarePath?: string;
|
|
102
|
+
/**
|
|
103
|
+
* Inline handler resolver function.
|
|
104
|
+
* This TypeScript function will be serialized, compiled with esbuild,
|
|
105
|
+
* and included in the config layer as middleware.js
|
|
106
|
+
*
|
|
107
|
+
* @remarks
|
|
108
|
+
* Validates: Requirement for inline handler resolution
|
|
109
|
+
*/
|
|
110
|
+
handlerResolver?: (bundle: unknown, context: {
|
|
111
|
+
originalHandler: string;
|
|
112
|
+
}) => Function;
|
|
113
|
+
}
|