简体   繁体   English

无法在S3上创建分段上传

[英]Failed to create a multipart upload on S3

I am very new to amazon web services and I am trying to create a file and upload it to S3 using the below code : 我对亚马逊网络服务非常陌生,我正在尝试使用以下代码创建文件并将其上传到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);
    });
}

It works fine when I run it on local but when I try to execute the same via AWS lambda, it throws this error : 当我在本地运行它时,它工作正常,但是当我尝试通过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
}

What could be the problem? 可能是什么问题呢?

It may work on your local test because it will be using your AWS Credentials. 它可能会在您的本地测试中使用,因为它将使用您的AWS凭证。 You need to ensure that the role assumed by your Lambda has write permissions to target S3 location. 您需要确保Lambda承担的角色具有对目标S3位置的写入权限。

For example: 例如:

{
  "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.

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