Friday 19 May 2017

How to write directly to an S3 file with node?

I come from PHP, and the AWS S3 PHP SDK has the ability to register a stream wrapper that lets you take advantage of commands like fopen, fwrite, etc.

So in PHP, I can do something like:

$s3 = new S3Client([...]);
$s3->registerStreamWrapper();

$fh = fopen('s3://bucket/filename.csv', 'w');

while($row = fgetcsv('localcsv.csv')) {
   fwrite($fh, $row[0].",".$row[1]."\n");
}
fclose($fh);

The above function lets me open a write stream to S3, and write to it line by line.

Is there a way that I can accomplish the same thing in Node? I would prefer not to write locally and upload the file as the file could be really big.

Thanks in advance!



via john

No comments:

Post a Comment