function uploadUIAssets()

in lambda-functions/deploy-function/index.js [126:170]


function uploadUIAssets(event) {
 console.log("In uploadUIAssets :%s", SourceUIFilePath);

 return S3.getObject({ Bucket: SourceFileBucket, Key: SourceUIFilePath }).promise()
  .then(data => {
   let zip = new AdmZip(data.Body);
   let zipEntries = zip.getEntries();

   zipEntries.forEach(function(zipEntry) {

    if (!zipEntry.isDirectory) {
     let mimeType = mime.getType(zipEntry.name.substring(zipEntry.name.lastIndexOf(".")));
     let fileContents = zipEntry.getData();
     // console.log('File Name: ', zipEntry.entryName);

     if ((zipEntry.entryName.includes("static/js/main.") && zipEntry.entryName.endsWith(".js")) || zipEntry.entryName.includes("test-harness/js/aws-exports.js")) {
      // console.log("Kinesis Stream name :%s",event.ResourceProperties.KinesisStreamName);

      fileContents = fileContents.toString().replace('QOS_DELIVERY_STREAM', event.ResourceProperties.KinesisStreamName);
      fileContents = fileContents.replace('QOS_IDENTITY_POOL_ID', event.ResourceProperties.IdentityPoolId);
      fileContents = fileContents.replace('QOS_DEPLOY_REGION', event.ResourceProperties.Region);
      fileContents = fileContents.replace('QOS_DEPLOY_REGION', event.ResourceProperties.Region);
      fileContents = fileContents.replace('QOS_GRAPHQL_ENDPOINT', event.ResourceProperties.GraphQLEndpoint);
      fileContents = fileContents.replace('QOS_API_KEY', event.ResourceProperties.GraphQLApiKey);
      fileContents = fileContents.replace('CLOUDFRONT_DOMAIN', event.ResourceProperties.CloudFrontDomain);
      // console.log(fileContents);
     }

     S3.putObject({
       // ACL: 'public-read',
       Body: fileContents,
       Bucket: SourceBucket,
       Key: UIPrefix + "/" + zipEntry.entryName,
       // Key: zipEntry.entryName,
       ContentType: mimeType
      }).promise()
      .catch(() => { console.log("Exception while uploading the file into S3 bucket") });
    }
   });
   console.log("Done uploading UI");
   // return new Promise((resolve, reject) => { // (*)
   //  resolve('Done uploading UI');
   // });
  });
}