@lambda-kata/cdk 0.1.3-rc.84 → 0.1.3-rc.85

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.
@@ -0,0 +1,82 @@
1
+ """
2
+ Lambda Kata Bootstrap Handler
3
+
4
+ Resilient entry point that delegates to lambdakata.optimized_handler
5
+ from the Lambda Kata Layer. Ensures SnapStart snapshot creation succeeds
6
+ by catching init errors gracefully.
7
+
8
+ Copyright (C) 2025-present Raman Marozau, Work Target Insight Function.
9
+ SPDX-License-Identifier: Apache-2.0
10
+ """
11
+
12
+ import json
13
+ import os
14
+ import sys
15
+ import traceback
16
+
17
+
18
+ # ---------------------------------------------------------------------------
19
+ # INIT PHASE — executed once during cold start / SnapStart snapshot creation
20
+ # ---------------------------------------------------------------------------
21
+
22
+ _real_handler = None
23
+ _init_error = None
24
+ _init_diagnostics = {}
25
+
26
+ try:
27
+ _init_diagnostics = {
28
+ "python_version": sys.version,
29
+ "opt_contents": sorted(os.listdir("/opt")) if os.path.isdir("/opt") else [],
30
+ "opt_python_exists": os.path.isdir("/opt/python"),
31
+ "lambdakata_in_opt": (
32
+ os.path.isdir("/opt/lambdakata")
33
+ or os.path.isdir("/opt/python/lambdakata")
34
+ ),
35
+ }
36
+
37
+ from lambdakata.optimized_handler import lambda_handler as _real_handler # type: ignore[import-untyped]
38
+
39
+ except ImportError as exc:
40
+ _init_error = exc
41
+ _init_diagnostics["import_error"] = str(exc)
42
+ _init_diagnostics["traceback"] = traceback.format_exc()
43
+ print(
44
+ f"[Lambda Kata] WARNING: Failed to import lambdakata.optimized_handler: {exc}",
45
+ file=sys.stderr,
46
+ )
47
+
48
+ except Exception as exc: # noqa: BLE001 — intentional broad catch for resilience
49
+ _init_error = exc
50
+ _init_diagnostics["init_error"] = str(exc)
51
+ _init_diagnostics["error_type"] = type(exc).__name__
52
+ _init_diagnostics["traceback"] = traceback.format_exc()
53
+ print(
54
+ f"[Lambda Kata] WARNING: Init error: {type(exc).__name__}: {exc}",
55
+ file=sys.stderr,
56
+ )
57
+
58
+
59
+ # ---------------------------------------------------------------------------
60
+ # HANDLER
61
+ # ---------------------------------------------------------------------------
62
+
63
+ def handler(event, context):
64
+ """Delegate to the real Lambda Kata handler, or return diagnostics."""
65
+ if _real_handler is not None:
66
+ return _real_handler(event, context)
67
+
68
+ body = {
69
+ "error": "Lambda Kata runtime initialization failed",
70
+ "message": str(_init_error) if _init_error else "Unknown",
71
+ "error_type": type(_init_error).__name__ if _init_error else "Unknown",
72
+ "diagnostics": {
73
+ "lambdakata_in_opt": _init_diagnostics.get("lambdakata_in_opt", False),
74
+ "opt_python_exists": _init_diagnostics.get("opt_python_exists", False),
75
+ "opt_contents": _init_diagnostics.get("opt_contents", []),
76
+ },
77
+ }
78
+ print(
79
+ f"[Lambda Kata] Runtime not initialized: {json.dumps(body)}",
80
+ file=sys.stderr,
81
+ )
82
+ return {"statusCode": 503, "body": json.dumps(body)}
@@ -136,20 +136,20 @@ export declare const BOOTSTRAP_HANDLER_MODULE = "kata_bootstrap";
136
136
  */
137
137
  export declare const BOOTSTRAP_HANDLER_PATH = "kata_bootstrap.handler";
138
138
  /**
139
- * Resolves the absolute path to the compiled bootstrap handler .pyc file.
139
+ * Resolves the absolute path to the bootstrap handler .py source file.
140
140
  *
141
141
  * Two resolution paths:
142
- * 1. Production (bundled JS / npm package): out/dist/python/kata_bootstrap.pyc
143
- * __dirname = out/dist/ → __dirname/python/kata_bootstrap.pyc
144
- * 2. Development (ts-jest / source): src/python/dist/kata_bootstrap.pyc
145
- * __dirname = src/ → __dirname/python/dist/kata_bootstrap.pyc
142
+ * 1. Production (bundled JS / npm package): out/dist/python/kata_bootstrap.py
143
+ * __dirname = out/dist/ → __dirname/python/kata_bootstrap.py
144
+ * 2. Development (ts-jest / source): src/python/kata_bootstrap.py
145
+ * __dirname = src/ → __dirname/python/kata_bootstrap.py
146
146
  *
147
- * @returns Absolute path to kata_bootstrap.pyc
148
- * @throws Error if the compiled .pyc is not found (build step was skipped)
147
+ * @returns Absolute path to kata_bootstrap.py
148
+ * @throws Error if the source file is not found
149
149
  *
150
150
  * @internal
151
151
  */
152
- export declare function resolveBootstrapPycPath(): string;
152
+ export declare function resolveBootstrapPyPath(): string;
153
153
  /**
154
154
  * Creates a Lambda Layer containing the kata configuration.
155
155
  *
@@ -25,7 +25,7 @@ export { resolveAccountIdSync, resolveAccountIdSyncWithSource, resolveRegionSync
25
25
  export { kata, kataWithAccountId, applyTransformation, handleUnlicensed, isKataTransformed, getKataPromise, extractBundlePathFromHandler, KataWrapperOptions, KataResult, } from './kata-wrapper';
26
26
  export { SnapStartActivator, SnapStartActivatorProps, } from './snapstart-construct';
27
27
  export { activateSnapStart, handler as snapStartHandler, SnapStartActivationResult, SnapStartActivatorConfig, CustomResourceEvent, CustomResourceResponse, } from './snapstart-activator';
28
- export { createKataConfigLayer, generateConfigContent, resolveBootstrapPycPath, KataConfigLayerProps, CONFIG_DIR_NAME, CONFIG_FILE_NAME, HANDLER_CONFIG_KEY, BOOTSTRAP_HANDLER_MODULE, BOOTSTRAP_HANDLER_PATH, } from './config-layer';
28
+ export { createKataConfigLayer, generateConfigContent, resolveBootstrapPyPath, KataConfigLayerProps, CONFIG_DIR_NAME, CONFIG_FILE_NAME, HANDLER_CONFIG_KEY, BOOTSTRAP_HANDLER_MODULE, BOOTSTRAP_HANDLER_PATH, } from './config-layer';
29
29
  export { EnsureNodeRuntimeLayerOptions, EnsureNodeRuntimeLayerResult, NodeVersionInfo, LayerInfo, LayerSearchOptions, LayerRequirements, LayerCreationOptions, Logger, RuntimeDetector, LayerManager, ErrorCodes, NodeRuntimeLayerError, VersionCacheEntry, LayerMetadata, NodejsLayerDeploymentOptions, NodejsLayerDeploymentResult, MultiArchitectureDeploymentResult, } from './nodejs-layer-manager';
30
30
  export { DockerRuntimeDetector, DockerRuntimeDetectorOptions, } from './docker-runtime-detector';
31
31
  export { AWSLayerManager, AWSLayerManagerOptions, } from './aws-layer-manager';
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "@lambda-kata/cdk",
3
- "version": "0.1.3-rc.84",
3
+ "version": "0.1.3-rc.85",
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",
7
7
  "scripts": {
8
- "build:python": "python3 src/python/compile.py && mkdir -p out/dist/python && cp src/python/dist/kata_bootstrap.pyc out/dist/python/kata_bootstrap.pyc",
8
+ "build:python": "python3 src/python/compile.py && mkdir -p out/dist/python && cp src/python/kata_bootstrap.py out/dist/python/kata_bootstrap.py",
9
9
  "build": "rm -rf ./dist && rm -rf ./out && rm -rf ./lib && yarn run build:cdk && yarn run types && yarn run build:python",
10
10
  "types": "tsc --emitDeclarationOnly && tsc-alias",
11
11
  "build:cdk": "yarn run build:config && node dist/utils/build.js --target=cdk",
Binary file