I am copying S3 objects from one Bucket A (region: us-west-2) to another Bucket B( region: us-east-1), While doing so, I am getting these errors: The bucket is in this region: us-east-1. Please use this region to retry the request (Service: Amazon S3; Status Code: 301; Error Code: PermanentRedirect; Request ID: 8A8C33763F67F1EE; S3 Extended Request ID: y2IHUTD6Fsi3aNLLJCWX4ZvnaDM9kxxk8yuJIUXZGBoIkWH9GQxHiJFog5No6pd1S4WK6cHIT14=; Proxy: null): com.amazonaws.services.s3.model.AmazonS3Exception
This is how I have created S3Client:
public AmazonS3 getAmazonS3(final AppConfigTree appConfigTree) {
return AmazonS3ClientBuilder
.standard()
.withClientConfiguration(s3ClientConfiguration())
.withRegion(appConfigTree.findString("us-west-2"))
.build();}
S3 Copy Operation :
private void copyObjects(final ObjectListing objects, final String srcBucket, final String srcPath,
final String destBucket, final String destPath) {
log.info(String.format("Copying %d objects from %s/%s to %s/%s.",
objects.getObjectSummaries().size(), srcBucket, srcPath, destBucket, destPath));
final ObjectMetadata metadata = new ObjectMetadata();
for (final S3ObjectSummary summary : objects.getObjectSummaries()) {
final CopyObjectRequest request = new CopyObjectRequest(srcBucket, summary.getKey(), destBucket,
FileUtility.getFilePath(summary.getKey(), destPath));
metadata.setContentType(getContentType(destPath));
request.setNewObjectMetadata(metadata);
amazonS3.copyObject(request);
}
log.info(String.format("Copied %d objects.", objects.getObjectSummaries().size()));
}