Skip to content

Commit f00a6bb

Browse files
authored
Merge pull request #91 from gjmooney/new_bucket_diff_region
Create new bucket in different region
2 parents 916d80a + 506b115 commit f00a6bb

File tree

2 files changed

+24
-5
lines changed

2 files changed

+24
-5
lines changed

jupyter_drives/handlers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ async def post(self, drive: str = "", path: str = ""):
101101
body = self.get_json_body()
102102
if 'location' in body:
103103
result = await self._manager.new_drive(drive, **body)
104-
if 'public' in body:
104+
elif 'public' in body:
105105
result = await self._manager.add_public_drive(drive)
106106
else:
107107
result = await self._manager.new_file(drive, path, **body)

jupyter_drives/manager.py

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)