简体   繁体   English

需要 SOAP - Node JS 包失败,AWS Lambda 中出现导入错误

[英]Requiring SOAP - Node JS package fails with an import error in AWS Lambda

My Lambda function is running on Node JS 10.x.我的 Lambda 函数在 Node JS 10.x 上运行。 Tried requiring the soap npm module but it fails with the following error.尝试要求使用 soap npm 模块,但失败并出现以下错误。

{
  "errorType": "Runtime.ImportModuleError",
  "errorMessage": "Error: Cannot find module 'soap'",
  "trace": [
    "Runtime.ImportModuleError: Error: Cannot find module 'soap'",
    "    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)"
  ]
}

Tried looking in several threads but no luck.尝试查看多个线程,但没有运气。 The file name is index.js and the handler name is index.handler if that information helps.如果该信息有帮助,文件名为 index.js,处理程序名为 index.handler。

The issue was due to the folder structure and dependencies set up.问题是由于文件夹结构和依赖项设置造成的。 Since 'soap' module is an additional package which is out of the libraries in the AWS SDK for JavaScript.由于“soap”模块是一个附加包,它不在适用于 JavaScript 的 AWS 开发工具包中的库中。 I install it locally with npm and included it in the deployment package.我使用 npm 在本地安装它并将其包含在部署包中。 Then updated the Lambda function using AWS SDK.然后使用 AWS 开发工具包更新了 Lambda 函数。

Refer this - https://docs.aws.amazon.com/lambda/latest/dg/nodejs-package.html#nodejs-package-dependencies参考这个 - https://docs.aws.amazon.com/lambda/latest/dg/nodejs-package.html#nodejs-package-dependencies

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM