Can I use WebWorkers in AWS Lambda (node 6.10)

爷,独闯天下 提交于 2019-12-24 08:09:40

问题


I've got a very simple node module that I want in AWS lambda, and its importing 'Natural' for some text processing.

This line throws the error: var n = require('natural');

The error is this:

{
  "errorMessage": "/var/task/node_modules/webworker-threads/build/Release/WebWorkerThreads.node: invalid ELF header",
  "errorType": "Error",
  "stackTrace": [
    "Module.load (module.js:487:32)",
    "tryModuleLoad (module.js:446:12)",
    "Function.Module._load (module.js:438:3)",
    "Module.require (module.js:497:17)",
    "require (internal/module.js:20:19)",
    "bindings (/var/task/node_modules/bindings/bindings.js:76:44)",
    "Object.<anonymous> (/var/task/node_modules/webworker-threads/index.js:1:105)",
    "Module._compile (module.js:570:32)"
  ]
}

and it returns a

{
  "message": "Internal server error"
}

Does AWS lambda not run webworkers? I've tried compiling with nvm 6.10 exactly and rebuilt the zip file, but to no avail. Is there something else I need to include in the zip to make sure the aws lambda env supports the webworker module?

EDIT: (Solved) I wrote up a long tutorial and blog with code to dockerize the Native compilation process.

https://medium.com/@james_mtc/how-to-unsuck-aws-lambdas-native-compilation-for-nodejs-functions-with-docker-and-bash-5301a26a19b1


回答1:


You need to build the native modules on an Amazon AMI with static rather than shared/dynamic libraries. Changing a module from shared to static might be non trivial for some packages.

Native modules are similarly installed and deployed, but you’ll need to build them against the Amazon Linux libraries. You’ll need to either ensure that the libraries and their transitive dependencies are statically compiled or use rpath-style linking; we’ll do it the static way in this post, and demonstrate use of rpath in a subsequent post. (Note that many, but not all, libraries can be statically linked this way.)



来源:https://stackoverflow.com/questions/43690371/can-i-use-webworkers-in-aws-lambda-node-6-10

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!