experimental-download.js
@@ -1,24 +1,1216 @@
-experimental-download.js
+var AWS = require('aws-sdk');%0A%0A%0A%0Avar filePath = '/Users/mikermcneil/Desktop/foo.txt';%0Avar awsAccessKey = process.argv%5B2%5D;%0Avar awsSecret = process.argv%5B3%5D;%0Avar bucketName = 'experiment-jun28-2018';%0A%0Aconsole.log('Using AWS access key:', awsAccessKey);%0Aconsole.log('Using AWS secret:', awsSecret);%0Aconsole.log('Using bucket:', bucketName);%0Aconsole.log('Uploading file:', filePath);%0A%0Avar s3 = new AWS.S3(%7B%0A  apiVersion: '2006-03-01',%0A  region: 'us-west-2',%0A  accessKeyId: awsAccessKey,%0A  secretAccessKey: awsSecret%0A%7D);%0A%0A%0Avar readable = s3.getObject(%7B%0A  Bucket: bucketName,%0A  Key: require('path').basename(filePath),%0A%7D)%0A.createReadStream();%0Areadable.on('error', (err)=%3E%7B%0A  console.error('s3 download stream error:',err);%0A%7D);%0Avar drain = require('fs').createWriteStream('/Users/mikermcneil/Desktop/downloaded-foo.txt');%0Adrain.on('error', (err)=%3E%7B%0A  console.error('local filesystem write error:',err);%0A%7D);%0A%0Areadable.pipe(drain);%0Aconsole.log('Download Success!');%0A%0A%0A// wtf:%0A//%0A// s3.getObject(%7B%0A//   Bucket: bucketName,%0A//   Key: require('path').basename(filePath),%0A// %7D, function (err, data) %7B%0A//   if (err) %7B%0A//     console.log('Error', err);%0A//   %7D if (data) %7B%0A//     console.log('Download Success', data);%0A//   %7D%0A// %7D);%0A

Set up experimental download using aws-sdk directly