1616from libcloud .storage .types import Provider
1717from libcloud .storage .providers import get_driver
1818import pyarrow
19- import boto3
19+ from aiobotocore . session import get_session
2020
2121from .log import get_logger
2222from .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 ,
0 commit comments