Skip to content

Commit 3a56547

Browse files
authored
Merge pull request #49 from DenisaCG/asyncLocation
Switch to async logic for region extraction
2 parents c7a824f + 1978c37 commit 3a56547

File tree

3 files changed

+11
-15
lines changed

3 files changed

+11
-15
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ jobs:
4242
4343
jupyter labextension list
4444
jupyter labextension list 2>&1 | grep -ie "jupyter-drives.*OK"
45-
python -m jupyterlab.browser_check
45+
python -m jupyterlab.browser_check --no-chrome-test
4646
4747
- name: Package the extension
4848
run: |

jupyter_drives/manager.py

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
from libcloud.storage.types import Provider
1717
from libcloud.storage.providers import get_driver
1818
import pyarrow
19-
import boto3
19+
from aiobotocore.session import get_session
2020

2121
from .log import get_logger
2222
from .base import DrivesConfig
@@ -42,14 +42,11 @@ def __init__(self, config: traitlets.config.Config) -> None:
4242
self._content_managers = {}
4343
self._max_files_listed = 1000
4444

45-
# initiate boto3 session if we are dealing with S3 drives
45+
# initiate aiobotocore session if we are dealing with S3 drives
4646
if self._config.provider == 's3':
47-
self._s3_clients = {}
4847
if self._config.access_key_id and self._config.secret_access_key:
49-
if self._config.session_token is None:
50-
self._s3_session = boto3.Session(aws_access_key_id = self._config.access_key_id, aws_secret_access_key = self._config.secret_access_key)
51-
else:
52-
self._s3_session = boto3.Session(aws_access_key_id = self._config.access_key_id, aws_secret_access_key = self._config.secret_access_key, aws_session_token = self._config.session_token)
48+
self._s3_clients = {}
49+
self._s3_session = get_session()
5350
else:
5451
raise tornado.web.HTTPError(
5552
status_code= httpx.codes.BAD_REQUEST,
@@ -149,7 +146,7 @@ async def mount_drive(self, drive_name, provider):
149146
if drive_name not in self._content_managers or self._content_managers[drive_name] is None:
150147
if provider == 's3':
151148
# get region of drive
152-
region = self._get_drive_location(drive_name)
149+
region = await self._get_drive_location(drive_name)
153150
if self._config.session_token is None:
154151
configuration = {
155152
"aws_access_key_id": self._config.access_key_id,
@@ -555,7 +552,7 @@ async def presigned_link(self, drive_name, path):
555552
}
556553
return response
557554

558-
def _get_drive_location(self, drive_name):
555+
async def _get_drive_location(self, drive_name):
559556
"""Helping function for getting drive region.
560557
561558
Args:
@@ -564,10 +561,9 @@ def _get_drive_location(self, drive_name):
564561
location = 'eu-north-1'
565562
try:
566563
# set temporary client for location extraction
567-
s3 = self._s3_session.client('s3')
568-
result = s3.get_bucket_location(Bucket = drive_name)
569-
570-
location = result['LocationConstraint']
564+
async with self._s3_session.create_client('s3', aws_secret_access_key=self._config.secret_access_key, aws_access_key_id=self._config.access_key_id, aws_session_token=self._config.session_token) as client:
565+
result = await client.get_bucket_location(Bucket=drive_name)
566+
location = result['LocationConstraint']
571567
except Exception as e:
572568
raise tornado.web.HTTPError(
573569
status_code= httpx.codes.BAD_REQUEST,

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ dependencies = [
2525
"obstore>=0.3.0b,<0.4",
2626
"arro3-core>=0.2.1,<0.3",
2727
"pyarrow>=18.0.0,<19.0.0",
28+
"aiobotocore>=2.15.2,<2.16.0",
2829
"jupyter_server>=2.14.2,<3",
29-
"s3contents>=0.11.1,<0.12.0",
3030
"apache-libcloud>=3.8.0, <4",
3131
"entrypoints>=0.4, <0.5",
3232
"httpx>=0.25.1, <0.26"

0 commit comments

Comments
 (0)