conteh
conteh

Reputation: 1614

AWS JAVA SDK error "The bucket is in this region: us-east-1. Please use this region to"

I'm getting the error

"The bucket is in this region: us-east-1. Please use this region to..."

when trying to delete a bucket

s3.deleteObject(new DeleteObjectRequest(bucketName, var));

I'm executing a java application in ca-central-1 and accessing buckets that are in ca-central-1 according to the region column in the AWS S3 Management Console.

The folder in question is a child of a bucket that is displayed as existing in the ca-central-1 region.

Is it possible to that a folder of a bucket in ca-central-1 is in us-east-1 for example if I moved the bucket from us-east-1 bucket to a bucket in ca-central-1?

I note that the folders in a bucket don't have a region displayed in the management console. The error doesn't make sense to me as the bucket of which the folder in question is in is clearly marked as being ca-central-1.

Maven

    <dependency>
        <groupId>com.amazonaws</groupId>
        <artifactId>aws-java-sdk</artifactId>
        <version>1.11.700</version>
    </dependency>
    <dependency>
        <groupId>com.amazonaws</groupId>
        <artifactId>aws-java-sdk-sts</artifactId>
        <version>1.11.701</version>
    </dependency>

Regards Conteh

Upvotes: 2

Views: 14049

Answers (1)

smac2020
smac2020

Reputation: 10704

When using the AWS SDK for Java, your service client needs to be configured to the same region. For example, the service client to interact with this bucket needs to be:

  Region region = Region.US_WEST_2;
  S3Client s3 = S3Client.builder()
                .region(region)
                .build();

enter image description here

Your question - "Is it possible to that a sub-directory of a bucket in ca-central-1 is in us-east-1"

This is not possible. An AWS resource - like a bucket is only in 1 region. An Amazon S3 bucket is not split among different regions.

Also - this code is not part of the S3 Java V1 API:

s3 = requests.getS3();

Consider moving to V2 of the AWS SDK for Java. You can find S3 V2 API examples here and the V2 dependencies are in the POM file.

https://github.com/awsdocs/aws-doc-sdk-examples/tree/master/javav2/example_code/s3

Upvotes: 2

Related Questions