# How to Copy or Duplicate Files Between AWS S3 Buckets

Duplicating files from one AWS S3 bucket to another is a common task when
migrating data, creating backups, or deploying content across environments. This
guide walks you through the methods to copy objects from one bucket to another
efficiently


PREREQUISITES

Before you begin, ensure that you have:

 * An AWS account

 * AWS CLI installed on your system

 * IAM credentials with s3:GetObject access on the source bucket and
   s3:PutObject access on the destination bucket

 * Both buckets created in the same or compatible AWS regions


METHOD 1: USING AWS CLI


STEP 1: INSTALL AND CONFIGURE AWS CLI

If not already installed:

 * Download AWS CLI for Windows, Mac, or Linux
   [https://docs.aws.amazon.com/cli/latest/userguide/install-cliv2.html]

Then configure:

aws configure

Enter your Access Key, Secret Key, region (e.g. af-south-1), and output format
(json recommended).


STEP 2: USE THE SYNC COMMAND

To copy all files and folders from one bucket to another:

aws s3 sync s3://source-bucket-name s3://destination-bucket-name --region your-region

📌 Example:

aws s3 sync s3://my-old-bucket s3://my-new-bucket --region af-south-1

Optional Flags:

 * --delete: Remove files in the destination that don’t exist in the source

 * --exclude "*.tmp": Skip specific files or patterns

 * --dryrun: Test the command before executing it


METHOD 2: COPYING A SPECIFIC FILE

To copy a single file:

aws s3 cp s3://source-bucket/path/to/file.pdf s3://destination-bucket/path/to/file.pdf

You can also use --recursive to copy entire folders:

aws s3 cp s3://source-bucket/folder/ s3://destination-bucket/folder/ --recursive


COMMON ISSUES

Issue

Solution

AccessDenied

Ensure your IAM user has s3:GetObject on the source and s3:PutObject on the
destination

Slow transfers

Use --only-show-errors or run during off-peak hours

Bucket in different region

Add --region explicitly for both source and destination if needed


IAM POLICY EXAMPLE

Here’s an example IAM policy for copying between buckets:

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Action": ["s3:GetObject", "s3:ListBucket"],
      "Resource": ["arn:aws:s3:::source-bucket/*", "arn:aws:s3:::source-bucket"]
    },
    {
      "Effect": "Allow",
      "Action": ["s3:PutObject"],
      "Resource": ["arn:aws:s3:::destination-bucket/*"]
    }
  ]
}

If you need to automate this process or integrate it into a deployment pipeline,
feel free to contact our DevOps team for advanced scripting assistance.