我可以在 AWS Lambda(节点 6.10)中使用 WebWorkers 吗?

Can I use WebWorkers in AWS Lambda (node 6.10)

我有一个我想要在 AWS lambda 中使用的非常简单的节点模块,它导入 'Natural' 用于一些文本处理。

这一行抛出错误: var n = require('natural');

错误是这样的:

{
  "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)"
  ]
}

它returns一个

{
  "message": "Internal server error"
}

AWS lambda 不是 运行 网络工作者吗?我试过完全使用 nvm 6.10 进行编译并重建 zip 文件,但无济于事。我还需要在 zip 中包含其他内容以确保 aws lambda env 支持 webworker 模块吗?

编辑:(已解决) 我写了一篇很长的教程和博客,其中包含将本机编译过程 docker 化的代码。

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

You need to build the native modules on an Amazon AMI 使用静态而不是 shared/dynamic 库。将模块从共享更改为静态对于某些包来说可能并不简单。

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.)