我正在尝试将文件从s3存储桶中的一个文件夹复制到另一个文件夹。我正在使用aws jdk复制文件。我检查了其他问题,但主要是使用其他sdk' s。我使用了这篇文章中提到的相同方式(AWS S3 copy object source key and destination key),只是我的密钥包含文件夹结构。
我正在使用以下代码。
public CopyObjectResult copyToAFolder(String sourceBucketName,
String sourceKeyName, String destinationBucketName,
String destinationKeyName) {
LOG.info(
"Archiving the file Source:{},SourceKey:{},Destination:{},DestinationKey:{}",
new Object[] { sourceBucketName, sourceKeyName, destinationBucketName,
destinationKeyName });
CopyObjectRequest copyObjRequest = new CopyObjectRequest(sourceBucketName,
sourceKeyName, destinationBucketName, destinationKeyName);
return amazonS3Client.copyObject(copyObjRequest);
}
我正在传递这样的参数。我通过使用列表服务获得了密钥名称,因此密钥名称是正确的。
sourceBucketName: myTestBucket
sourceKeyName:testing/movement/sample.txt
destinationBucketName:myTestBucket
destinationKeyName:testing/movement2/sample.txt(I have tried with /testing/movement2/ also)
这与accessDenied异常失败。我可以完全访问此存储桶,我可以使用S3Client从此存储桶中删除文件。拒绝访问仅限于复制。不知道为什么会这样。
错误。
com.amazonaws.services.s3.model.AmazonS3Exception: Access Denied (Service: Amazon S3; Status Code: 403; Error Code: AccessDenied; Request ID: XXXXXXXXXXXX)
at com.amazonaws.http.AmazonHttpClient.handleErrorResponse(AmazonHttpClient.java:1343) ~[aws-java-sdk-core-1.11.37.jar:na]
at com.amazonaws.http.AmazonHttpClient.executeOneRequest(AmazonHttpClient.java:961) ~[aws-java-sdk-core-1.11.37.jar:na]
at com.amazonaws.http.AmazonHttpClient.executeHelper(AmazonHttpClient.java:738) ~[aws-java-sdk-core-1.11.37.jar:na]
at com.amazonaws.http.AmazonHttpClient.doExecute(AmazonHttpClient.java:489) ~[aws-java-sdk-core-1.11.37.jar:na]
at com.amazonaws.http.AmazonHttpClient.executeWithTimer(AmazonHttpClient.java:448) ~[aws-java-sdk-core-1.11.37.jar:na]
at com.amazonaws.http.AmazonHttpClient.execute(AmazonHttpClient.java:397) ~[aws-java-sdk-core-1.11.37.jar:na]
at com.amazonaws.http.AmazonHttpClient.execute(AmazonHttpClient.java:378) ~[aws-java-sdk-core-1.11.37.jar:na]
at com.amazonaws.services.s3.AmazonS3Client.invoke(AmazonS3Client.java:4039) ~[aws-java-sdk-s3-1.11.37.jar:na]
at com.amazonaws.services.s3.AmazonS3Client.copyObject(AmazonS3Client.java:1714) ~[aws-java-sdk-s3-1.11.37.jar:na]
答案 0 :(得分:1)
我有一个类似的问题,我被拒绝访问..
原来是因为我没有用元数据复制对象,因此添加了加密算法。
ObjectMetadata metadatum = new ObjectMetadata();
metadatum.setSSEAlgorithm(AES);
request.setNewObjectMetadata(metadatum);
答案 1 :(得分:0)
解决方案可以是,
感谢。