部署和测试Lambda函数时出错



你能帮忙吗我有一个名为insertaurora.ts 的lambda函数

我把lambda称为

const insertaurora = new lambda.Function(this,'LambdaHandler',{
runtime : lambda.Runtime.NODEJS_16_X,
code : lambda.Code.fromAsset(path.join(__dirname, '/../lambda/')),
handler : 'insertaurora.handler'
});

以下是我的tsconfig

{
"compilerOptions": {
"target": "es2020",
"strict": true,
"preserveConstEnums": true,
"noEmit": true,
"sourceMap": false,
"module":"commonjs",
"moduleResolution":"node",
"esModuleInterop": true, 
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true, 
"isolatedModules": true, 
},
"exclude": ["node_modules", "**/*.test.ts"]
}

/*{
"compilerOptions": {
"target": "ES2020",
"module": "commonjs",
"lib": [
"es2018"
],
"declaration": true,
"strict": true,
"noImplicitAny": true,
"strictNullChecks": true,
"noImplicitThis": true,
"alwaysStrict": true,
"noUnusedLocals": false,
"noUnusedParameters": false,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": false,
"inlineSourceMap": true,
"inlineSources": true,
"experimentalDecorators": true,
"strictPropertyInitialization": false,
"typeRoots": [
"./node_modules/@types"
]
},
"exclude": [
"node_modules",
"cdk.out"
]
}*/

package.json
{
"name": "lambda-cdk",
"version": "0.1.0",
"bin": {
"lambda-cdk": "bin/lambda-cdk.js"
},
"scripts": {
"compile": "tsc",
"watch": "tsc -w",
"test": "jest",
"cdk": "cdk",

},
"devDependencies": {
"@types/jest": "^27.5.2",
"@types/node": "10.17.27",
"@types/pg": "^8.6.5",
"@types/prettier": "2.6.0",
"aws-cdk-lib": "2.38.0",
"jest": "^27.5.1",
"ts-jest": "^27.1.4",
"ts-node": "^10.9.1",
"typescript": "~3.9.7"
},
"dependencies": {
"@aws-sdk/client-rds": "^3.161.0",
"@aws-sdk/client-secrets-manager": "^3.163.0",
"aws-cdk-lib": "2.38.0",
"cctx": "^1.0.1",
"pg": "^8.8.0",
"yn": "^5.0.0"
}
}

当我尝试部署和测试时,我得到了以下错误

"errorType":"Runtime.ImportModuleError";,"errorMessage":"错误:找不到模块"insertaurora"\n要求堆栈:\n-/var/runtime/index.mjs","trace":["Runtime.ImportModuleError:错误:找不到模块"insertaurora";,"需要堆栈:";,"-/var/runtime/index.mjs";,"在_loadUserApp(file:///var/runtime/index.mjs:951:17)&";,"在异步Object.UserFunction.js.module.exports.load(file:///var/runtime/index.mjs:976:21)&";,"异步启动时(file:///var/runtime/index.mjs:1137:23)&";,"异步file:///var/runtime/index.mjs:1143:1"]

你能帮忙吗?

我们还有通过apigateway连接到lambda的示例吗λ应该连接到aurora以插入数据

lambda应该是具有.ts扩展名的类型脚本文件

错误消息指示它找不到名为insertaurora的lambda文件,该文件应该包含处理程序。

我在这里有一个示例项目

最新更新