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년 전922회 조회
1개 답변
0

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

답변함 3년 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠