Created
November 3, 2018 18:22
-
-
Save Kulasangar/964fae7247eb2d241d833c9cfa7b3095 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.amazonaws.services.s3.AmazonS3; | |
import com.amazonaws.services.s3.AmazonS3ClientBuilder; | |
import com.amazonaws.AmazonServiceException; | |
/** | |
* Copy an object from one Amazon S3 bucket to another. | |
*/ | |
public class test { | |
public static void main(String[] args) { | |
final String USAGE = "\n" + "To run this example, supply the name (key) of an S3 object, the bucket name\n" | |
+ "that it's contained within, and the bucket to copy it to.\n" + "\n" | |
+ "Ex: CopyObject <objectname> <frombucket> <tobucket>\n"; | |
if (args.length < 3) { | |
System.out.println(USAGE); | |
System.exit(1); | |
} | |
String object_key = args[0]; | |
String from_bucket = args[1]; | |
String to_bucket = args[2]; | |
System.out.format("Copying object %s from bucket %s to %s\n", object_key, from_bucket, to_bucket); | |
final AmazonS3 s3 = AmazonS3ClientBuilder.defaultClient(); | |
try { | |
s3.copyObject(from_bucket, object_key, to_bucket, object_key); | |
} catch (AmazonServiceException e) { | |
System.err.println(e.getErrorMessage()); | |
System.exit(1); | |
} | |
System.out.println("Done!"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment