简体   繁体   English

无服务器部署到 AWS Lambda 缺少模块?

[英]Serverless deployment to AWS Lambda missing modules?

First time dealing with serverless here.第一次在这里处理无服务器。 Have successfully deployed using serverless deploy after following the guide to migrating an existing express app over to serverless.在遵循将现有快速应用程序迁移到无服务器的指南后,已使用无服务器部署成功部署。 But aws lambda keeps throwing an error:但是 aws lambda 不断抛出错误:

“errorType”: “Runtime.ImportModuleError”, “errorMessage”: “Error: Cannot find module 'serverless-http'\nRequire stack:\n- /var/task/app.js\n- /var/runtime/UserFunction.js\n- /var/runtime/index.js”, “errorType”:“Runtime.ImportModuleError”,“errorMessage”:“错误:找不到模块'serverless-http'\n需要堆栈:\n- /var/task/app.js\n- /var/runtime/UserFunction。 js\n- /var/runtime/index.js”,

So I'm confused.所以我很困惑。 What am I doing wrong?我究竟做错了什么? The guide to converting an existing express app didn't say we'd need to create an AWS Lambda Layer, but since it seems like Lambda can't find the serverless-http module, does it mean that creating a layer is the fix?转换现有 express 应用程序的指南没有说我们需要创建一个 AWS Lambda 层,但是由于 Lambda 似乎找不到 serverless-http 模块,这是否意味着创建一个层是解决方法?

Edit: my.zip file seems to only be an express.js file .编辑: my.zip 文件似乎只是一个 express.js 文件 I'm not sure if that's unusual but reading online reveals that most people seem to have a node_modules folder zipped up as well?我不确定这是否不寻常,但在线阅读显示大多数人似乎也有一个 node_modules 文件夹压缩了? I presume the lack of a node_module folder in the.zip file is causing this runtime.ImportModuleError fail?我认为 .zip 文件中缺少 node_module 文件夹导致此 runtime.ImportModuleError 失败? How do I get serverless to add a node_modules folder if that's the case?如果是这种情况,如何让无服务器添加 node_modules 文件夹?

node_modules folder is generally packaged with your code -- provided it exists in your directory (does it?). node_modules 文件夹通常与您的代码一起打包 - 只要它存在于您的目录中(是吗?)。

If node_modules isn't installed on your local machine, then you can create it by using the npm install command.如果本地计算机上未安装 node_modules,则可以使用npm install命令创建它。 This command will install all the dependencies listed in the package-lock.json file (or package.json) -- sorry I'm not a node guy:(.此命令将安装 package-lock.json 文件(或 package.json)中列出的所有依赖项——对不起,我不是节点人:(。

But it definitely sounds like you're not uploading your node_modules folder because it's not on your local machine.但听起来你肯定没有上传你的 node_modules 文件夹,因为它不在你的本地机器上。 You have to initialize the directory first.您必须先初始化目录。

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

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