Error while deploying and testing Lambda function

Viewed 59

Can you help I have a lambda function with name insertaurora.ts

and i am calling the lambda as below

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

Following is my 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"
  }
}

When i try to deploy and test i am getting the following error

"errorType": "Runtime.ImportModuleError", "errorMessage": "Error: Cannot find module 'insertaurora'\nRequire stack:\n- /var/runtime/index.mjs", "trace": [ "Runtime.ImportModuleError: Error: Cannot find module 'insertaurora'", "Require stack:", "- /var/runtime/index.mjs", " at _loadUserApp (file:///var/runtime/index.mjs:951:17)", " at async Object.UserFunction.js.module.exports.load (file:///var/runtime/index.mjs:976:21)", " at async start (file:///var/runtime/index.mjs:1137:23)", " at async file:///var/runtime/index.mjs:1143:1" ]

Can you help?

Also do we have any sample that connects to lambda via apigateway and the lambda should be connecting to aurora to insert data

lambda should be a typescript file with .ts extension

1 Answers

The error message indicates that it cannot find your lambda file named insertaurora, which should contain the handler.

I have an example project here

Related