How to get node.js to wait until pdfkitDocument.on(‘end’) finishes completely

We have an application that uploads a PDF to S3 and returns an object with metadata about the S3 file. This works fine if we want to email the link to the document to someone. The problem comes if we want to download the file from S3 immediately thereafter, for instance, to attach the file to a message vs. a link to the file. What seems to be happening is that the metadata regarding the S3 file is returned to the calling function BEFORE the pdf.on(‘end’) code is executed which triggers the upload to S3. The relevent code snippet is here:

  pdf.on('end', async () => {
    const result = await Buffer.concat(chunks);
    await s3.putObject(
      {
        Bucket: 'corp-attch',
        Key: filePath,
        Body: result,
        ContentType: 'application/pdf',
      }).promise();
    this.logger.log(`S3 Upload Success:  ${filePath}`);
  });

  await pdf.end();
  this.logger.log(`Finished with pdf:  ${filePath}`);
  returnAttach.attachDest = filePath;
  returnAttach.attachName = filePath.split('/').pop();
  const getObjectParams = {
    Bucket: this.configService.awsCorpBucketName,
    Key: filePath, Expires: 900,
  };

  returnAttach.attachUrl = s3.getSignedUrl('getObject', getObjectParams);
  return new Promise(resolve => resolve(returnAttach));

Is there a good way to force the whole thing to wait until the s3.putObject is complete?

In this case, no matter what we try in this code, the ‘S3 Upload Success’ message is logged AFTER the ‘Finished with pdf:’ code and any attempt to access the file via the url returns a 404 when we try to do so from the calling function.