private String getBucketRegionViaHeadRequest ( String bucketName ) { String bucketRegion = null ; try { Request < HeadBucketRequest > request = createRequest ( bucketName , null , new HeadBucketRequest ( bucketName ) , HttpMethodName . HEAD ) ; request . addHandlerContext ( HandlerContextKey . OPERATION_NAME , "HeadBucket" ) ; HeadBucketResult result = invoke ( request , new HeadBucketResultHandler ( ) , bucketName , null , true ) ; bucketRegion = result . getBucketRegion ( ) ; } catch ( AmazonS3Exception exception ) { if ( exception . getAdditionalDetails ( ) != null ) { bucketRegion = exception . getAdditionalDetails ( ) . get ( Headers . S3_BUCKET_REGION ) ; } } if ( bucketRegion == null && log . isDebugEnabled ( ) ) { log . debug ( "Not able to derive region of the " + bucketName + " from the HEAD Bucket requests." ) ; } return bucketRegion ; }
Retrieves the region of the bucket by making a HeadBucket request to us - west - 1 region .