@@ -698,21 +698,40 @@ async def check_file(self, drive_name, path):
698698
699699 return
700700
701- async def new_drive (self , new_drive_name , location = 'us-east-1' ):
701+ async def new_drive (self , new_drive_name , location ):
702702 """Create a new drive in the given location.
703-
703+
704704 Args:
705705 new_drive_name: name of new drive to create
706706 location: (optional) region of bucket
707707 """
708+ location = location or 'us-east-1'
709+
708710 try :
709- await self ._file_system ._mkdir (new_drive_name , region_name = location )
711+ # Create a region-specific S3 client for bucket creation
712+ # This ensures the client matches the target region
713+ async with self ._s3_session .create_client (
714+ 's3' ,
715+ aws_secret_access_key = self ._config .secret_access_key ,
716+ aws_access_key_id = self ._config .access_key_id ,
717+ aws_session_token = self ._config .session_token ,
718+ region_name = location
719+ ) as client :
720+ if location == 'us-east-1' :
721+ # For us-east-1, don't specify location constraint
722+ await client .create_bucket (Bucket = new_drive_name )
723+ else :
724+ # For other regions, specify the location constraint
725+ await client .create_bucket (
726+ Bucket = new_drive_name ,
727+ CreateBucketConfiguration = {'LocationConstraint' : location }
728+ )
710729 except Exception as e :
711730 raise tornado .web .HTTPError (
712731 status_code = httpx .codes .BAD_REQUEST ,
713732 reason = f"The following error occured when creating the new drive: { e } " ,
714733 )
715-
734+
716735 return
717736
718737 async def add_external_drive (self , drive_name , is_public , region = 'us-east-1' ):
0 commit comments