Amazon S3 Java SDK: recursive copy from S3 to S3

Using the Java SDK for AWS S3, I need to copy each object under one s3 prefix to another s3 prefix, so the files are here in $prefix_1 :

 $prefix_1/key_remainder_1 $prefix_1/key_remainder_2 $prefix_1/key_remainder_3 

copied to $prefix_2 , which therefore looks like this:

 $prefix_2/key_remainder_1 $prefix_2/key_remainder_2 $prefix_2/key_remainder_3 

Using aws cli, I can use aws s3 sync $bucket/$prefix1 $bucket/$prefix2 to perform this operation. At first glance, sync is essentially a list followed by a bunch of generated COPYs. However, java sdk does not seem to support the all-in-one approach (i.e., one command / method, such as sync ) to copy files from one prefix to another.

For some reason, TransferManager can do bulk copy between s3 and disk, but not between s3 and s3.

Apparently i either have to

  • explicitly LIST all objects under the prefix, then run a bunch of individual COPY s
  • use TransferManager to first download everything from the source prefix to disk, and then load the local directory into the destination prefix.

Did I miss something? Is there a way to get what I want using the java SDK?

+5
source share

All Articles