-
Notifications
You must be signed in to change notification settings - Fork 840
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to detect bucket region #3554
Comments
Hello @paleloser , Thank you very much for your submission. The exception
In the following sample: S3ClientBuilder clientBuilder = S3Client.builder();
[...]
clientBuilder.credentialsProvider(credentialsProvider);
try (final S3Client client = clientBuilder.build()) {
final GetBucketLocationResponse response = client.getBucketLocation(GetBucketLocationRequest.builder().bucket("test-bucket-for-customer").build());
clientBuilder.region(Region.of(response.locationConstraintAsString()));
} You attempt to build an S3 client without any specified region to retrieve a bucket's location. This is unfortunately not possible in the AWS Java SDK V2. Example: The following modification to your sample should work to use getBucketLocation: try (final S3Client client = clientBuilder.region(`US_EAST_2`).build()) {
final GetBucketLocationResponse response = client.getBucketLocation(GetBucketLocationRequest.builder().bucket(bucket).build());
clientBuilder.region(Region.of(response.locationConstraintAsString()));
}
S3Client client = clientBuilder.build(); I have tested this out using my own account and bucket located in As a side note, we do have an open feature request in the AWS Java SDK V2 to support S3 client automatically routing requests to the correct bucket region: #52 I will transfer this issue submission to the AWS Java SDK V2 repository as this is in issue with the use of the AWS Java SDK V2 rather than V1. I would love to have your feedback on potential documentation improvement for the AWS Java SDK V2. Sincerely, Yasmine |
First of all, thank you for such quick and detailed response. It looks like your proposal does the job for me, unless for I've also 👍🏼 -ed the feature request. Regarding to possible documentation improvements on the AWS Java SDK v2, it'd be nice to have a section dedicated to this part in the S3 site. I mean, by reading the docs, I supposed that unless I already knew the region of the bucket, I couldn't perform any operation. But after this conversation I found out that some operations (like On the other side, having this restriction seems very weird to me (maybe I'm not enough familiar with how does the AWS API work). Because I've been able to connect to MinIO instances locally with the client, where the region didn't made any sense at all. So it would be also good to have some references on that. Again thank you. |
Hello @paleloser , Thank you very much for your detailed feedback. I will bring up the documentation improvement for the S3 portion of the developer guide to the docs team. I agree that this behavior should be documented for better visibility. Thank you very much again for your feedback and contribution. Sincerely, Yasmine |
Great to hear that. From my side, we can close this issue now. |
|
Describe the issue
Reading the documentation on how to use the SDK, I find that in order to initialize the client I previously must know which region am I going to talk to.
Let's say I have a program whose job is receiving a bucket URL,
S3://bucket-name
, plus the credentials to write objects on it (AWS_ACCESS_KEY_ID
andAWS_SECRET_ACCESS_KEY
). With that info. my program writes an object in the bucket. Currently my program doesn't accept more parameters.Thus, it would try to instantiate an
S3Client
the following way:However, when the program attempts so detect the region, it throws with the following exception:
Which in theory says that again, either the program must know previously in which region the bucket is located, or it won't be able to detect it dynamically.
Is that the expected behavior? Should I change my program input parameters to accept the bucket region as well? I find this very weird, since the URL
S3://
is the suggested way in the docs, and it doesn't contain all of the info about the target bucket.Thanks in advance.
Links
https://docs.aws.amazon.com/sdk-for-java/latest/developer-guide/home.html
https://docs.aws.amazon.com/sdk-for-java/latest/developer-guide/region-selection.html
https://docs.aws.amazon.com/AmazonS3/latest/userguide/access-bucket-intro.html
The text was updated successfully, but these errors were encountered: