DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones AWS Cloud
by AWS Developer Relations
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones
AWS Cloud
by AWS Developer Relations
Building Scalable Real-Time Apps with AstraDB and Vaadin
Register Now

Trending

  • Redefining DevOps: The Transformative Power of Containerization
  • Authorization: Get It Done Right, Get It Done Early
  • Auto-Scaling Kinesis Data Streams Applications on Kubernetes
  • What ChatGPT Needs Is Context

Trending

  • Redefining DevOps: The Transformative Power of Containerization
  • Authorization: Get It Done Right, Get It Done Early
  • Auto-Scaling Kinesis Data Streams Applications on Kubernetes
  • What ChatGPT Needs Is Context
  1. DZone
  2. Software Design and Architecture
  3. Cloud Architecture
  4. Upload an Entire s3 Bucket/Local Directory to Another s3 Bucket From Node.js

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

Checkout this convenient method for working with s3 Buckets.

Vijaykishan Shyamsundar user avatar by
Vijaykishan Shyamsundar
·
Oct. 15, 19 · Code Snippet
Like (3)
Save
Tweet
Share
9.62K Views

Join the DZone community and get the full member experience.

Join For Free

Cat sitting in red bucket

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

  • Five Things You Probably Didn't Know About Amazon S3.
  • Working with Amazon S3 – Part I.
AWS Upload Node.js Directory

Opinions expressed by DZone contributors are their own.

Trending

  • Redefining DevOps: The Transformative Power of Containerization
  • Authorization: Get It Done Right, Get It Done Early
  • Auto-Scaling Kinesis Data Streams Applications on Kubernetes
  • What ChatGPT Needs Is Context

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com

Let's be friends: