简体   繁体   English

无法部署 NodeJS AWS Lambda 函数。 Object.fs.openSync 中的错误

[英]Cannot deploy a NodeJS AWS Lambda Function. Error at Object.fs.openSync

so until a few days ago I used to deploy my Node.JS AWS Lambda functions via a short and simple shell script, which worked perfectly fine.所以直到几天前,我曾经通过一个简短而简单的 shell 脚本来部署我的 Node.JS AWS Lambda 函数,它运行得非常好。

Now I do not know why or what I have done different, but for some reason after every deploy of my lambda function I now get the following error, when invoking the function via Alexa:现在我不知道为什么或我做了什么不同的事情,但出于某种原因,在每次部署我的 lambda 函数后,我现在在通过 Alexa 调用该函数时收到以下错误:

19:47:58
module initialization error Error
module initialization error
Error

19:47:59
START RequestId: 596b2724-68f9-11e8-aaa7-d9ff3044ed9d Version: $LATEST
START RequestId: 596b2724-68f9-11e8-aaa7-d9ff3044ed9d Version: $LATEST

19:47:59
module initialization error: Error at Object.fs.openSync (fs.js:646:18) 
at Object.fs.readFileSync (fs.js:551:33) 
at Object.Module._extensions..js (module.js:662:20) 
at Module.load (module.js:565:32) 
at tryModuleLoad (module.js:505:12) 
at Function.Module._load (module.js:497:3) 
at Module.require (module.js:596:17) 
at require (internal/module.js:11:18)

module initialization error: Error
at Object.fs.openSync (fs.js:646:18)
at Object.fs.readFileSync (fs.js:551:33)
at Object.Module._extensions..js (module.js:662:20)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)
at Module.require (module.js:596:17)
at require (internal/module.js:11:18)

19:47:59
END RequestId: 596b2724-68f9-11e8-aaa7-d9ff3044ed9d

19:47:59
REPORT RequestId: 596b2724-68f9-11e8-aaa7-d9ff3044ed9d  
Duration: 218.74 ms  Billed Duration: 300 ms 
Memory Size: 128 MB Max Memory Used: 20 MB

REPORT RequestId: 596b2724-68f9-11e8-aaa7-d9ff3044ed9d  
Duration: 218.74 ms Billed Duration: 300 ms 
Memory Size: 128 MB Max Memory Used: 20 MB  

Now here comes the part that really makes me clueless how I could solve this, (and it is probably something local on my Mac, I guess).现在到了真正让我不知道如何解决这个问题的部分,(我猜这可能是我 Mac 上的本地问题)。 If I download / export a previously working deployment package from my Lambda function and directly reupload the Zip file, it works .如果我从我的 Lambda 函数下载/导出以前工作的部署包并直接重新上传 Zip 文件,它就可以工作

If I unzip the file and rezip it again , I get the error如果我解压缩文件并再次重新压缩,我会收到错误消息

without me changing anything about the code.无需我更改代码。 That is what makes me wonder if there is something wrong with the zipping on my mac or maybe the file system?这就是让我想知道我的 mac 或文件系统上的压缩是否有问题的原因?

I am using Mac OSX High Sierra, Node 6.10 / 8.10 via nvm.我正在通过 nvm 使用 Mac OSX High Sierra、Node 6.10 / 8.10。 The code on lambda runs with 6.10 and 8.10 lambda 上的代码在 6.10 和 8.10 上运行

Any suggestions appreciated :)任何建议表示赞赏:)

Edit: The last working commit was done on a windows PC... I am slightly worried whether the file system change somehow breaks the zipping / upload.编辑:最后一次工作提交是在 Windows PC 上完成的...我有点担心文件系统更改是否会以某种方式破坏压缩/上传。 I will try and have a deeper look into that.我会尝试更深入地了解这一点。

We were uploading a .zip archive of the code to AWS Lambda.我们正在将代码的 .zip 存档上传到 AWS Lambda。

The problem for us was that the files inside the .zip file didn't have world-readable permissions.我们的问题是 .zip 文件中的文件没有世界可读的权限。

Okay, only thing that was able to solve this, was going back to the last commit that I did from OSX and ignoring the last 3 commits that I did on windows.好的,唯一能够解决这个问题的是回到我从 OSX 所做的最后一次提交并忽略我在 Windows 上所做的最后 3 次提交。

It looks like there were some path or encoding changes that were introduced by committing on windows which resolved in this error.看起来有一些路径或编码更改是通过在解决此错误的 Windows 上提交而引入的。 Unfortunately I cannot see those in the commit diffs.不幸的是,我在提交差异中看不到那些。

So looking for differences between operating systems might be important here.因此,在这里寻找操作系统之间的差异可能很重要。

I was facing the same issue.我面临着同样的问题。 This worked for me on Windows-这在 Windows 上对我有用-

  1. export the lambda function (which downloads a .zip file)导出 lambda 函数(下载 .zip 文件)
  2. extract files提取文件
  3. Zip those files again再次压缩这些文件
  4. Upload this new zip to the lambda将此新 zip 上传到 lambda

I have run into issues with Lambda and code from Windows machines in the past.我过去遇到过 Lambda 和 Windows 机器代码的问题。 The solution (for me) was to chmod -R 644 lambdaDirectory from outside the directory, fixing whatever Windows did to the permissions.解决方案(对我而言)是从目录外部chmod -R 644 lambdaDirectory ,修复 Windows 对权限所做的任何事情。 I have no clue what would cause the download/reupload to work, maybe AWS is doing something to the manifest?我不知道什么会导致下载/重新上传工作,也许 AWS 正在对清单做些什么?

I have also had issues with zip files coming from other machines that use third party compression tools, as they compress the entire directory into an archive named the same instead of just the contents.我也遇到了来自使用第三方压缩工具的其他机器的 zip 文件的问题,因为它们将整个目录压缩到一个名称相同的存档中,而不仅仅是内容。 IE you don't want lambdaDirectory/ to be included in your lambdaDirectory.zip . IE 您不希望lambdaDirectory/包含在您的lambdaDirectory.zip To solve this, run zip -r lambdaDirectory.zip ./* from inside the directory.要解决此问题, zip -r lambdaDirectory.zip ./*从目录内部运行zip -r lambdaDirectory.zip ./*

暂无
暂无

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

相关问题 AWS Lambda:模块初始化错误:Object.fs.openSync错误(本机)错误(fs.js:641:18) - AWS Lambda: module initialization error: Error at Error (native) at Object.fs.openSync (fs.js:641:18) 模块初始化错误:Object.fs.readFileSync(fs.js:551:33)的Object.fs.openSync(fs.js:646:18)错误 - module initialization error: Error at Object.fs.openSync (fs.js:646:18) at Object.fs.readFileSync (fs.js:551:33) 错误:否:没有此类文件或目录,请在Object.fs.openSync(fs.js:646:18)中打开“ /etc/letsencrypt/live/awiclass.monoame.com/privkey.pem” - Error: ENOENT: no such file or directory, open '/etc/letsencrypt/live/awiclass.monoame.com/privkey.pem' at Object.fs.openSync (fs.js:646:18) 无法将 Nodejs 和 Typescript 部署到 AWS cdk + lambda - Cannot deploy Nodejs and Typescript to AWS cdk + lambda AWS Lambda nodejs 函数中的事件对象为空 - Event Object is empty in AWS Lambda nodejs function 带有标志“a”的 nodejs fs.openSync() 无法运行 java 程序 - nodejs fs.openSync() with the flags 'a' fails to run java program 错误:在 NodeJS AWS 中找不到模块“aws-sdk” Lambda Function - Error: Cannot find module 'aws-sdk' in NodeJS AWS Lambda Function 内部服务器错误 aws lambda 函数 nodejs - Internal server error aws lambda function nodejs 如何处理 nodejs 中的 AWS lambda 函数错误 - How to handle the AWS lambda function error in nodejs 使用 nodejs 4.3 的 AWS lambda 函数中的错误 _LAMBDA_LOG_FD - Error _LAMBDA_LOG_FD in AWS lambda function with nodejs 4.3
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM