Я новичок в веб-сервисах Amazon и пытаюсь создать файл и загрузить его на 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
}
В чем может быть проблема?