Hey, as this a Lambda function with custom bundling. You would need to define the tsconfig, run the tsc command in the bundling. by default Lambda expects a index.mjs file as the handler file, you would need create a index.ts .
new Function(stk, "say-hello", {
handler: "index.handler",
runtime: Runtime.NODEJS_22_X,
timeout: Duration.seconds(20),
architecture: Architecture.X86_64,
code: Code.fromAsset(handlerPath, {
bundling: {
image: DockerImage.fromRegistry("dummy"),
local: {
tryBundle(outputDir: string) {
// Create a package.json in the output directory
execSync(
`cp ${path.join(handlerPath, "package.json")} ${outputDir}`,
{ stdio: "inherit" }
);
// Install dependencies including TypeScript
execSync(
`cd ${outputDir} && npm install onnxruntime-node typescript @types/node`,
{ stdio: "inherit" }
);
// Copy the handler code and tsconfig
execSync(`cp -r ${handlerPath}/* ${outputDir}`, { stdio: "inherit" });
// Create a minimal tsconfig.json if it doesn't exist
const tsConfig = {
compilerOptions: {
target: "es2022",
module: "node16",
moduleResolution: "node16",
esModuleInterop: true,
strict: true,
outDir: "dist",
},
include: ["*.ts"],
exclude: ["node_modules"],
};
fs.writeFileSync(
path.join(outputDir, "tsconfig.json"),
JSON.stringify(tsConfig, null, 2)
);
// Transpile TypeScript
execSync(`cd ${outputDir} && npx tsc`, { stdio: "inherit" });
// Move compiled files to root and cleanup
execSync(`cd ${outputDir} && mv dist/* . && rm -rf dist`, {
stdio: "inherit",
});
return true;
},
},
},
}),
});
While i am defining all in the bundling, you can create a folder with the required files on lambda function then define the compilation steps in the bundling
https://github.com/aws-samples/cdk-lambda-bundling/blob/main/lib/cdk-bundling-lambda-stack.ts
https://docs.aws.amazon.com/lambda/latest/dg/lambda-cdk-tutorial.html
wanted to quickly understand your use case. is there a requirement to use onnxruntime-node in your function?