deploy.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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:', Object.assign({
  23. "Location2": data.Location.replace("https://s3.amazonaws.com/justlistenmusic4560.com", "https://d3crpuooyqht8f.cloudfront.net")
  24. }, data));
  25. // const cloudfront = new AWS.CloudFront();
  26. // const params = {
  27. // DistributionId: 'E1OARMP9V91HD1',
  28. // InvalidationBatch: {
  29. // CallerReference: Date.now().toString(),
  30. // Paths: {
  31. // Quantity: 1,
  32. // Items: ['/*'],
  33. // },
  34. // },
  35. // };
  36. // cloudfront.createInvalidation(params)
  37. // .promise()
  38. // .then(data => {
  39. // console.log('CloudFront cache has been successfully refreshed.', data);
  40. // })
  41. // .catch(err => {
  42. // console.error('Error refreshing CloudFront cache:', err);
  43. // });
  44. })
  45. .catch(err => {
  46. console.error('Error uploading file:', err);
  47. });