Skip to content

Instantly share code, notes, and snippets.

@guikaercher
Last active December 4, 2018 15:35
Show Gist options
  • Save guikaercher/d5ece0c054c760a026e73cf0ed26a383 to your computer and use it in GitHub Desktop.
Save guikaercher/d5ece0c054c760a026e73cf0ed26a383 to your computer and use it in GitHub Desktop.
upload file to S3 AWS
// Please remember there are constants that are not defined in this scripts
// You have to set logs dir, bucket credentials and so forth
const uploadToS3 = (fileName) => {
let s3bucket = new AWS.S3({
accessKeyId: IAM_USER_KEY,
secretAccessKey: IAM_USER_SECRET,
Bucket: BUCKET_NAME,
});
const contents = fs.readFileSync(LOGS_DIR + fileName, 'utf8');
const fileToUpload = {
name: REMOTE_PATH + fileName,
data: contents
}
s3bucket.createBucket(function () {
const params = {
Bucket: BUCKET_NAME,
Key: fileToUpload.name,
Body: fileToUpload.data,
};
const options = {partSize: PART_SIZE, queueSize: 1};
s3bucket.upload(params, options, function (err, data) {
if (err) {
console.log('error in upload callback');
console.log(err);
}
console.log('synced with the cloud');
console.log(data);
// renameFile(LOGS_DIR + fileName, LOGS_DIR + fileName + '.synced')
});
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment