const AWS = require('aws-sdk'); const fs = require("fs"); // 配置 AWS 访问凭证和 S3 区域 AWS.config.update({ accessKeyId: 'AKIA2TBT2JUNG6X3W737', secretAccessKey: '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', region: 'us-east-1', }); const s3 = new AWS.S3(); const bucketName = 'justlistenmusic4560.com'; const filePath = 'bundle.js'; const destinationPath = 'bundle2.js'; const fileContent = fs.readFileSync(filePath); const params = { Bucket: bucketName, Key: destinationPath, Body: fileContent, }; s3.upload(params) .promise() .then(data => { console.log('File uploaded successfully. Location:', data); const cloudfront = new AWS.CloudFront(); const params = { DistributionId: 'E1OARMP9V91HD1', InvalidationBatch: { CallerReference: Date.now().toString(), Paths: { Quantity: 1, Items: ['/*'], }, }, }; cloudfront.createInvalidation(params) .promise() .then(data => { console.log('CloudFront cache has been successfully refreshed.', data); }) .catch(err => { console.error('Error refreshing CloudFront cache:', err); }); }) .catch(err => { console.error('Error uploading file:', err); });