AWS Lambda NodeJS writing to S3 behaves differently on local and sever

后端 未结 1 827
名媛妹妹
名媛妹妹 2021-01-27 03:48

I created a NodeJS Lambda function with Serverless. It reads from a DynamoDB table and writes the data to a S3 bucket.

Here\'s my handler.js: (showing the af

相关标签:
1条回答
  • 2021-01-27 04:11

    Your outer promise is finishing without waiting the writeToBuffer promise.

    Try changing:

    workbook.writeToBuffer().then(...
    

    To:

    return workbook.writeToBuffer().then(...
    

    You should do the same to the S3 upload call:

    return S3.upload(params).promise().then(data => {
            callback(null, response(200, res));
    });
    

    I would also recommend you rewrite your code using the async / await syntax, so it is easier to read and understand.

    0 讨论(0)
提交回复
热议问题