Last active
December 4, 2018 15:35
-
-
Save guikaercher/d5ece0c054c760a026e73cf0ed26a383 to your computer and use it in GitHub Desktop.
upload file to S3 AWS
This file contains 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
// 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