Skip to content

Commit d8e3d0a

Browse files
committed
Use boto3 client to create bucket
1 parent 87c06ce commit d8e3d0a

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

jupyter_drives/manager.py

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,9 @@ class JupyterDrivesManager():
4747
It needs them to extract the ``DrivesConfig``.
4848
"""
4949
def __init__(self, config: traitlets.config.Config) -> None:
50+
print("[DEBUG] JupyterDrivesManager.__init__() called11")
5051
self._config = DrivesConfig(config=config)
52+
print("[DEBUG] JupyterDrivesManager.__init__() config loaded", self._config)
5153
self._client = httpx.AsyncClient()
5254
self._content_managers = {}
5355
self._max_files_listed = 1025
@@ -703,9 +705,24 @@ async def new_drive(self, new_drive_name, location):
703705
location: (optional) region of bucket
704706
"""
705707
try:
706-
# AWS returns an error if the region is set to 'us-east-1' (Their default)
707-
region_name = '' if location == 'us-east-1' else location
708-
await self._file_system._mkdir(new_drive_name, region_name)
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 # Use the target region
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+
)
709726
except Exception as e:
710727
raise tornado.web.HTTPError(
711728
status_code= httpx.codes.BAD_REQUEST,

0 commit comments

Comments
 (0)