jcalloway jcalloway - 1 month ago 60
Java Question

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)

Answer

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)