Upload an Entire s3 Bucket/Local Directory to Another s3 Bucket From Node.js – DZone Web Dev | xxxUpload an Entire s3 Bucket/Local Directory to Another s3 Bucket From Node.js – DZone Web Dev – xxx
菜单

Upload an Entire s3 Bucket/Local Directory to Another s3 Bucket From Node.js – DZone Web Dev

九月 6, 2019 - MorningStar

Over a million developers have joined DZone.
Upload an Entire s3 Bucket/Local Directory to Another s3 Bucket From Node.js - DZone Web Dev

{{announcement.body}}

{{announcement.title}}

Let’s be friends:

Upload an Entire s3 Bucket/Local Directory to Another s3 Bucket From Node.js

DZone ‘s Guide to

Upload an Entire s3 Bucket/Local Directory to Another s3 Bucket From Node.js

Checkout this convenient method for working with s3 Buckets.

Free Resource

Join the DZone community and get the full member experience.

Join For Free

Upload an Entire s3 Bucket/Local Directory to Another s3 Bucket From Node.js - DZone Web Dev

If he fits (in an s3 bucket, he sits (in an s3 bucket)

I have come across several requests wherein a team needs to upload an entire folder/source s3 bucket (that may contain subfolders) to another s3 bucket (destination).

We are all aware of the nice little AWS CLI command to complete the above task:

Bucket to bucket sync:

 s3 sync s3://srcBucket s3://destBucket 

Local folder to s3Bucket sync:

 s3 sync . s3://destBucket 

The problem is that when we would like to achieve the same result from a script rather than the command line, we find that none of the SDKs provided by AWS helps us achieve this.

You may also like: AWS S3 Bucket Naming Challenge [Comic].

Some suggest using AWS’s data pipeline though I believe this is unnecessary when there is no transformation requirement.

So How do we go about this?

There is a node package — aws-cli-js.  You can read more about it here.

Use the following code:

var awsCli = require('aws-cli-js');  var Options = awsCli.Options;  var Aws = awsCli.Aws;  var options = new Options(  /* accessKey */ CRED.accesskey,  /* secretKey */ CRED.secretkey,  );  var aws = new Aws(options);  aws.command(' s3 sync s3://srcBkt s3://destBkt, function (err, data) {  console.log('data = ', JSON.stringify(data.raw));  });

Note: Make sure to pass on the right credentials. We can use the callback method and process the results too. I hope this helps. Let me know your thoughts and anything that can be improved!

Further Reading

Topics:
s3 file upload ,s3 bucket ,web dev ,data transfer ,aws-cli ,tutorial

Opinions expressed by DZone contributors are their own.

Web Dev Partner Resources

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.linkDescription }}

{{ parent.urlSource.name }}

· {{ parent.articleDate | date:'MMM. dd, yyyy' }} {{ parent.linkDate | date:'MMM. dd, yyyy' }}


Notice: Undefined variable: canUpdate in /var/www/html/wordpress/wp-content/plugins/wp-autopost-pro/wp-autopost-function.php on line 51