Skip to content

Commit 52d54ab

Browse files
fix(parameter): improve AppConfig cached configuration retrieval (#3195)
* Fixing cache for multiple configurations * Doc * Addressing Heitor's feedback * Adressing Ruben's feedback
1 parent 5bfb60f commit 52d54ab

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

aws_lambda_powertools/utilities/parameters/appconfig.py

+8-3
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,8 @@ def __init__(
9999
self.current_version = ""
100100

101101
self._next_token: Dict[str, str] = {} # nosec - token for get_latest_configuration executions
102-
self.last_returned_value = ""
102+
# Dict to store the recently retrieved value for a specific configuration.
103+
self.last_returned_value: Dict[str, str] = {}
103104

104105
def _get(self, name: str, **sdk_options) -> str:
105106
"""
@@ -126,10 +127,14 @@ def _get(self, name: str, **sdk_options) -> str:
126127
return_value = response["Configuration"].read()
127128
self._next_token[name] = response["NextPollConfigurationToken"]
128129

130+
# The return of get_latest_configuration can be null because this value is supposed to be cached
131+
# on the customer side.
132+
# We created a dictionary that stores the most recently retrieved value for a specific configuration.
133+
# See https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/appconfigdata/client/get_latest_configuration.html
129134
if return_value:
130-
self.last_returned_value = return_value
135+
self.last_returned_value[name] = return_value
131136

132-
return self.last_returned_value
137+
return self.last_returned_value[name]
133138

134139
def _get_multiple(self, path: str, **sdk_options) -> Dict[str, str]:
135140
"""

0 commit comments

Comments
 (0)