是否可以创建具有空区域的AWS s3存储桶

时间:2016-08-30 23:35:58

标签: java amazon-web-services amazon-s3

我看到一个Java堆栈跟踪错误,意味着存在一个带有空区域的S3 Bucket。

这可能吗?我试图重新创建错误和空区域s3存储桶但没有成功。

com.amazonaws.services.s3.model.AmazonS3Exception: The bucket is in this region: null.Please use this region to retry the request (Service: Amazon S3; Status Code: 301; Error Code: PermanentRedirect; Request ID: EA0959BA1B1D56A7)
        at com.amazonaws.http.AmazonHttpClient.handleErrorResponse(AmazonHttpClient.java:1372)
        at com.amazonaws.http.AmazonHttpClient.executeOneRequest(AmazonHttpClient.java:919)
        at com.amazonaws.http.AmazonHttpClient.executeHelper(AmazonHttpClient.java:697)
        at com.amazonaws.http.AmazonHttpClient.doExecute(AmazonHttpClient.java:449)
        at com.amazonaws.http.AmazonHttpClient.executeWithTimer(AmazonHttpClient.java:411)
        at com.amazonaws.http.AmazonHttpClient.execute(AmazonHttpClient.java:360)
        at com.amazonaws.services.s3.AmazonS3Client.invoke(AmazonS3Client.java:3962)
        at com.amazonaws.services.s3.AmazonS3Client.getBucketPolicy(AmazonS3Client.java:2544)
        at com.amazonaws.services.s3.AmazonS3Client.getBucketPolicy(AmazonS3Client.java:2504)

4 个答案:

答案 0 :(得分:10)

我能够重现此错误。 当您的AmazonS3Client设置为与您正在呼叫的存储区不同的区域时,就会发生这种情况。

def s3Client = new AmazonS3Client(new BasicAWSCredentials("accessKey", "secretKey"))
s3Client.setRegion(com.amazonaws.regions.Region.getRegion( Regions.AP_NORTHEAST_1) )
def policy = s3Client.getBucketPolicy('joshuacalloway-us-east-1-bucket')
println policy

- >结果

Result: com.amazonaws.services.s3.model.AmazonS3Exception: The bucket is in this region: null. Please use this region to retry the request (Service: Amazon S3; Status Code: 301; Error Code: PermanentRedirect; Request ID: 5F941FB57305BDEC), S3 Extended Request ID: xajT6YydJU+EfoOFWtD4SFiaxS7zoOUS9OKAmFVq/CECmoNuCbcDu4q7z4L+kztbyrMxb5c/Bcw=
    at com.amazonaws.http.AmazonHttpClient$RequestExecutor.handleErrorResponse(AmazonHttpClient.java:1543)
    at com.amazonaws.http.AmazonHttpClient$RequestExecutor.executeOneRequest(AmazonHttpClient.java:1181)
    at com.amazonaws.http.AmazonHttpClient$RequestExecutor.executeHelper(AmazonHttpClient.java:962)

答案 1 :(得分:3)

不,你不能 - 在现有区域内创建一个必须的存储桶,使用此信息也是从存储桶中检索对象的方式

http://docs.aws.amazon.com/AmazonS3/latest/dev/UsingBucket.html

  

创建存储桶时,您需要提供要在其中创建存储桶的名称和AWS区域

     

如果您未指定区域,Amazon S3将在美国东部(弗吉尼亚北部)区域中创建存储桶。

如果您希望在不同区域自动复制存储桶,则可以启用Cross-Region Replication

答案 2 :(得分:1)

这是误导性错误。我也遇到过这个问题,但发现它是一个与存储桶名称拼写错误的策略。例如而不是mybucket,我提到过mybuckt。

"Resource": [
     "arn:aws:s3:::mybuckt",
     "arn:aws:s3:::mybuckt/*"
]

一旦我纠正了,问题就解决了。

答案 3 :(得分:0)

确保您的env和s3存储桶位于同一区域。如果没有,则提供一些存储桶策略,以便从其他区域访问您的存储桶。