@@ -244,7 +244,14 @@ protected S3ClientBuilder buildClientBuilder(S3ClientSettings clientSettings, Sd
244244 s3clientBuilder .forcePathStyle (true );
245245 }
246246
247- s3clientBuilder .region (getClientRegion (clientSettings ));
247+ final var clientRegion = getClientRegion (clientSettings );
248+ if (clientRegion == null ) {
249+ // If no region or endpoint is specified then (for BwC with SDKv1) default to us-east-1 and enable cross-region access:
250+ s3clientBuilder .region (Region .US_EAST_1 );
251+ s3clientBuilder .crossRegionAccessEnabled (true );
252+ } else {
253+ s3clientBuilder .region (clientRegion );
254+ }
248255
249256 if (Strings .hasLength (clientSettings .endpoint )) {
250257 s3clientBuilder .endpointOverride (URI .create (clientSettings .endpoint ));
@@ -253,11 +260,14 @@ protected S3ClientBuilder buildClientBuilder(S3ClientSettings clientSettings, Sd
253260 return s3clientBuilder ;
254261 }
255262
263+ @ Nullable // if the region is wholly unknown (falls back to us-east-1 and enables cross-region access)
256264 Region getClientRegion (S3ClientSettings clientSettings ) {
257265 if (Strings .hasLength (clientSettings .region )) {
258266 return Region .of (clientSettings .region );
259267 }
260- if (Strings .hasLength (clientSettings .endpoint )) {
268+ final String endpointDescription ;
269+ final var hasEndpoint = Strings .hasLength (clientSettings .endpoint );
270+ if (hasEndpoint ) {
261271 final var guessedRegion = RegionFromEndpointGuesser .guessRegion (clientSettings .endpoint );
262272 if (guessedRegion != null ) {
263273 LOGGER .warn (
@@ -269,30 +279,39 @@ Region getClientRegion(S3ClientSettings clientSettings) {
269279 S3ClientSettings .REGION .getConcreteSettingForNamespace ("CLIENT_NAME" ).getKey ()
270280 );
271281 return Region .of (guessedRegion );
272- } else {
273- LOGGER .info (
274- """
275- found S3 client with endpoint [{}] which does not map to a known AWS region; \
276- to suppress this message, configure the [{}] setting on this node""" ,
277- clientSettings .endpoint ,
278- S3ClientSettings .REGION .getConcreteSettingForNamespace ("CLIENT_NAME" ).getKey ()
279- );
280282 }
283+ endpointDescription = "configured endpoint [" + clientSettings .endpoint + "]" ;
284+ } else {
285+ endpointDescription = "no configured endpoint" ;
281286 }
282287 final var defaultRegion = this .defaultRegion ;
283288 if (defaultRegion != null ) {
284289 LOGGER .debug ("""
285- found S3 client with no configured region, using region [{}] from SDK""" , defaultRegion );
290+ found S3 client with no configured region and {} , using region [{}] from SDK""" , endpointDescription , defaultRegion );
286291 return defaultRegion ;
287292 }
288- LOGGER .warn (
289- """
290- found S3 client with no configured region, falling back to [{}]; \
291- to suppress this warning, configure the [{}] setting on this node""" ,
292- Region .US_EAST_1 ,
293- S3ClientSettings .REGION .getConcreteSettingForNamespace ("CLIENT_NAME" ).getKey ()
294- );
295- return Region .US_EAST_1 ;
293+
294+ if (hasEndpoint ) {
295+ LOGGER .warn (
296+ """
297+ found S3 client with no configured region and {}, falling back to [{}]; \
298+ to suppress this warning, configure the [{}] setting on this node""" ,
299+ endpointDescription ,
300+ Region .US_EAST_1 ,
301+ S3ClientSettings .REGION .getConcreteSettingForNamespace ("CLIENT_NAME" ).getKey ()
302+ );
303+ return Region .US_EAST_1 ;
304+ } else {
305+ LOGGER .warn (
306+ """
307+ found S3 client with no configured region and {}, falling back to [{}] and enabling cross-region access; \
308+ to suppress this warning, configure the [{}] setting on this node""" ,
309+ endpointDescription ,
310+ Region .US_EAST_1 ,
311+ S3ClientSettings .REGION .getConcreteSettingForNamespace ("CLIENT_NAME" ).getKey ()
312+ );
313+ return null ;
314+ }
296315 }
297316
298317 @ Nullable // in production, but exposed for tests to override
0 commit comments