@lambda-kata/cdk 0.1.3-rc.67 → 0.1.3-rc.69

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.
@@ -23,6 +23,8 @@ export { MockLicensingService, createMockLicensingService, } from './mock-licens
23
23
  export { resolveAccountId, resolveAccountIdWithSource, isValidAccountIdFormat, AccountResolutionError, AccountResolutionResult, AccountResolverOptions, } from './account-resolver';
24
24
  export { resolveAccountIdSync, resolveAccountIdSyncWithSource, resolveRegionSync, SyncAccountResolutionError, SyncAccountResolutionResult, SyncAccountResolverOptions, } from './sync-account-resolver';
25
25
  export { kata, kataWithAccountId, applyTransformation, handleUnlicensed, isKataTransformed, getKataPromise, extractBundlePathFromHandler, KataWrapperOptions, KataResult, } from './kata-wrapper';
26
+ export { SnapStartActivator, SnapStartActivatorProps, } from './snapstart-construct';
27
+ export { activateSnapStart, SnapStartActivationResult, SnapStartActivatorConfig, } from './snapstart-activator';
26
28
  export { createKataConfigLayer, generateConfigContent, KataConfigLayerProps, CONFIG_DIR_NAME, CONFIG_FILE_NAME, HANDLER_CONFIG_KEY, } from './config-layer';
27
29
  export { EnsureNodeRuntimeLayerOptions, EnsureNodeRuntimeLayerResult, NodeVersionInfo, LayerInfo, LayerSearchOptions, LayerRequirements, LayerCreationOptions, Logger, RuntimeDetector, LayerManager, ErrorCodes, NodeRuntimeLayerError, VersionCacheEntry, LayerMetadata, NodejsLayerDeploymentOptions, NodejsLayerDeploymentResult, MultiArchitectureDeploymentResult, } from './nodejs-layer-manager';
28
30
  export { DockerRuntimeDetector, DockerRuntimeDetectorOptions, } from './docker-runtime-detector';
@@ -0,0 +1,101 @@
1
+ /**
2
+ * SnapStart Activator - Custom Resource Handler
3
+ *
4
+ * This module provides the Lambda handler for a CloudFormation Custom Resource
5
+ * that enables SnapStart on Lambda functions after deployment. SnapStart requires
6
+ * asynchronous waiting for snapshot creation, which cannot be done during CDK synthesis.
7
+ *
8
+ * The activation process:
9
+ * 1. Wait for function to be Active
10
+ * 2. Enable SnapStart configuration
11
+ * 3. Wait for configuration update
12
+ * 4. Publish new version (triggers snapshot creation)
13
+ * 5. Wait for snapshot to be ready (up to 3 minutes)
14
+ * 6. Create/update 'kata' alias pointing to the new version
15
+ *
16
+ * @module snapstart-activator
17
+ */
18
+ import { LambdaClient } from '@aws-sdk/client-lambda';
19
+ /**
20
+ * Custom Resource event from CloudFormation.
21
+ */
22
+ export interface CustomResourceEvent {
23
+ RequestType: 'Create' | 'Update' | 'Delete';
24
+ ServiceToken: string;
25
+ ResponseURL: string;
26
+ StackId: string;
27
+ RequestId: string;
28
+ ResourceType: string;
29
+ LogicalResourceId: string;
30
+ PhysicalResourceId?: string;
31
+ ResourceProperties: {
32
+ ServiceToken: string;
33
+ FunctionName: string;
34
+ AliasName?: string;
35
+ };
36
+ OldResourceProperties?: {
37
+ FunctionName: string;
38
+ AliasName?: string;
39
+ };
40
+ }
41
+ /**
42
+ * Custom Resource response to CloudFormation.
43
+ */
44
+ export interface CustomResourceResponse {
45
+ Status: 'SUCCESS' | 'FAILED';
46
+ Reason?: string;
47
+ PhysicalResourceId: string;
48
+ StackId: string;
49
+ RequestId: string;
50
+ LogicalResourceId: string;
51
+ Data?: {
52
+ Version?: string;
53
+ AliasName?: string;
54
+ AliasArn?: string;
55
+ OptimizationStatus?: string;
56
+ };
57
+ }
58
+ /**
59
+ * Result of SnapStart activation.
60
+ */
61
+ export interface SnapStartActivationResult {
62
+ version: string;
63
+ aliasName: string;
64
+ aliasArn: string;
65
+ optimizationStatus: string;
66
+ }
67
+ /**
68
+ * Configuration for SnapStart activation.
69
+ */
70
+ export interface SnapStartActivatorConfig {
71
+ /** Maximum time to wait for snapshot creation in seconds. Default: 180 (3 minutes) */
72
+ snapshotTimeoutSeconds?: number;
73
+ /** Polling interval in seconds. Default: 2 */
74
+ pollingIntervalSeconds?: number;
75
+ /** Alias name to create/update. Default: 'kata' */
76
+ aliasName?: string;
77
+ }
78
+ /**
79
+ * Activates SnapStart on a Lambda function.
80
+ *
81
+ * This function performs the full SnapStart activation cycle:
82
+ * 1. Ensures function is Active
83
+ * 2. Enables SnapStart configuration
84
+ * 3. Waits for configuration update
85
+ * 4. Publishes new version
86
+ * 5. Waits for snapshot creation
87
+ * 6. Creates/updates alias
88
+ *
89
+ * @param lambdaClient - AWS Lambda client
90
+ * @param functionName - Name or ARN of the Lambda function
91
+ * @param config - Optional configuration
92
+ * @returns Activation result with version and alias information
93
+ */
94
+ export declare function activateSnapStart(lambdaClient: LambdaClient, functionName: string, config?: SnapStartActivatorConfig): Promise<SnapStartActivationResult>;
95
+ /**
96
+ * Lambda handler for CloudFormation Custom Resource.
97
+ *
98
+ * This handler is invoked by CloudFormation when the custom resource
99
+ * is created, updated, or deleted.
100
+ */
101
+ export declare function handler(event: CustomResourceEvent): Promise<CustomResourceResponse>;
@@ -0,0 +1,87 @@
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 SnapStartActivator construct.
15
+ */
16
+ export interface SnapStartActivatorProps {
17
+ /**
18
+ * The Lambda function to enable SnapStart on.
19
+ */
20
+ targetFunction: IFunction;
21
+ /**
22
+ * The alias name to create/update.
23
+ * @default 'kata'
24
+ */
25
+ aliasName?: string;
26
+ /**
27
+ * Maximum time to wait for snapshot creation in seconds.
28
+ * @default 180 (3 minutes)
29
+ */
30
+ snapshotTimeoutSeconds?: number;
31
+ }
32
+ /**
33
+ * CDK Construct that enables SnapStart on a Lambda function after deployment.
34
+ *
35
+ * This construct creates a Custom Resource that:
36
+ * 1. Waits for the target function to be Active
37
+ * 2. Enables SnapStart configuration
38
+ * 3. Publishes a new version (triggers snapshot creation)
39
+ * 4. Waits for the snapshot to be ready
40
+ * 5. Creates/updates an alias pointing to the new version
41
+ *
42
+ * @example
43
+ * ```typescript
44
+ * const myFunction = new lambda.Function(this, 'MyFunction', { ... });
45
+ *
46
+ * new SnapStartActivator(this, 'SnapStart', {
47
+ * targetFunction: myFunction,
48
+ * aliasName: 'kata',
49
+ * });
50
+ * ```
51
+ */
52
+ export declare class SnapStartActivator extends Construct {
53
+ /**
54
+ * The alias name that was created/updated.
55
+ */
56
+ readonly aliasName: string;
57
+ /**
58
+ * The Custom Resource that manages SnapStart activation.
59
+ */
60
+ readonly resource: CustomResource;
61
+ /**
62
+ * The version number created by SnapStart activation.
63
+ * Available after deployment via CloudFormation outputs.
64
+ */
65
+ readonly versionRef: string;
66
+ /**
67
+ * The alias ARN created by SnapStart activation.
68
+ * Available after deployment via CloudFormation outputs.
69
+ */
70
+ readonly aliasArnRef: string;
71
+ constructor(scope: Construct, id: string, props: SnapStartActivatorProps);
72
+ /**
73
+ * Creates the Lambda function that handles Custom Resource events.
74
+ */
75
+ private createProviderFunction;
76
+ /**
77
+ * Grants necessary permissions to the provider function.
78
+ */
79
+ private grantPermissions;
80
+ /**
81
+ * Generates the inline handler code for the Custom Resource.
82
+ *
83
+ * This is a self-contained version of the snapstart-activator logic
84
+ * that can be deployed as inline Lambda code.
85
+ */
86
+ private generateHandlerCode;
87
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lambda-kata/cdk",
3
- "version": "0.1.3-rc.67",
3
+ "version": "0.1.3-rc.69",
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",