6868import static org .apache .hadoop .fs .s3a .auth .SignerFactory .createHttpSigner ;
6969import static org .apache .hadoop .fs .s3a .impl .AWSHeaders .REQUESTER_PAYS_HEADER ;
7070import static org .apache .hadoop .fs .s3a .impl .InternalConstants .AUTH_SCHEME_AWS_SIGV_4 ;
71+ import static org .apache .hadoop .fs .s3a .impl .RegionResolution .RegionResolutionMechanism .Ec2Metadata ;
7172import static org .apache .hadoop .fs .s3a .impl .RegionResolution .RegionResolutionMechanism .Sdk ;
7273import static org .apache .hadoop .fs .s3a .impl .RegionResolution .calculateRegion ;
7374
@@ -313,7 +314,15 @@ private <BuilderT extends S3BaseClientBuilder<BuilderT, ClientT>, ClientT> Regio
313314 // which tests expect.
314315 builder .fipsEnabled (resolution .isUseFips ());
315316
316- if (Sdk != resolution .getMechanism ()) {
317+ final RegionResolution .RegionResolutionMechanism mechanism = resolution .getMechanism ();
318+ if (Sdk == mechanism ) {
319+ // handing off all resolution to SDK.
320+ // region configuration was set to empty string.
321+ // allow this if people really want it; it is OK to rely on this
322+ // when deployed in EC2.
323+ DEFAULT_REGION_CHAIN .info (SDK_REGION_CHAIN_IN_USE );
324+ LOG .debug (SDK_REGION_CHAIN_IN_USE );
325+ } else {
317326 final Region region = resolution .getRegion ();
318327 builder .region (requireNonNull (region ));
319328 // s3 cross region access
@@ -327,13 +336,6 @@ private <BuilderT extends S3BaseClientBuilder<BuilderT, ClientT>, ClientT> Regio
327336 LOG .debug ("Setting endpoint to {}" , endpointUri );
328337 }
329338 }
330- } else {
331- // handing off all resolution to SDK.
332- // region configuration was set to empty string.
333- // allow this if people really want it; it is OK to rely on this
334- // when deployed in EC2.
335- DEFAULT_REGION_CHAIN .info (SDK_REGION_CHAIN_IN_USE );
336- LOG .debug (SDK_REGION_CHAIN_IN_USE );
337339 }
338340 return resolution ;
339341 }
0 commit comments