66import boto3
77import pandas as pd
88
9+ from awswrangler import _utils
910from awswrangler .data_api import connector
1011
1112
@@ -28,6 +29,8 @@ class RedshiftDataApi(connector.DataApiConnector):
2829 Factor by which to increase the sleep between result fetch attempts - defaults to 1.5.
2930 retries: int
3031 Maximum number of result fetch attempts - defaults to 15.
32+ boto3_session : boto3.Session(), optional
33+ The boto3 session. If `None`, the default boto3 session is used.
3134 """
3235
3336 def __init__ (
@@ -39,12 +42,13 @@ def __init__(
3942 sleep : float = 0.25 ,
4043 backoff : float = 1.5 ,
4144 retries : int = 15 ,
45+ boto3_session : Optional [boto3 .Session ] = None ,
4246 ) -> None :
4347 self .cluster_id = cluster_id
4448 self .database = database
4549 self .secret_arn = secret_arn
4650 self .db_user = db_user
47- self .client = boto3 .client ("redshift-data" )
51+ self .client : boto3 . client = _utils .client (service_name = "redshift-data" , session = boto3_session )
4852 self .waiter = RedshiftDataApiWaiter (self .client , sleep , backoff , retries )
4953 logger : logging .Logger = logging .getLogger (__name__ )
5054 super ().__init__ (self .client , logger )
@@ -162,7 +166,14 @@ class RedshiftDataApiTimeoutException(Exception):
162166 """Indicates a statement execution did not complete in the expected wait time."""
163167
164168
165- def connect (cluster_id : str , database : str , secret_arn : str = "" , db_user : str = "" , ** kwargs : Any ) -> RedshiftDataApi :
169+ def connect (
170+ cluster_id : str ,
171+ database : str ,
172+ secret_arn : str = "" ,
173+ db_user : str = "" ,
174+ boto3_session : Optional [boto3 .Session ] = None ,
175+ ** kwargs : Any ,
176+ ) -> RedshiftDataApi :
166177 """Create a Redshift Data API connection.
167178
168179 Parameters
@@ -175,14 +186,18 @@ def connect(cluster_id: str, database: str, secret_arn: str = "", db_user: str =
175186 The ARN for the secret to be used for authentication - only required if `db_user` not provided.
176187 db_user: str
177188 The database user to generate temporary credentials for - only required if `secret_arn` not provided.
189+ boto3_session : boto3.Session(), optional
190+ The boto3 session. If `None`, the default boto3 session is used.
178191 **kwargs
179192 Any additional kwargs are passed to the underlying RedshiftDataApi class.
180193
181194 Returns
182195 -------
183196 A RedshiftDataApi connection instance that can be used with `wr.redshift.data_api.read_sql_query`.
184197 """
185- return RedshiftDataApi (cluster_id , database , secret_arn = secret_arn , db_user = db_user , ** kwargs )
198+ return RedshiftDataApi (
199+ cluster_id , database , secret_arn = secret_arn , db_user = db_user , boto3_session = boto3_session , ** kwargs
200+ )
186201
187202
188203def read_sql_query (sql : str , con : RedshiftDataApi , database : Optional [str ] = None ) -> pd .DataFrame :
0 commit comments