@@ -695,21 +695,40 @@ async def check_file(self, drive_name, path):
695695
696696 return
697697
698- async def new_drive (self , new_drive_name , location = 'us-east-1' ):
698+ async def new_drive (self , new_drive_name , location ):
699699 """Create a new drive in the given location.
700-
700+
701701 Args:
702702 new_drive_name: name of new drive to create
703703 location: (optional) region of bucket
704704 """
705+ location = location or 'us-east-1'
706+
705707 try :
706- await self ._file_system ._mkdir (new_drive_name , region_name = location )
708+ # Create a region-specific S3 client for bucket creation
709+ # This ensures the client matches the target region
710+ async with self ._s3_session .create_client (
711+ 's3' ,
712+ aws_secret_access_key = self ._config .secret_access_key ,
713+ aws_access_key_id = self ._config .access_key_id ,
714+ aws_session_token = self ._config .session_token ,
715+ region_name = location
716+ ) as client :
717+ if location == 'us-east-1' :
718+ # For us-east-1, don't specify location constraint
719+ await client .create_bucket (Bucket = new_drive_name )
720+ else :
721+ # For other regions, specify the location constraint
722+ await client .create_bucket (
723+ Bucket = new_drive_name ,
724+ CreateBucketConfiguration = {'LocationConstraint' : location }
725+ )
707726 except Exception as e :
708727 raise tornado .web .HTTPError (
709728 status_code = httpx .codes .BAD_REQUEST ,
710729 reason = f"The following error occured when creating the new drive: { e } " ,
711730 )
712-
731+
713732 return
714733
715734 async def add_public_drive (self , drive_name ):
0 commit comments