I am creating an Excel file with a Lambda function that is later sent by E-Mail. The Excel is filled with data before and is then stored like this(With the excel4node nom package):
console.log("Before print");
    var test2 = await workbook.write(path, function(err, stats) {
        console.log("Excel written");
        if (err) {
          console.error(err);
        } else {
          console.log(stats); // Prints out an instance of a node.js fs.Stats object
        }
      });
    console.log("After print");
The code works sometimes. The problem is the following code is not waiting until the excel is written and the E-Mail cannot find the attachment.
How can I make my Lambda function wait until the excel is written to disk?
 
     
     
    