How to copy contents from one S3 bucket to another

Copy file from one bucket to another within the same region where bucketname1 is the source bucket and bucketname2 is the target bucket.

aws s3 cp s3://bucketname1/filename s3://bucketname2/filename

Copy file from one bucket to another in a different region as below where bucketname1 is the source bucket and bucketname2 is the target bucket.

aws s3 cp s3://bucketname1/filename s3://bucketname2/filename --source-region us-east-1 --region eu-west-1

Copy all the contents of bucketname1 to bucketname2

aws 3 sync s3://bucketname1 s3://bucketname2

To exclude copying one of the folders while copying an entire bucket, use the below command where ‘prefix‘ is the folder name that you would like to exclude.

aws 3 sync s3://bucketname1 s3://bucketname2 --exclude 'prefix/*'

To exclude multiple folders while copying contents from one s3 bucket to another, use below command where ‘prefix1’, ‘prefix2’, ‘prefix3’ are the folders that should be excluded

aws 3 sync s3://bucketname1 s3://bucketname2 --exclude 'prefix1/*' --exclude 'prefix2/*' --exclude 'prefix3/*'

See also  How to cancel a running query in Redshift