Last active
November 19, 2017 12:46
-
-
Save tatethurston/4b32134a8bc74a9311d4376eb3d583b7 to your computer and use it in GitHub Desktop.
node script for AWS S3 uploads
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* NOTE: You'll need to follow the steps outlined in aws-config.js.example | |
* before running this deploy script for the first time | |
*/ | |
// https://github.com/andrewrk/node-s3-client | |
const s3 = require('s3'); | |
const DIRECTORY = 'dist'; | |
const client = s3.createClient({ | |
s3Options: { | |
sslEnabled: true, | |
region: process.env.AWS_REGION, | |
accessKeyId: process.env.AWS_ACCESS_KEY_ID, | |
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY | |
} | |
}); | |
const params = { | |
localDir: DIRECTORY, | |
// remove s3 objects that have no corresponding local file. | |
deleteRemoved: true, | |
s3Params: { | |
Bucket: process.env.AWS_BUCKET_NAME, | |
ACL: 'public-read' | |
} | |
}; | |
const uploader = client.uploadDir(params); | |
uploader.on('error', function(err) { | |
console.error('Upload failed:', err.stack); | |
}); | |
uploader.on('progress', function() { | |
console.log('Progress', uploader.progressAmount, uploader.progressTotal); | |
}); | |
uploader.on('end', function() { | |
console.log('Upload complete.'); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment