I am writing JAVA code to copy object within AWS S3.
CopyObjectRequest copyObjRequest = new CopyObjectRequest(srcbucket, srcKey, destbucket, destKey);
s3Client.copyObject(copyObjRequest);
What is source key and destination key? I read a lot in theory but no where it is mentioned that from where we can get these keys. Maybe I missed some part.
Please help me to get source and destination keys of bucket....
Please provide an example for that also...
From the documentation:
CopyObjectRequest(java.lang.String sourceBucketName, java.lang.String sourceKey, java.lang.String destinationBucketName, java.lang.String destinationKey)
Constructs with basic options.
The "sourceKey" and "destinationKey" are the keys of the S3 Objects you are looking to copy. The "sourceKey" is the key of the existing object, and the "destinationKey" is the keyName you want to use for the copy of the source object.
To make a copy of the object in the same bucket:
CopyObjectRequest copyObjRequest = new CopyObjectRequest("myBucket", "myObject.txt", "myBucket", "myNewObject.txt");
s3Client.copyObject(copyObjRequest);
To make a copy of the object in a different bucket:
CopyObjectRequest copyObjRequest = new CopyObjectRequest("myBucket", "myObject.txt", "myOtherBucket", "myNewObject.txt");
s3Client.copyObject(copyObjRequest);
Further Reading:
- S3 Documentation - Object Keys and Metadata
- S3 Documentation - Working with Amazon S3 Objects