aws-sdk-java-v2 icon indicating copy to clipboard operation
aws-sdk-java-v2 copied to clipboard

Cross-Region S3 Client

Open millems opened this issue 8 years ago • 9 comments

The 1.11.x S3 client automatically routed requests to the correct bucket region in a complicated manner. The 2.0.x client does not perform this automatic re-routing.

We should create a wrapper to pool S3 clients for different regions and automatically route requests to the region in which the bucket was created.

millems avatar Jul 06 '17 19:07 millems

Is there an update on when this feature would be shipped out ?

manasshukla avatar Jun 20 '20 08:06 manasshukla

Sorry, no update.

It's not our #1 priority, because with access points and other arn-based ways of accessing buckets/objects plus the use-arn-region flag, the SDK will automatically route the request to the correct region without the overhead of an extra call to AWS to find out where the bucket actually is.

I understand there's still value in this feature request, since the caller may not have a full bucket ARN.

millems avatar Sep 25 '20 22:09 millems

If anyone thinks using ARNs like arn:aws:s3:::mybucket will work, they won't https://github.com/aws/aws-sdk-java-v2/issues/2244

byF avatar Jul 22 '21 21:07 byF

@millems Hi. Any plan of supporting this feature ? A lot of people think they need this feature from the perspective of customers using AWS S3 products.

pkgonan avatar Nov 28 '21 08:11 pkgonan

At some point, probably, but in the meantime you could try using access points which automatically support cross-region request routing.

millems avatar Nov 30 '21 18:11 millems

@millems Oh. That's good news. When are you expecting?

pkgonan avatar Dec 01 '21 01:12 pkgonan

@pkgonan Unfortunately we have no expected date to report at this time.

millems avatar Dec 01 '21 01:12 millems

@millems Thanks for your reply. :)

pkgonan avatar Dec 01 '21 01:12 pkgonan

FYI we are working on adding cross-region S3 client to Spring Cloud AWS. It's early stage but looks promising so far: https://github.com/awspring/spring-cloud-aws/blob/3.0.x-s3/spring-cloud-aws-s3-parent/spring-cloud-aws-s3/src/main/java/io/awspring/cloud/s3/CrossRegionS3Client.java

Basic idea is that every region-specific method is wrapped in a try catch that on http status 301 uses client created for the region where the bucket got created. Clients are cached both by region and also by bucket name (to speed up subsequent calls for the same bucket). Implementation is a bit Spring specific as we use LRU cache from spring-core, but if needed this can be replaced with something else or abstracted out.

Repetitive chunk of this class is generated with JavaParser. If you're interested this is a very sketchy implementation:

  • https://github.com/awspring/spring-cloud-aws/blob/3.0.x-s3/spring-cloud-aws-s3-parent/spring-cloud-aws-s3-codegen/src/main/java/io/awspring/cloud/s3/codegen/CrossRegionS3ClientGenerator.java
  • https://github.com/awspring/spring-cloud-aws/blob/3.0.x-s3/spring-cloud-aws-s3-parent/spring-cloud-aws-s3-codegen/src/main/java/io/awspring/cloud/s3/codegen/CrossRegionS3ClientTemplate.java

maciejwalkowiak avatar Mar 24 '22 14:03 maciejwalkowiak

This feature has been released in 2.20.99. You can enable it by setting crossRegionAccessEnabled to true on the S3 client builder. Example:

S3AsyncClient client = S3AsyncClient.builder()
                                    .crossRegionAccessEnabled(true)
                                    .build();

I'll go ahead and close this issue. As always, feedback is welcome! :)

zoewangg avatar Jul 14 '23 00:07 zoewangg

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see. If you need more assistance, please open a new issue that references this one. If you wish to keep having a conversation with other community members under this issue feel free to do so.

github-actions[bot] avatar Jul 14 '23 00:07 github-actions[bot]

So the addition of .crossRegionAccessEnabled(true) is nice... but it still doesn't work with opt-in regions, even if your account is opted into the given region. For example, if I create an S3 client in the us-east-1 region and then try to head an object in an af-south-1 bucket that I own, it will result in a 400 error. Or if I create an S3 client in the af-south-1 region and then try to head an object in an us-east-1 bucket that I own, it will also result in a 400 error. The SDKv1 client didn't have this problem...

dasmowenator avatar Mar 25 '24 17:03 dasmowenator