@@ -70,6 +70,9 @@ class DynamoDBOnlineStoreConfig(FeastConfigBaseModel):
7070 tags : Union [Dict [str , str ], None ] = None
7171 """AWS resource tags added to each table"""
7272
73+ session_based_auth : bool = False
74+ """AWS session based client authentication"""
75+
7376
7477class DynamoDBOnlineStore (OnlineStore ):
7578 """
@@ -104,10 +107,14 @@ def update(
104107 online_config = config .online_store
105108 assert isinstance (online_config , DynamoDBOnlineStoreConfig )
106109 dynamodb_client = self ._get_dynamodb_client (
107- online_config .region , online_config .endpoint_url
110+ online_config .region ,
111+ online_config .endpoint_url ,
112+ online_config .session_based_auth ,
108113 )
109114 dynamodb_resource = self ._get_dynamodb_resource (
110- online_config .region , online_config .endpoint_url
115+ online_config .region ,
116+ online_config .endpoint_url ,
117+ online_config .session_based_auth ,
111118 )
112119 # Add Tags attribute to creation request only if configured to prevent
113120 # TagResource permission issues, even with an empty Tags array.
@@ -166,7 +173,9 @@ def teardown(
166173 online_config = config .online_store
167174 assert isinstance (online_config , DynamoDBOnlineStoreConfig )
168175 dynamodb_resource = self ._get_dynamodb_resource (
169- online_config .region , online_config .endpoint_url
176+ online_config .region ,
177+ online_config .endpoint_url ,
178+ online_config .session_based_auth ,
170179 )
171180
172181 for table in tables :
@@ -201,7 +210,9 @@ def online_write_batch(
201210 online_config = config .online_store
202211 assert isinstance (online_config , DynamoDBOnlineStoreConfig )
203212 dynamodb_resource = self ._get_dynamodb_resource (
204- online_config .region , online_config .endpoint_url
213+ online_config .region ,
214+ online_config .endpoint_url ,
215+ online_config .session_based_auth ,
205216 )
206217
207218 table_instance = dynamodb_resource .Table (
@@ -228,7 +239,9 @@ def online_read(
228239 assert isinstance (online_config , DynamoDBOnlineStoreConfig )
229240
230241 dynamodb_resource = self ._get_dynamodb_resource (
231- online_config .region , online_config .endpoint_url
242+ online_config .region ,
243+ online_config .endpoint_url ,
244+ online_config .session_based_auth ,
232245 )
233246 table_instance = dynamodb_resource .Table (
234247 _get_table_name (online_config , config , table )
@@ -323,15 +336,27 @@ def _get_aioboto_session(self):
323336 def _get_aiodynamodb_client (self , region : str ):
324337 return self ._get_aioboto_session ().create_client ("dynamodb" , region_name = region )
325338
326- def _get_dynamodb_client (self , region : str , endpoint_url : Optional [str ] = None ):
339+ def _get_dynamodb_client (
340+ self ,
341+ region : str ,
342+ endpoint_url : Optional [str ] = None ,
343+ session_based_auth : Optional [bool ] = False ,
344+ ):
327345 if self ._dynamodb_client is None :
328- self ._dynamodb_client = _initialize_dynamodb_client (region , endpoint_url )
346+ self ._dynamodb_client = _initialize_dynamodb_client (
347+ region , endpoint_url , session_based_auth
348+ )
329349 return self ._dynamodb_client
330350
331- def _get_dynamodb_resource (self , region : str , endpoint_url : Optional [str ] = None ):
351+ def _get_dynamodb_resource (
352+ self ,
353+ region : str ,
354+ endpoint_url : Optional [str ] = None ,
355+ session_based_auth : Optional [bool ] = False ,
356+ ):
332357 if self ._dynamodb_resource is None :
333358 self ._dynamodb_resource = _initialize_dynamodb_resource (
334- region , endpoint_url
359+ region , endpoint_url , session_based_auth
335360 )
336361 return self ._dynamodb_resource
337362
@@ -443,17 +468,38 @@ def _to_client_batch_get_payload(online_config, table_name, batch):
443468 }
444469
445470
446- def _initialize_dynamodb_client (region : str , endpoint_url : Optional [str ] = None ):
447- return boto3 .client (
448- "dynamodb" ,
449- region_name = region ,
450- endpoint_url = endpoint_url ,
451- config = Config (user_agent = get_user_agent ()),
452- )
471+ def _initialize_dynamodb_client (
472+ region : str ,
473+ endpoint_url : Optional [str ] = None ,
474+ session_based_auth : Optional [bool ] = False ,
475+ ):
476+ if session_based_auth :
477+ return boto3 .Session ().client (
478+ "dynamodb" ,
479+ region_name = region ,
480+ endpoint_url = endpoint_url ,
481+ config = Config (user_agent = get_user_agent ()),
482+ )
483+ else :
484+ return boto3 .client (
485+ "dynamodb" ,
486+ region_name = region ,
487+ endpoint_url = endpoint_url ,
488+ config = Config (user_agent = get_user_agent ()),
489+ )
453490
454491
455- def _initialize_dynamodb_resource (region : str , endpoint_url : Optional [str ] = None ):
456- return boto3 .resource ("dynamodb" , region_name = region , endpoint_url = endpoint_url )
492+ def _initialize_dynamodb_resource (
493+ region : str ,
494+ endpoint_url : Optional [str ] = None ,
495+ session_based_auth : Optional [bool ] = False ,
496+ ):
497+ if session_based_auth :
498+ return boto3 .Session ().resource (
499+ "dynamodb" , region_name = region , endpoint_url = endpoint_url
500+ )
501+ else :
502+ return boto3 .resource ("dynamodb" , region_name = region , endpoint_url = endpoint_url )
457503
458504
459505# TODO(achals): This form of user-facing templating is experimental.
0 commit comments