Reputation: 1155
Am seeing a Java stacktrace error that implies there is an S3 Bucket with null region.
Is this possible? I tried to re-create the error and a null-region s3 bucket with no success.
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)
Upvotes: 9
Views: 11318
Reputation: 33
Make sure that your env and the s3 buckets are in the same region. If not then provide some bucket policies to make your bucket accessible from the other region.
Upvotes: 0
Reputation: 1155
I was able to reproduce this error. It occurs when your AmazonS3Client is set to a different region then the bucket you are calling.
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
--> results in
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)
Upvotes: 13
Reputation: 181
This is misleading error. I also faced this issue but identified it to be a Policy which had a spelling mistake with the bucket name. e.g. instead of mybucket, i had mentioned mybuckt.
"Resource": [
"arn:aws:s3:::mybuckt",
"arn:aws:s3:::mybuckt/*"
]
Once I corrected it, the issue got resolved.
Upvotes: 1
Reputation: 53713
No you can't - A bucket must be created within an existing region, using this information is also how you retrieve objects from your bucket
http://docs.aws.amazon.com/AmazonS3/latest/dev/UsingBucket.html
When you create a bucket, you provide a name and AWS Region where you want the bucket created
If you don’t specify a region, Amazon S3 creates the bucket in the US East (N. Virginia) Region.
you can enable Cross-Region Replication if you want your bucket to be automatically replicated in different region
Upvotes: 3