Javascript 无法从本地读取zip文件
我想从本地节点JS中读取zip文件(我还将在基于Linux的服务器上托管此后端) 在下面的代码中,exampleLambda.zip文件位于.js代码文件所在的文件夹中Javascript 无法从本地读取zip文件,javascript,node.js,amazon-web-services,file,aws-lambda,Javascript,Node.js,Amazon Web Services,File,Aws Lambda,我想从本地节点JS中读取zip文件(我还将在基于Linux的服务器上托管此后端) 在下面的代码中,exampleLambda.zip文件位于.js代码文件所在的文件夹中 const zipContents = fs.readFileSync('exampleLambda.zip'); var params = { Code: { // here at below I have to pass the zip file readi
const zipContents = fs.readFileSync('exampleLambda.zip');
var params = {
Code: {
// here at below I have to pass the zip file reading it from the S3 public bucket
ZipFile: zipContents,
},
FunctionName: 'testFunction', /* required */
Role: 'arn:aws:iam::149727569662:role/ROLE', /* required */
Description: 'Created with tempalte',
Handler: 'index.handler',
MemorySize: 256,
Publish: true,
Runtime: 'nodejs12.x',
Timeout: 15,
TracingConfig: {
Mode: "Active"
}
};
lambda.createFunction(params, function(err, data) {
if (err) console.log(err, err.stack); // an error occurred
else console.log(data); // successful response
});
读取文件时抛出错误error:enoint:没有这样的文件或目录,打开'exampleLambda.zip
我也尝试过的错误
const-zipContents=fs.readFileSync('./exampleLambda.zip')代码>
该文件与.Js文件位于同一文件夹中
const zipContents = fs.readFileSync('exampleLambda.zip');
var params = {
Code: {
// here at below I have to pass the zip file reading it from the S3 public bucket
ZipFile: zipContents,
},
FunctionName: 'testFunction', /* required */
Role: 'arn:aws:iam::149727569662:role/ROLE', /* required */
Description: 'Created with tempalte',
Handler: 'index.handler',
MemorySize: 256,
Publish: true,
Runtime: 'nodejs12.x',
Timeout: 15,
TracingConfig: {
Mode: "Active"
}
};
lambda.createFunction(params, function(err, data) {
if (err) console.log(err, err.stack); // an error occurred
else console.log(data); // successful response
});
为什么这会引发错误,我使用的是来自nodeJS的fs lib。有什么办法吗?
另外,我需要一个解决方案,它也可以在基于Linux的服务器上工作,因为我要将它上传到那里。1。如果这是常规操作,而不是部署流水线的一部分,那么考虑文件的常规解压缩可能不是一个好主意2。请在命令运行的目录中发布ls的输出,甚至可能在我在节点上使用readFileSync时使用相应的node fs命令。最近,我在当前目录中的文件名前面没有/
directory@ScottAnderson我没有别的选择了,因为我必须通过模板文件以编程方式创建AWS lambda函数。另一个选项是AWS bucket,但它限制了用户,我想让它对所有人都通用。@ScottAnderson我尝试了/
,但没有。但是没有为我工作,很公平,恐怕不能对AWS工作流程发表评论。你能试着输出这里演示的fs.readdir吗:@ScottAnderson只是一个注释-我正在做一个API调用来在AWS上创建一个Lambda。