From abc84492219705e55c9b1526413f7d3965eb6804 Mon Sep 17 00:00:00 2001 From: hkuepers Date: Mon, 15 Apr 2024 17:01:24 +0200 Subject: [PATCH 1/2] Add tags to dynamodb config Signed-off-by: hkuepers --- sdk/python/feast/infra/online_stores/dynamodb.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/sdk/python/feast/infra/online_stores/dynamodb.py b/sdk/python/feast/infra/online_stores/dynamodb.py index a049189de7f..7aa12f2c0a1 100644 --- a/sdk/python/feast/infra/online_stores/dynamodb.py +++ b/sdk/python/feast/infra/online_stores/dynamodb.py @@ -65,6 +65,9 @@ class DynamoDBOnlineStoreConfig(FeastConfigBaseModel): consistent_reads: StrictBool = False """Whether to read from Dynamodb by forcing consistent reads""" + tags: Union[Dict[str, str], None] = None + """AWS resource tags added to each table""" + class DynamoDBOnlineStore(OnlineStore): """ @@ -114,6 +117,12 @@ def update( {"AttributeName": "entity_id", "AttributeType": "S"} ], BillingMode="PAY_PER_REQUEST", + Tags=[ + {"Key": key, "Value": value} + for key, value in online_config.tags.items() + ] + if online_config.tags is not None + else [], ) except ClientError as ce: # If the table creation fails with ResourceInUseException, From ce328f6165905b80075bd7b9e5ad0e77926e4dc2 Mon Sep 17 00:00:00 2001 From: hkuepers Date: Tue, 16 Apr 2024 16:55:34 +0200 Subject: [PATCH 2/2] Only add tags to dynamodb when configured Signed-off-by: hkuepers --- .../feast/infra/online_stores/dynamodb.py | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/sdk/python/feast/infra/online_stores/dynamodb.py b/sdk/python/feast/infra/online_stores/dynamodb.py index 7aa12f2c0a1..4a74f9e27f3 100644 --- a/sdk/python/feast/infra/online_stores/dynamodb.py +++ b/sdk/python/feast/infra/online_stores/dynamodb.py @@ -107,7 +107,18 @@ def update( dynamodb_resource = self._get_dynamodb_resource( online_config.region, online_config.endpoint_url ) - + # Add Tags attribute to creation request only if configured to prevent + # TagResource permission issues, even with an empty Tags array. + kwargs = ( + { + "Tags": [ + {"Key": key, "Value": value} + for key, value in online_config.tags.items() + ] + } + if online_config.tags + else {} + ) for table_instance in tables_to_keep: try: dynamodb_resource.create_table( @@ -117,12 +128,7 @@ def update( {"AttributeName": "entity_id", "AttributeType": "S"} ], BillingMode="PAY_PER_REQUEST", - Tags=[ - {"Key": key, "Value": value} - for key, value in online_config.tags.items() - ] - if online_config.tags is not None - else [], + **kwargs, ) except ClientError as ce: # If the table creation fails with ResourceInUseException,