Closed jtwp closed 5 years ago
I'm not able to reproduce the issue when running lambda with Node10.x runtime.
Does this apply to all events received by Lambda or a specific event we can try reproducing with?
Is there any chance when creating a package via make package
you had a different NodeJS version than 10.x?
I have removed and deployed it all again using "nodejs10.x" as the Runtime in the CF template, and got the same error. If I switch the run time back to "Node.js 8.10" in the Lambda function directly it works, change back to "Node.js 10.x" I get the error.
Maybe I missed something in the package, but then it's strange that 8.10 works and 10.x doesn't.
I have deployed it another AWS account and it works there for both 8.10 and 10.x, so something is up somewhere. Funny thing is it's the exact same deployment method for both. I'll keep looking...
How are you creating the deployable package? Can you confirm that you are running Node 10 locally when it does npm install
?
It's okay now, all working. I think something went wrong during the make, but was my issue. Thanks!
I'm actually getting this same error with the nodejs10.x runtime. Can't for the life of me figure out what is going on.
The woes of changing runtime versions :( There’s a pre-built zip attached to the release. Or, maybe try clearing your local npm caches before rebuilding?
I've updated my local node and npm versions. Purged node_modules and run npm install --production
. I'm actually packaging aws-to-slack as part of another project, for deploying aws-to-slack via terraform, https://github.com/plus3it/terraform-aws-slack-notifier.
Running make package
generates a package with this structure:
$ tree -L 2
.
├── node_modules
│ └── lodash
├── package-lock.json
├── package.json
└── src
├── eventdef.js
├── index.js
├── parsers
├── ses.js
└── slack.js
4 directories, 7 files
The terraform project generates this structure (with a lambda handler of aws-to-slack/src/index.handler
):
$ tree -L 1
.
├── aws-to-slack
└── lodash
2 directories, 1 file
This worked fine in nodejs6 and nodejs8. I'm far from a nodejs expert, so I'm guessing something in nodejs10.x
is requiring a different project structure?
yeah, with nodejs10.x the dependencies need to be in the node_modules
directory. no longer works if they are just in the root. dang it. that makes it harder to wrap/vendor nodejs projects and dependencies... i.e. this package structure is working:
$ tree -L 2
.
├── aws-to-slack
│ ├── LICENSE
│ ├── Makefile
│ ├── README.md
│ ├── cloudformation.yaml
│ ├── docs
│ ├── package.json
│ ├── src
│ └── test
└── node_modules
└── lodash
Ok, patch for that project that looks to be working... https://github.com/plus3it/terraform-aws-slack-notifier/pull/23
Wow, @lorengordon thank you for sharing your findings!
With the recent announcement about the depreciation of Node.js 8.10, at the end of the year, I tested this using the Nodejs10.x run time, and am receiving the following error when it executes the function:
{ "errorType": "Runtime.ImportModuleError", "errorMessage": "Error: Cannot find module 'lodash'", "trace": [ "Runtime.ImportModuleError: Error: Cannot find module 'lodash'", " 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)" ] }
Just wonder if anyone else is seeing this?