Skip to content

Commit 4672eb5

Browse files
feat(v2/appconfigdata): refactoring new api calls
1 parent 5046a35 commit 4672eb5

File tree

4 files changed

+222
-55
lines changed

4 files changed

+222
-55
lines changed

aws_lambda_powertools/utilities/parameters/appconfig.py

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from botocore.config import Config
1212

1313
if TYPE_CHECKING:
14-
from mypy_boto3_appconfig import AppConfigClient
14+
from mypy_boto3_appconfigdata import AppConfigDataClient
1515

1616
from ...shared import constants
1717
from ...shared.functions import resolve_env_var_choice
@@ -34,8 +34,8 @@ class AppConfigProvider(BaseProvider):
3434
Botocore configuration to pass during client initialization
3535
boto3_session : boto3.session.Session, optional
3636
Boto3 session to create a boto3_client from
37-
boto3_client: AppConfigClient, optional
38-
Boto3 AppConfig Client to use, boto3_session will be ignored if both are provided
37+
boto3_client: AppConfigDataClient, optional
38+
Boto3 AppConfigData Client to use, boto3_session will be ignored if both are provided
3939
4040
Example
4141
-------
@@ -73,16 +73,16 @@ def __init__(
7373
application: Optional[str] = None,
7474
config: Optional[Config] = None,
7575
boto3_session: Optional[boto3.session.Session] = None,
76-
boto3_client: Optional["AppConfigClient"] = None,
76+
boto3_client: Optional["AppConfigDataClient"] = None,
7777
):
7878
"""
7979
Initialize the App Config client
8080
"""
8181

8282
super().__init__()
8383

84-
self.client: "AppConfigClient" = self._build_boto3_client(
85-
service_name="appconfig", client=boto3_client, session=boto3_session, config=config
84+
self.client: "AppConfigDataClient" = self._build_boto3_client(
85+
service_name="appconfigdata", client=boto3_client, session=boto3_session, config=config
8686
)
8787

8888
self.application = resolve_env_var_choice(
@@ -91,6 +91,10 @@ def __init__(
9191
self.environment = environment
9292
self.current_version = ""
9393

94+
# new appconfidgdata apis
95+
self.api_token = ""
96+
self.last_returned_value = ""
97+
9498
def _get(self, name: str, **sdk_options) -> str:
9599
"""
96100
Retrieve a parameter value from AWS App config.
@@ -102,14 +106,24 @@ def _get(self, name: str, **sdk_options) -> str:
102106
sdk_options: dict, optional
103107
Dictionary of options that will be passed to the client's get_configuration API call
104108
"""
109+
if not self.api_token:
110+
print("TOKEN")
111+
sdk_options["ConfigurationProfileIdentifier"] = name
112+
sdk_options["ApplicationIdentifier"] = self.application
113+
sdk_options["EnvironmentIdentifier"] = self.environment
114+
115+
response_configuration = self.client.start_configuration_session(**sdk_options)
116+
117+
self.api_token = response_configuration["InitialConfigurationToken"]
118+
119+
response = self.client.get_latest_configuration(ConfigurationToken=self.api_token)
120+
return_value = response["Content"].read()
121+
self.api_token = response["NextPollConfigurationToken"]
105122

106-
sdk_options["Configuration"] = name
107-
sdk_options["Application"] = self.application
108-
sdk_options["Environment"] = self.environment
109-
sdk_options["ClientId"] = CLIENT_ID
123+
if return_value:
124+
self.last_returned_value = return_value
110125

111-
response = self.client.get_configuration(**sdk_options)
112-
return response["Content"].read() # read() of botocore.response.StreamingBody
126+
return self.last_returned_value
113127

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

aws_lambda_powertools/utilities/parameters/base.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
from .exceptions import GetParameterError, TransformParameterError
1616

1717
if TYPE_CHECKING:
18-
from mypy_boto3_appconfig import AppConfigClient
18+
from mypy_boto3_appconfigdata import AppConfigDataClient
1919
from mypy_boto3_dynamodb import DynamoDBServiceResource
2020
from mypy_boto3_secretsmanager import SecretsManagerClient
2121
from mypy_boto3_ssm import SSMClient
@@ -28,7 +28,7 @@
2828
TRANSFORM_METHOD_JSON = "json"
2929
TRANSFORM_METHOD_BINARY = "binary"
3030
SUPPORTED_TRANSFORM_METHODS = [TRANSFORM_METHOD_JSON, TRANSFORM_METHOD_BINARY]
31-
ParameterClients = Union["AppConfigClient", "SecretsManagerClient", "SSMClient"]
31+
ParameterClients = Union["AppConfigDataClient", "SecretsManagerClient", "SSMClient"]
3232

3333

3434
class BaseProvider(ABC):

0 commit comments

Comments
 (0)