AWS S3 copy files and folders between two buckets

+2 votes
Can I copy by S3 files and foldes form one bucket to other?
Apr 10, 2018 in Cloud Computing by brat_1
• 7,200 points
4,837 views

3 answers to this question.

+1 vote

I have come across similar question. Yes there is definitely a way to this: We CLI tools in the market that let you do what you have asked for. For that you need to install CLI Tools, I would say refer this for the same:

http://aws.amazon.com/cli/

This command should be good enough to meet your requirements:
$ aws s3 sync s3://mybucket-src s3://mybucket-target --exclude *.tmp
..

This will copy from one target bucket to another bucket.

answered Apr 10, 2018 by hemant
• 5,790 points
+1 vote

A simplified example using the aws-sdk gem:

AWS.config(:access_key_id => '...', :secret_access_key => '...')
s3 = AWS::S3.new
s3.buckets['bucket-name'].objects['source-key'].copy_to('target-key')

If you want to perform the copy between different buckets, then specify the target bucket name:

s3.buckets['bucket-name'].objects['source-key'].copy_to('target-key', :bucket_name => 'target-bucket')
answered Aug 16, 2018 by Priyaj
• 58,020 points
0 votes

It's possible with recent aws-sdk gem, see the code sample:

require 'aws-sdk'

AWS.config(
  :access_key_id     => '***',
  :secret_access_key => '***',
  :max_retries       => 10
)

file     = 'test_file.rb'
bucket_0 = {:name => 'bucket_from', :endpoint => 's3-eu-west-1.amazonaws.com'}
bucket_1 = {:name => 'bucket_to',   :endpoint => 's3.amazonaws.com'}

s3_interface_from = AWS::S3.new(:s3_endpoint => bucket_0[:endpoint])
bucket_from       = s3_interface_from.buckets[bucket_0[:name]]
bucket_from.objects[file].write(open(file))

s3_interface_to   = AWS::S3.new(:s3_endpoint => bucket_1[:endpoint])
bucket_to         = s3_interface_to.buckets[bucket_1[:name]]
bucket_to.objects[file].copy_from(file, {:bucket => bucket_from})

answered Aug 28, 2018 by eatcodesleeprepeat
• 4,710 points

Related Questions In Cloud Computing

0 votes
1 answer

Is there a way to transfer files between AWS s3 and ec2

The answer is a definite yes yes. ...READ MORE

answered Apr 17, 2018 in Cloud Computing by brat_1
• 7,200 points
917 views
+4 votes
2 answers

How come AWS S3 is erasing my extension from PDF files?

I think the problem should be with ...READ MORE

answered Mar 27, 2018 in Cloud Computing by code_ninja
• 6,300 points
4,044 views
+3 votes
6 answers

Are the S3 buckets in AWS, Region Specific?

Yes S3 buckets are region specific. When you ...READ MORE

answered Oct 16, 2018 in Cloud Computing by Rijo
30,035 views
0 votes
1 answer

Is it possible to use VPC to have access between two AWS Regions

Good question this. Currently this feature is ...READ MORE

answered Apr 18, 2018 in Cloud Computing by code_ninja
• 6,300 points
851 views
0 votes
1 answer

What is the difference between AWS S3 Bucket Log Vs AWS CloudTrail

Let me give you a few pointers: In ...READ MORE

answered Apr 19, 2018 in Cloud Computing by brat_1
• 7,200 points
1,522 views
0 votes
1 answer

AWS: Having trouble serving files with S3

Why go to the trouble of EC2 ...READ MORE

answered Aug 13, 2018 in Cloud Computing by bug_seeker
• 15,510 points
593 views
0 votes
1 answer

AWS: Is there a way I can edit files in S3 right away in the browser?

There is not currently an AWS-supported method ...READ MORE

answered Jun 19, 2018 in Cloud Computing by Meci Matt
• 9,460 points
5,231 views
0 votes
1 answer

AWS: S3 and EC2 inctances

Yes, it can be used for instances ...READ MORE

answered Jun 20, 2018 in Cloud Computing by DragonLord999
• 8,450 points
723 views
+3 votes
5 answers

AWS EFS vs EBS vs S3 (differences & when to use?)

EFS is: May not yet be available in ...READ MORE

answered Apr 9, 2018 in Cloud Computing by hemant
• 5,790 points
4,975 views
+2 votes
2 answers

Is there a way to add cache control in AWS S3?

use of  current upstream master branch will ...READ MORE

answered Apr 10, 2018 in Cloud Computing by hemant
• 5,790 points
8,688 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP