Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

is it possible to create AWS s3 bucket with null region

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)
like image 761
jcalloway Avatar asked Aug 30 '16 23:08

jcalloway


3 Answers

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)
like image 102
jcalloway Avatar answered Oct 14 '22 10:10

jcalloway


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

like image 28
Frederic Henri Avatar answered Oct 14 '22 10:10

Frederic Henri


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.

like image 38
Avinash Barnwal Avatar answered Oct 14 '22 08:10

Avinash Barnwal