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

}

gefragt vor 3 Jahren924 Aufrufe
1 Antwort
0

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

beantwortet vor 3 Jahren

Du bist nicht angemeldet. Anmelden um eine Antwort zu veröffentlichen.

Eine gute Antwort beantwortet die Frage klar, gibt konstruktives Feedback und fördert die berufliche Weiterentwicklung des Fragenstellers.

Richtlinien für die Beantwortung von Fragen