Upload to S3 from Lambda doesn't create file in bucket, no error

0

I use serverless lambda to upload files to an S3 bucket with nodejs. When calling s3.PutObject nothing happens and none of my debug statements printed after that. The last line printed is '=== test 1 ==='. Please suggest possible solutions or how to track it down. Thanks.

async function uploadFileToS3 (fileAttributes) {
// call S3 to retrieve upload file to specified bucket
const uploadParams = { Bucket: bucket, Key: '', Body: '' };

const fileStream = fs.createReadStream(fileAttributes.filepath);  
fileStream.on('error', (err) => {  
    logger.error('File Error', err);  
});  
uploadParams.Body = fileStream;  
uploadParams.Key = fileAttributes.filename;  

logger.debug('Uploading to S3', uploadParams);  
// call S3 to retrieve upload file to specified bucket  
console.log('=== test 1 ===');  
try {  
    const stored = await s3.putObject(uploadParams).promise();  
    logger.info('=== Upload Success ===', stored);  
} catch (err) {  
    logger.error('=== S3 upload error ===', err);  
}  
console.log('=== test 2 ===');  

}

已提問 3 年前檢視次數 924 次
1 個回答
0

The issue was that the uploadFileToS3 was called in a forEach loop which is not promise aware.

已回答 3 年前

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南