aws s3 copy

  • Post author:
  • Post category:Amazon S3

How to Copy files, folders in AWS S3?

The copy operation creates a copy of an object that is already stored in Amazon S3.

Using the copy operation, you can:

  • Create additional copies of objects
  • Rename objects by copying them and deleting the original ones
  • Move objects across Amazon S3 locations
  • Change object metadata

Each object has metadata. When you copy an object, user-controlled system metadata and user-defined metadata are also copied. Amazon S3 resets the system-controlled metadata. For example, when you copy an object, Amazon S3 resets the creation date of the copied object.

Few other features of aws s3 copy

  • If the source object has encryption enabled, you must provide encryption information in your request so that Amazon S3 can decrypt the object for copying.
  • To copy more than one amazon S3 object in single request, Amazon S3 batch operations should be used.

To copy an object, you can do in multiple ways

Using S3 Console

  1. Sign in to the AWS Management Console and open the Amazon S3 console at
  2. Navigate to the Amazon S3 bucket or folder that contains the objects that you want to copy.
  3. Select the check box to the left of the names of the objects that you want to copy.
  4. Choose Actions and choose Copy from the list of options that appears.
  5. Select the destination type and destination account. To specify the destination path, choose Browse S3, navigate to the destination, and select the check box to the left of the destination. Choose Choose destination in the lower-right corner.
  6. Choose Copy in the bottom-right corner. Amazon S3 copies your objects to the destination.

Using S3 CLI

In any environments where aws cli is installed like EC2 instances, AWS cloud shell, you can execute the following command

aws s3 cp <LocalPath> <S3Uri> or <S3Uri> <LocalPath> or <S3Uri> <S3Uri>

LocalPath = Your Source path which can be a local file on a server

S3Uri = S3 path

aws s3 cp example

  • Copy a file from S3 to S3

aws s3 cp s3://bucket1/file.txt s3://bucket2/file.txt

  • Copy a local file to S3

aws s3 cp file.txt s3://bucket1/file.txt

  • Copy a file from S3 to Local

aws s3 cp s3://bucket1/file.txt file.txt

aws s3 cp folder

  • Copy folders

aws s3 cp /home/dir1/ s3://bucket1/ –recursive

aws s3 cp recursive

copying S3 objects to a local directory Recursively

aws s3 cp s3://bucket1 . –recursive

  • copying S3 objects to another bucket Recursively

aws s3 cp s3://bucket1/test1.txt to s3://bucket2/test1.txt –recursive

  • ACLs while copying S3 object

aws s3 cp s3://bucket1/test.txt s3://bucket2/test2.txt –acl public-read-write