aws-cdk-examples icon indicating copy to clipboard operation
aws-cdk-examples copied to clipboard

Execution Error: Cannot find module 'uuid/v4 in typescript ApiLambdaCrudDynamoDBExample

Open tinynet opened this issue 6 years ago • 2 comments

:bug: Bug Report

Error executing the create function in typescript/api-cors-lambda-crud-dynamodb project

What is the problem?

The RestApiCrudLambdaDynamoDB-createItem lambda function cannot be executed because cannot find module 'uuid/v4'. The project deploys an API gateway integrated with lambda functions that execute simple CRUD on a DynamoDB table.

Reproduction Steps

Simply install, build, deploy, and test the function with API gateway:

  $ npm install
  $ npm run build
  $ cdk synth
  $ cdk deploy

When it's deployed, in the API gateway, test the POST method on /items/ resource. You can set body = {}

Verbose Log

From the lambda logs:

{
    "errorType": "Runtime.ImportModuleError",
    "errorMessage": "Error: Cannot find module 'uuid/v4'",
    "stack": [
        "Runtime.ImportModuleError: Error: Cannot find module 'uuid/v4'",
        "    at _loadUserApp (/var/runtime/UserFunction.js:100:13)",
        "    at Object.module.exports.load (/var/runtime/UserFunction.js:140:17)",
        "    at Object.<anonymous> (/var/runtime/index.js:45:30)",
        "    at Module._compile (internal/modules/cjs/loader.js:778:30)",
        "    at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)",
        "    at Module.load (internal/modules/cjs/loader.js:653:32)",
        "    at tryModuleLoad (internal/modules/cjs/loader.js:593:12)",
        "    at Function.Module._load (internal/modules/cjs/loader.js:585:3)",
        "    at Function.Module.runMain (internal/modules/cjs/loader.js:831:12)",
        "    at startup (internal/bootstrap/node.js:283:19)"
    ]
}

Environment

  • CDK CLI Version: 1.75.0 (build 7708242)
  • Example: api-cors-lambda-crud-dynamodb
  • Example Version: #207
  • OS: OSX Catalina
  • Language: Typescript

Other information

It seems a known problem But I could not make it work. I changed the require statement as mentioned in SO, but same result:

const {"v4": uuidv4} = require('uuid');

Probably it will work uploading manually the module, but I'd like to solve it with cdk.

tinynet avatar Nov 29 '20 16:11 tinynet

Missed duplicate. This is a duplicate of #276

NGL321 avatar Jan 04 '21 04:01 NGL321

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see. If you need more assistance, please either tag a team member or open a new issue that references this one. If you wish to keep having a conversation with other community members under this issue feel free to do so.

github-actions[bot] avatar Jan 04 '21 04:01 github-actions[bot]