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

}

feita há 3 anos922 visualizações
1 Resposta
0

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

respondido há 3 anos

Você não está conectado. Fazer login para postar uma resposta.

Uma boa resposta responde claramente à pergunta, dá feedback construtivo e incentiva o crescimento profissional de quem perguntou.

Diretrizes para responder a perguntas