gpt4 book ai didi

node.js - Lambda 函数错误 : EROFS: read-only file system, 打开 './tmp/test.zip' 进程在完成请求之前退出

转载 作者:IT老高 更新时间:2023-10-28 23:02:33 25 4
gpt4 key购买 nike

I have download a zip file from s3 bucket then extracting the zip file and finally upload one file to s3 bucket in Lambda function using Node JS.But am getting the error

==> Error: EROFS: read-only file system, open './tmp/test.zip' "Process exited before completing> request"

exports.handler = function (callback) {

downloadZipFile(params, downloadPath, function (err) {
if (err) {
callback(err);
} else {
processZipFile(downloadPath, function (err) {
if (err) {
callback(err);
} else {
callback(null);
}
});

}
});

};

function downloadZipFile(params, downloadPath, callback) {

const file = fs.createWriteStream(downloadPath);

s3.getObject(params)
.on('httpData', function (chunk) {

file.write(chunk);
})
.on('success', function () {

callback(null);
})
.on('error', function (err) {

callback(err);
})
.on('complete', function () {

file.end();
})
.send();
}

function processZipFile(filePath) {

const stats = fs.statSync(filePath)
const fileSizeInBytes = stats.size

if (fileSizeInBytes > 0) {

var srcPath = filePath;
var destPath = "./tmp";
targz.decompress({
src: srcPath,
dest: destPath

}, function (err) {
if (err) {
console.log(err);
} else {
console.log("Done!");

UploadFile();
}

});
}
}

function UploadFile() {

var body = fs.createReadStream('./tmp/SampleFile.txt')

var srcfileKey = "SampleFile.txt";
// Upload the stream
var s3obj = new AWS.S3({ params: { Bucket: bucketName, Key: srcfileKey } });
s3obj.upload({ Body: body }, function (err, data) {
if (err) {
console.log("An error occurred", err);
}

console.log("Uploaded the file at", data.Location);
})
}

最佳答案

您需要将文件路径更改为/tmp 而不是./tmp。 Lambda 只允许你写入 /tmp 目录。

关于node.js - Lambda 函数错误 : EROFS: read-only file system, 打开 './tmp/test.zip' 进程在完成请求之前退出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43389724/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com