From 8cf50bae6fcc4a4d86046887b4e9647a15d18190 Mon Sep 17 00:00:00 2001 From: Leandro Damascena Date: Thu, 12 Oct 2023 18:52:06 +0100 Subject: [PATCH 1/4] Fixing cache for multiple configurations --- aws_lambda_powertools/utilities/parameters/appconfig.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/aws_lambda_powertools/utilities/parameters/appconfig.py b/aws_lambda_powertools/utilities/parameters/appconfig.py index 87c6f5077b2..2edeb343b80 100644 --- a/aws_lambda_powertools/utilities/parameters/appconfig.py +++ b/aws_lambda_powertools/utilities/parameters/appconfig.py @@ -99,7 +99,7 @@ def __init__( self.current_version = "" self._next_token: Dict[str, str] = {} # nosec - token for get_latest_configuration executions - self.last_returned_value = "" + self.last_returned_value: Dict[str, str] = {} def _get(self, name: str, **sdk_options) -> str: """ @@ -126,10 +126,12 @@ def _get(self, name: str, **sdk_options) -> str: return_value = response["Configuration"].read() self._next_token[name] = response["NextPollConfigurationToken"] + # The return of get_latest_configuration can be null because this value is supposed to be cached + # on the customer side. We created a dict with the last returned value for the specific configuration if return_value: - self.last_returned_value = return_value + self.last_returned_value[name] = return_value - return self.last_returned_value + return self.last_returned_value[name] def _get_multiple(self, path: str, **sdk_options) -> Dict[str, str]: """ From bfdc195f9cf629c04ab6ba8ede05789f89bc5c8b Mon Sep 17 00:00:00 2001 From: Leandro Damascena Date: Thu, 12 Oct 2023 19:41:25 +0100 Subject: [PATCH 2/4] Doc --- aws_lambda_powertools/utilities/parameters/appconfig.py | 1 + 1 file changed, 1 insertion(+) diff --git a/aws_lambda_powertools/utilities/parameters/appconfig.py b/aws_lambda_powertools/utilities/parameters/appconfig.py index 2edeb343b80..9d12530b454 100644 --- a/aws_lambda_powertools/utilities/parameters/appconfig.py +++ b/aws_lambda_powertools/utilities/parameters/appconfig.py @@ -128,6 +128,7 @@ def _get(self, name: str, **sdk_options) -> str: # The return of get_latest_configuration can be null because this value is supposed to be cached # on the customer side. We created a dict with the last returned value for the specific configuration + # See https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/appconfigdata/client/get_latest_configuration.html if return_value: self.last_returned_value[name] = return_value From f9043f49078745dcbcd5ee673d72b16ef5796a16 Mon Sep 17 00:00:00 2001 From: Leandro Damascena Date: Fri, 13 Oct 2023 10:57:47 +0100 Subject: [PATCH 3/4] Addressing Heitor's feedback --- aws_lambda_powertools/utilities/parameters/appconfig.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/aws_lambda_powertools/utilities/parameters/appconfig.py b/aws_lambda_powertools/utilities/parameters/appconfig.py index 9d12530b454..629b4283512 100644 --- a/aws_lambda_powertools/utilities/parameters/appconfig.py +++ b/aws_lambda_powertools/utilities/parameters/appconfig.py @@ -99,6 +99,7 @@ def __init__( self.current_version = "" self._next_token: Dict[str, str] = {} # nosec - token for get_latest_configuration executions + # Dict to store the recently retrieved value for a specific configuration. self.last_returned_value: Dict[str, str] = {} def _get(self, name: str, **sdk_options) -> str: @@ -127,7 +128,8 @@ def _get(self, name: str, **sdk_options) -> str: self._next_token[name] = response["NextPollConfigurationToken"] # The return of get_latest_configuration can be null because this value is supposed to be cached - # on the customer side. We created a dict with the last returned value for the specific configuration + # on the customer side. + # We created dict that stores the most recently retrieved value for a specific configuration. # See https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/appconfigdata/client/get_latest_configuration.html if return_value: self.last_returned_value[name] = return_value From 836fa671b2f2d067827a39e02d279eae017da15b Mon Sep 17 00:00:00 2001 From: Leandro Damascena Date: Fri, 13 Oct 2023 11:36:29 +0100 Subject: [PATCH 4/4] Adressing Ruben's feedback --- aws_lambda_powertools/utilities/parameters/appconfig.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aws_lambda_powertools/utilities/parameters/appconfig.py b/aws_lambda_powertools/utilities/parameters/appconfig.py index 629b4283512..d5a9b7856e4 100644 --- a/aws_lambda_powertools/utilities/parameters/appconfig.py +++ b/aws_lambda_powertools/utilities/parameters/appconfig.py @@ -129,7 +129,7 @@ def _get(self, name: str, **sdk_options) -> str: # The return of get_latest_configuration can be null because this value is supposed to be cached # on the customer side. - # We created dict that stores the most recently retrieved value for a specific configuration. + # We created a dictionary that stores the most recently retrieved value for a specific configuration. # See https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/appconfigdata/client/get_latest_configuration.html if return_value: self.last_returned_value[name] = return_value