![](/img/trans.png)
[英]AWS file upload with loopback: Failed to create a multipart upload on S3
[英]Failed to create a multipart upload on S3
我對亞馬遜網絡服務非常陌生,我正在嘗試使用以下代碼創建文件並將其上傳到S3:
let uploadCsvToS3 = (fileData, csvName) => {
let data = fileData;
let readObj = new Readable();
let timeOfErrorLog = timeUtility.convertDateToUnixTS(new Date());
let errorLogFileName = `errorlog/errorlog_${timeOfErrorLog}_${csvName}`;
readObj.push(data); // Push the CSV
readObj.push(null); // Signal that we're done writing the CSV
var upload = s3Stream.upload({
"Bucket": "bucketname",
"Key": errorLogFileName
});
readObj.pipe(upload);
upload.on('error', function (error) {
console.log('error is:',error);
console.log(`There was an error uploading error file: ${errorLogFileName} on S3`);
});
upload.on('uploaded', function (details) {
console.log(`Successfully Uploaded error log file on S3 by name: ${errorLogFileName}`);
console.log(details);
markErrorLogAsDumped(csvName);
});
}
當我在本地運行它時,它工作正常,但是當我嘗試通過AWS lambda執行該操作時,它會拋出此錯誤:
Failed to create a multipart upload on S3:
{
"message": "Access Denied",
"code": "AccessDenied",
"region": null,
"time": "2019-01-14T10:21:01.983Z",
"requestId": "24FC75B2103C1FC4",
"extendedRequestId": "iTDnNrMWSfixL9j6S6yDz68AgTIZthUlTzjZ/Rwrqu7CUJj5f4lrq2Ds7hFapbvzko3DYyRGA/E=",
"statusCode": 403,
"retryable": false,
"retryDelay": 64.85863274563219
}
可能是什么問題呢?
它可能會在您的本地測試中使用,因為它將使用您的AWS憑證。 您需要確保Lambda承擔的角色具有對目標S3位置的寫入權限。
例如:
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "Stmt1547468052811",
"Action": "s3:*",
"Effect": "Allow",
"Resource": "arn:aws:s3:::<bucket_name>/"
}
]
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.