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 ===');  

}

asked 3 years ago905 views
1 Answer
0

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

answered 3 years ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions