in ec2/gov-cloud-import.js [539:612]
async function syncS3(){
try {
//changeInstanceTag(instanceId);
let activityArn = await createS3ActivityArn();
let taskData = await findS3Task(activityArn);
let mounted = await mountBucket(taskData.sourceBucket);
if (mounted == "success"){
changeInstanceTag(instanceId);
taskData.accessKeyId = await getParameter('gov-cloud-import-accessKey');
taskData.secretAccessKey = await getParameter('gov-cloud-import-secretKey');
let govRegion = findGovRegion()
//Create S3 client object
let client = s3.createClient({
maxAsyncS3: 20, // this is the default
s3RetryCount: 3, // this is the default
s3RetryDelay: 1000, // this is the default
multipartUploadThreshold: 20971520, // this is the default (20 MB)
multipartUploadSize: 15728640, // this is the default (15 MB)
s3Options: {
accessKeyId: taskData.accessKeyId,
secretAccessKey: taskData.secretAccessKey,
region: govRegion
},
});
let params = {
localDir: "/home/ec2-user/s3fs/" + taskData.sourceBucket,
deleteRemoved: true,
s3Params: {
Bucket: taskData.destBucket,
},
};
//Start Sync
let uploader = client.uploadDir(params);
//Create Heartbeat
heartbeat.push(taskData.taskToken);
//EventEmitters
uploader.on('error', function(err) {
writeToLog("unable to sync: "+err, 'log');
removeHeartbeat(heartbeat, taskData.taskToken);
umountBucket(taskData.sourceBucket);
sendTaskFailure(taskData.taskToken);
});
uploader.on('progress', function() {
let msg = "S3 Sync Progress: "+formatBytes(uploader.progressAmount)+" of "+formatBytes(uploader.progressTotal)
writeToLog(msg, "syncProgressLog");
});
uploader.on('fileUploadStart', function(localFilePath, s3Key) {
let filePath = localFilePath.replace("/home/ec2-user/s3fs/", "");
let msg = "Started copying From: s3://"+filePath+" To: s3://"+taskData.destBucket+'/'+s3Key
writeToLog(msg, "s3SyncLog");
});
uploader.on('fileUploadEnd', function(localFilePath, s3Key) {
let filePath = localFilePath.replace("/home/ec2-user/s3fs/", "");
let msg = "Finished copying From: s3://"+filePath+" To: s3://"+taskData.destBucket+'/'+s3Key
writeToLog(msg, "s3SyncLog");
});
uploader.on('end', function() {
let msg = "Destination: "+ taskData.destBucket +" has been synchronized with Source: "+ taskData.sourceBucket
writeToLog(msg, 'log');
sendTaskSuccess(taskData.taskToken);
removeHeartbeat(heartbeat, taskData.taskToken);
umountBucket(taskData.sourceBucket);
});
} else {
writeToLog("S3FS Commercial S3 Bucket failed to mount", 'log')
}
} catch (err){
if (err){
writeToLog(err, 'log');
} else {
writeToLog('No New S3 Sync Tasks', 'log');
}
}
}