spaenigs
spaenigs

Reputation: 152

Java aws sdk - The specified location-constraint is not valid (non-amazon)

I would like to create a bucket in the ceph object storage via the S3 API. Which works fine, if I use Pythons boto3:

s3 = boto3.resource(
   's3',
   endpoint_url='https://my.non-amazon-endpoint.com',
   aws_access_key_id=access_key,
   aws_secret_access_key=secret_key
)

bucket = s3.create_bucket(Bucket="my-bucket") # successfully creates bucket

Trying the same with java leads to an exception:

BasicAWSCredentials awsCreds = new BasicAWSCredentials(access_key, secret_key);

AwsClientBuilder.EndpointConfiguration config =
        new AwsClientBuilder.EndpointConfiguration(
                "https://my.non-amazon-endpoint.com",
                "MyRegion");

AmazonS3 s3Client = AmazonS3ClientBuilder.standard()
        .withCredentials(new AWSStaticCredentialsProvider(awsCreds))
        .withEndpointConfiguration(config)
        .build();

List<Bucket> buckets = s3Client.listBuckets();
// this works and lists all containers, hence the connection should be fine
for (Bucket bucket : buckets) {
    System.out.println(bucket.getName() + "\t" +
            StringUtils.fromDate(bucket.getCreationDate()));
}

Bucket bucket = s3Client.createBucket("my-bucket");
// AmazonS3Exception: The specified location-constraint is not valid (Service: Amazon S3; Status Code: 400; Error Code: InvalidLocationConstraint...

I am aware of several related issues, for instance this issue, but I was not able to adjust the suggested solutions to my non-amazon storage.

Digging deeper into the boto3 code, it turns out, that the LocationConstraint is set to None, if no region has been specified. But omitting the region in java leads to the InvalidLocationConstrain, too.

How do I have to configure the endpoint with the java s3 aws sdk to successfully create buckets?

Kind regards

UPDATE

Setting the signingRegion to "us-east-1" enables bucket creation functionality:

AwsClientBuilder.EndpointConfiguration config =
            new AwsClientBuilder.EndpointConfiguration(
                    "https://my.non-amazon.endpoint.com",
                    "us-east-1");

If one assigns another region, the sdk will parse the region from endpoint url, as specified here.

In my case, this leads to an invalid region, for instance non-amazon.

Upvotes: 4

Views: 5335

Answers (1)

spaenigs
spaenigs

Reputation: 152

Setting the signingRegion to "us-east-1" enables bucket creation functionality:

AwsClientBuilder.EndpointConfiguration config =
        new AwsClientBuilder.EndpointConfiguration(
                "https://my.non-amazon.endpoint.com",
                "us-east-1");

If one assigns another region, the sdk will parse the region from endpoint url, as specified here.

In my case, this leads to an invalid region, for instance non-amazon.

Upvotes: 3

Related Questions