Skip to content

Create design doc for cross-region S3 client #3937

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

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions docs/design/services/s3/cross-region-s3-client.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
**Design:** New Feature, **Status:** [In Development](../README.md)

# Cross-Region S3 Client Design

## Overview

The [cross-region S3 client](https://github.com/aws/aws-sdk-java-v2/issues/52) is a feature supported in the AWS SDK for Java 1.x that automatically routes requests to the correct bucket region. This is useful for customers who do not know the region of the bucket beforehand. Without this support, customers would need to write their own logic to retrieve the region of a specific bucket for each request and redirect the request accordingly, which could be complex and error prone. This documentation proposes the design to implement it in the AWS SDK for Java 2.x.

## Specification

The SDK 2.x will support this feature in the S3 sync client, S3 async client and the AWS-CRT based S3 client.

### Usage Examples

#### Example 1: enabling cross-region access in the S3 sync client

```
S3ClientBuilder s3ClientBuilder = S3Client.builder()
Copy link
Contributor

@joviegas joviegas Apr 26, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The crossRegionAcccessEnabled API will be made available to only "S3Client.builder" and not to AwsClientBuilder , right ? since it will make it available for all the clients even if its not supported.
Thus we might need to add Customization for S3 only to show this API.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, alternatively, we could consider adding it to S3Configuration, I don't have strong opinions. We still need to add crossRegionAcccessEnabled to the top level S3CrtAsyncClient builder though.

.crossRegionAcccessEnabled(true)
.build();
```

#### Example 2: enabling cross-region access in the S3 async client

```
// Java S3 async client
S3AsyncClient s3Client = S3AsyncClient.builder()
.crossRegionAcccessEnabled(true)
.build();

// AWS CRT-based S3 async client
S3AsyncClient s3CrtClient = S3AsyncClient.crtBuilder()
.crossRegionAcccessEnabled(true)
.build();
```

### Client Configuration

Users can enable this feature through a client configuration on the client builder, `crossRegionAccessEnabled`. It is default to false.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

small typo: It is default to false
should be It is set to false by default or something like that


### Implementation Notes

The region retrieval and redirect logic is implemented in a customized `S3EndPointProvider`. If `crossRegionAccessEnabled` is true, the SDK will add this customized endpoint provider to the client, which will first attempt to retrieve the region of the bucket by sending a HeadObject request and then configure the region for that request. It uses an [LRU cache](https://github.com/aws/aws-sdk-java-v2/blob/master/utils/src/main/java/software/amazon/awssdk/utils/cache/lru/LruCache.java) to bypass HeadObject API call for frequently used buckets and access points for performance optimization.

## Alternatives Considered

The alternative is to create a standalone S3 client that maintains a pool of S3 client instances configured with different regions. This approach is not recommended because 1) using multiple S3 clients means more resources will be used, which could confuse users 2) the implementation is more complex.

## Appendix: Java SDK v1 customer experience

```
AmazonS3ClientBuilder.standard()
.withRegion(region)
.withForceGlobalBucketAccessEnabled(enableGlobalBucketAccess)
.build();
```