@lambda-kata/cdk 0.1.3-rc.8 → 0.1.3-rc.81
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 +58 -107
- package/out/tsc/src/aws-layer-manager.d.ts +163 -10
- package/out/tsc/src/docker-runtime-detector.d.ts +1 -1
- package/out/tsc/src/index.d.ts +5 -2
- package/out/tsc/src/kata-wrapper.d.ts +46 -28
- package/out/tsc/src/mock-licensing.d.ts +18 -0
- package/out/tsc/src/nodejs-layer-manager.d.ts +128 -0
- package/out/tsc/src/snapstart-activator.d.ts +89 -0
- package/out/tsc/src/snapstart-construct.d.ts +118 -0
- package/out/tsc/src/sync-account-resolver.d.ts +63 -0
- package/out/tsc/src/types.d.ts +15 -1
- package/package.json +11 -3
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SnapStart Construct - CDK Custom Resource for SnapStart Activation
|
|
3
|
+
*
|
|
4
|
+
* This module provides a CDK construct that creates a Custom Resource
|
|
5
|
+
* to enable SnapStart on Lambda functions after deployment. The construct
|
|
6
|
+
* handles the asynchronous nature of SnapStart snapshot creation.
|
|
7
|
+
*
|
|
8
|
+
* @module snapstart-construct
|
|
9
|
+
*/
|
|
10
|
+
import { Construct } from 'constructs';
|
|
11
|
+
import { CustomResource } from 'aws-cdk-lib';
|
|
12
|
+
import { IFunction } from 'aws-cdk-lib/aws-lambda';
|
|
13
|
+
/**
|
|
14
|
+
* Properties for the {@link SnapStartActivator} construct.
|
|
15
|
+
*
|
|
16
|
+
* @see {@link SnapStartActivator} for the construct that consumes these properties
|
|
17
|
+
*/
|
|
18
|
+
export interface SnapStartActivatorProps {
|
|
19
|
+
/**
|
|
20
|
+
* The Lambda function to enable SnapStart on.
|
|
21
|
+
* The construct will add a dependency so the Custom Resource runs after this function is created.
|
|
22
|
+
*/
|
|
23
|
+
targetFunction: IFunction;
|
|
24
|
+
/**
|
|
25
|
+
* The alias name to create or update after publishing a SnapStart-enabled version.
|
|
26
|
+
* @default 'kata'
|
|
27
|
+
*/
|
|
28
|
+
aliasName?: string;
|
|
29
|
+
/**
|
|
30
|
+
* Maximum time in seconds to wait for SnapStart snapshot creation.
|
|
31
|
+
* The Custom Resource handler timeout is set to this value plus a 60-second buffer.
|
|
32
|
+
* @default 180
|
|
33
|
+
*/
|
|
34
|
+
snapshotTimeoutSeconds?: number;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* CDK Construct that enables SnapStart on a Lambda function after deployment.
|
|
38
|
+
*
|
|
39
|
+
* Creates a CloudFormation Custom Resource backed by a Lambda handler that
|
|
40
|
+
* performs the full SnapStart activation cycle during stack deployment:
|
|
41
|
+
*
|
|
42
|
+
* 1. Waits for the target function to reach Active state
|
|
43
|
+
* 2. Enables SnapStart configuration (`ApplyOn: PublishedVersions`)
|
|
44
|
+
* 3. Publishes a new version (triggers snapshot creation)
|
|
45
|
+
* 4. Polls until the snapshot is ready (or timeout is reached)
|
|
46
|
+
* 5. Creates or updates an alias pointing to the new version — ALWAYS, regardless of snapshot outcome
|
|
47
|
+
*
|
|
48
|
+
* After deployment, the published version number and alias ARN are available
|
|
49
|
+
* as CloudFormation attributes via {@link versionRef} and {@link aliasArnRef}.
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* ```typescript
|
|
53
|
+
* const myFunction = new lambda.Function(this, 'MyFunction', { ... });
|
|
54
|
+
*
|
|
55
|
+
* const snapStart = new SnapStartActivator(this, 'SnapStart', {
|
|
56
|
+
* targetFunction: myFunction,
|
|
57
|
+
* aliasName: 'kata',
|
|
58
|
+
* snapshotTimeoutSeconds: 180,
|
|
59
|
+
* });
|
|
60
|
+
*
|
|
61
|
+
* // Reference outputs after deployment
|
|
62
|
+
* new CfnOutput(this, 'Version', { value: snapStart.versionRef });
|
|
63
|
+
* new CfnOutput(this, 'AliasArn', { value: snapStart.aliasArnRef });
|
|
64
|
+
* ```
|
|
65
|
+
*
|
|
66
|
+
* @see {@link SnapStartActivatorProps} for configuration options
|
|
67
|
+
*/
|
|
68
|
+
export declare class SnapStartActivator extends Construct {
|
|
69
|
+
/**
|
|
70
|
+
* The alias name that was created or updated (e.g. "kata").
|
|
71
|
+
*
|
|
72
|
+
* This is a static property set at synthesis time from {@link SnapStartActivatorProps.aliasName}.
|
|
73
|
+
*/
|
|
74
|
+
readonly aliasName: string;
|
|
75
|
+
/**
|
|
76
|
+
* The Custom Resource that manages SnapStart activation during deployment.
|
|
77
|
+
*
|
|
78
|
+
* Use this to add additional dependencies or access CloudFormation attributes.
|
|
79
|
+
*/
|
|
80
|
+
readonly resource: CustomResource;
|
|
81
|
+
/**
|
|
82
|
+
* The version number created by SnapStart activation (CloudFormation attribute).
|
|
83
|
+
*
|
|
84
|
+
* This value is resolved at deployment time when the Custom Resource handler
|
|
85
|
+
* publishes a new Lambda version. Use it in `CfnOutput` or other constructs
|
|
86
|
+
* that need to reference the published version.
|
|
87
|
+
*/
|
|
88
|
+
readonly versionRef: string;
|
|
89
|
+
/**
|
|
90
|
+
* The alias ARN created by SnapStart activation (CloudFormation attribute).
|
|
91
|
+
*
|
|
92
|
+
* This value is resolved at deployment time when the Custom Resource handler
|
|
93
|
+
* creates or updates the alias. Use it in `CfnOutput` or other constructs
|
|
94
|
+
* that need to reference the alias.
|
|
95
|
+
*/
|
|
96
|
+
readonly aliasArnRef: string;
|
|
97
|
+
constructor(scope: Construct, id: string, props: SnapStartActivatorProps);
|
|
98
|
+
/**
|
|
99
|
+
* Creates the Lambda function that handles Custom Resource events.
|
|
100
|
+
* Permissions are passed via initialPolicy to ensure they are part of the
|
|
101
|
+
* role creation (not a separate AWS::IAM::Policy resource), preventing
|
|
102
|
+
* IAM propagation race conditions.
|
|
103
|
+
*/
|
|
104
|
+
private createProviderFunction;
|
|
105
|
+
/**
|
|
106
|
+
* Generates the inline handler code for the Custom Resource.
|
|
107
|
+
*
|
|
108
|
+
* This is a self-contained version of the snapstart-activator logic
|
|
109
|
+
* that can be deployed as inline Lambda code.
|
|
110
|
+
*
|
|
111
|
+
* Matches the proven deploy_lambda.py reference:
|
|
112
|
+
* - ONE publish, poll, ALWAYS create alias regardless of snapshot outcome
|
|
113
|
+
* - No retries on Failed state
|
|
114
|
+
* - On Update errors → return SUCCESS (prevent rollback deadlock)
|
|
115
|
+
* - On Create errors → throw (return FAILED)
|
|
116
|
+
*/
|
|
117
|
+
private generateHandlerCode;
|
|
118
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Synchronous Account ID Resolution for Lambda Kata CDK Integration
|
|
3
|
+
*
|
|
4
|
+
* This module provides synchronous account ID resolution for use during
|
|
5
|
+
* CDK synthesis, which requires synchronous operations.
|
|
6
|
+
*
|
|
7
|
+
* Resolution strategies (in order of precedence):
|
|
8
|
+
* 1. CDK context value (explicit configuration)
|
|
9
|
+
* 2. Stack account (if not a token/unresolved)
|
|
10
|
+
* 3. Environment variables (AWS_ACCOUNT_ID, CDK_DEFAULT_ACCOUNT)
|
|
11
|
+
* 4. STS GetCallerIdentity via execSync (fallback)
|
|
12
|
+
*
|
|
13
|
+
* @module sync-account-resolver
|
|
14
|
+
*/
|
|
15
|
+
import { Construct } from 'constructs';
|
|
16
|
+
/**
|
|
17
|
+
* Error thrown when account ID cannot be resolved through any strategy.
|
|
18
|
+
*/
|
|
19
|
+
export declare class SyncAccountResolutionError extends Error {
|
|
20
|
+
constructor(message: string);
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Result of account ID resolution, including the source of the resolution.
|
|
24
|
+
*/
|
|
25
|
+
export interface SyncAccountResolutionResult {
|
|
26
|
+
accountId: string;
|
|
27
|
+
source: 'context' | 'stack' | 'env' | 'sts';
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Options for synchronous account ID resolution.
|
|
31
|
+
*/
|
|
32
|
+
export interface SyncAccountResolverOptions {
|
|
33
|
+
/**
|
|
34
|
+
* Whether to skip the STS fallback (useful for testing).
|
|
35
|
+
* Default: false
|
|
36
|
+
*/
|
|
37
|
+
skipStsFallback?: boolean;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Resolves the target AWS account ID synchronously.
|
|
41
|
+
*
|
|
42
|
+
* This function attempts to determine the AWS account ID using multiple
|
|
43
|
+
* strategies in order of precedence:
|
|
44
|
+
*
|
|
45
|
+
* 1. **CDK Context**: Checks for `aws:cdk:account` context value
|
|
46
|
+
* 2. **Stack Account**: Uses the Stack's account if it's not a token
|
|
47
|
+
* 3. **Environment Variables**: Checks AWS_ACCOUNT_ID, CDK_DEFAULT_ACCOUNT
|
|
48
|
+
* 4. **STS Fallback**: Calls AWS CLI sts get-caller-identity
|
|
49
|
+
*
|
|
50
|
+
* @param scope - The CDK construct scope to resolve the account for
|
|
51
|
+
* @param options - Optional configuration for resolution behavior
|
|
52
|
+
* @returns The AWS account ID (12-digit string)
|
|
53
|
+
* @throws SyncAccountResolutionError if account cannot be resolved
|
|
54
|
+
*/
|
|
55
|
+
export declare function resolveAccountIdSync(scope: Construct, options?: SyncAccountResolverOptions): string;
|
|
56
|
+
/**
|
|
57
|
+
* Resolves the target AWS account ID synchronously with source information.
|
|
58
|
+
*/
|
|
59
|
+
export declare function resolveAccountIdSyncWithSource(scope: Construct, options?: SyncAccountResolverOptions): SyncAccountResolutionResult;
|
|
60
|
+
/**
|
|
61
|
+
* Resolves the deployment region synchronously.
|
|
62
|
+
*/
|
|
63
|
+
export declare function resolveRegionSync(scope: Construct): string;
|
package/out/tsc/src/types.d.ts
CHANGED
|
@@ -41,10 +41,19 @@ export interface LicensingResponse {
|
|
|
41
41
|
*/
|
|
42
42
|
entitled: boolean;
|
|
43
43
|
/**
|
|
44
|
-
*
|
|
44
|
+
* Base Lambda Layer ARN (without version number).
|
|
45
45
|
* Only present if the account is entitled.
|
|
46
|
+
* @deprecated Use layerVersionArn for attaching to Lambda functions
|
|
46
47
|
*/
|
|
47
48
|
layerArn?: string;
|
|
49
|
+
/**
|
|
50
|
+
* Full Lambda Layer Version ARN (with version number).
|
|
51
|
+
* This is the ARN that should be used when attaching layers to Lambda functions.
|
|
52
|
+
* Only present if the account is entitled.
|
|
53
|
+
*
|
|
54
|
+
* @example "arn:aws:lambda:eu-central-1:113258654684:layer:lambda-kata-euc:1"
|
|
55
|
+
*/
|
|
56
|
+
layerVersionArn?: string;
|
|
48
57
|
/**
|
|
49
58
|
* Human-readable status message
|
|
50
59
|
*/
|
|
@@ -67,6 +76,11 @@ export interface TransformationConfig {
|
|
|
67
76
|
* This will be stored in the config layer.
|
|
68
77
|
*/
|
|
69
78
|
originalHandler: string;
|
|
79
|
+
/**
|
|
80
|
+
* The original Node.js runtime (e.g., "nodejs20.x").
|
|
81
|
+
* Used to create the appropriate Node.js runtime layer.
|
|
82
|
+
*/
|
|
83
|
+
originalRuntime?: string;
|
|
70
84
|
/**
|
|
71
85
|
* The target runtime for the transformed Lambda.
|
|
72
86
|
* Always Runtime.PYTHON_3_12 for Lambda Kata.
|
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.81",
|
|
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/**/*",
|
|
@@ -50,11 +50,14 @@
|
|
|
50
50
|
},
|
|
51
51
|
"peerDependencies": {
|
|
52
52
|
"aws-cdk-lib": "^2.0.0",
|
|
53
|
-
"constructs": "^10.0.0"
|
|
53
|
+
"constructs": "^10.0.0",
|
|
54
|
+
"esbuild": "^0.23.0"
|
|
54
55
|
},
|
|
55
56
|
"dependencies": {
|
|
56
57
|
"@aws-sdk/client-lambda": "^3.500.0",
|
|
58
|
+
"@aws-sdk/client-s3": "^3.500.0",
|
|
57
59
|
"@aws-sdk/client-sts": "^3.500.0",
|
|
60
|
+
"@lambda-kata/licensing": "0.1.32",
|
|
58
61
|
"dotenv": "^17.2.3",
|
|
59
62
|
"reflect-metadata": "^0.2.2"
|
|
60
63
|
},
|
|
@@ -73,5 +76,10 @@
|
|
|
73
76
|
"ts-jest": "^29.1.2",
|
|
74
77
|
"tsc-alias": "^1.8.16",
|
|
75
78
|
"typescript": "^5.3.3"
|
|
79
|
+
},
|
|
80
|
+
"peerDependenciesMeta": {
|
|
81
|
+
"esbuild": {
|
|
82
|
+
"optional": true
|
|
83
|
+
}
|
|
76
84
|
}
|
|
77
85
|
}
|