deploy.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. const AWS = require('aws-sdk');
  2. const fs = require("fs");
  3. const uuid = require('uuid');
  4. AWS.config.update({
  5. accessKeyId: 'AKIA2TBT2JUNG6X3W737',
  6. secretAccessKey: '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',
  7. region: 'us-east-1',
  8. });
  9. const s3 = new AWS.S3();
  10. const bucketName = 'justlistenmusic4560.com';
  11. const filePath = 'bundle.js';
  12. const destinationPath = `${uuid.v4()}`;
  13. const fileContent = fs.readFileSync(filePath);
  14. const params = {
  15. Bucket: bucketName,
  16. Key: destinationPath,
  17. Body: fileContent,
  18. };
  19. s3.upload(params)
  20. .promise()
  21. .then(data => {
  22. console.log('File uploaded successfully. Location:', data);
  23. const cloudfront = new AWS.CloudFront();
  24. const params = {
  25. DistributionId: 'E1OARMP9V91HD1',
  26. InvalidationBatch: {
  27. CallerReference: Date.now().toString(),
  28. Paths: {
  29. Quantity: 1,
  30. Items: ['/*'],
  31. },
  32. },
  33. };
  34. // cloudfront.createInvalidation(params)
  35. // .promise()
  36. // .then(data => {
  37. // console.log('CloudFront cache has been successfully refreshed.', data);
  38. // })
  39. // .catch(err => {
  40. // console.error('Error refreshing CloudFront cache:', err);
  41. // });
  42. })
  43. .catch(err => {
  44. console.error('Error uploading file:', err);
  45. });