Skip to content

Commit 08f2b53

Browse files
refactor(parameters): deprecate the config parameter in favor of boto_config (#4893)
* Replacing config with boto_config * Replacing config with boto_config
1 parent 26cfe7f commit 08f2b53

File tree

9 files changed

+196
-71
lines changed

9 files changed

+196
-71
lines changed

Diff for: aws_lambda_powertools/utilities/feature_flags/appconfig.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def __init__(
5858
self.config = sdk_config
5959
self.envelope = envelope
6060
self.jmespath_options = jmespath_options
61-
self._conf_store = AppConfigProvider(environment=environment, application=application, config=sdk_config)
61+
self._conf_store = AppConfigProvider(environment=environment, application=application, boto_config=sdk_config)
6262

6363
@property
6464
def get_raw_configuration(self) -> Dict[str, Any]:

Diff for: aws_lambda_powertools/utilities/parameters/appconfig.py

+16-1
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@
33
"""
44

55
import os
6+
import warnings
67
from typing import TYPE_CHECKING, Dict, Optional, Union
78

89
import boto3
910
from botocore.config import Config
1011

1112
from aws_lambda_powertools.utilities.parameters.types import TransformOptions
13+
from aws_lambda_powertools.warnings import PowertoolsDeprecationWarning
1214

1315
if TYPE_CHECKING:
1416
from mypy_boto3_appconfigdata.client import AppConfigDataClient
@@ -72,15 +74,28 @@ def __init__(
7274
environment: str,
7375
application: Optional[str] = None,
7476
config: Optional[Config] = None,
77+
boto_config: Optional[Config] = None,
7578
boto3_session: Optional[boto3.session.Session] = None,
7679
boto3_client: Optional["AppConfigDataClient"] = None,
7780
):
7881
"""
7982
Initialize the App Config client
8083
"""
84+
85+
super().__init__()
86+
87+
if config:
88+
warnings.warn(
89+
message="The 'config' parameter is deprecated in V3 and will be removed in V4. "
90+
"Please use 'boto_config' instead.",
91+
category=PowertoolsDeprecationWarning,
92+
stacklevel=2,
93+
)
94+
8195
if boto3_client is None:
8296
boto3_session = boto3_session or boto3.session.Session()
83-
boto3_client = boto3_session.client("appconfigdata", config=config)
97+
boto3_client = boto3_session.client("appconfigdata", config=boto_config or config)
98+
8499
self.client = boto3_client
85100

86101
self.application = resolve_env_var_choice(

Diff for: aws_lambda_powertools/utilities/parameters/dynamodb.py

+14-1
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,15 @@
22
Amazon DynamoDB parameter retrieval and caching utility
33
"""
44

5+
import warnings
56
from typing import TYPE_CHECKING, Dict, Optional
67

78
import boto3
89
from boto3.dynamodb.conditions import Key
910
from botocore.config import Config
1011

12+
from aws_lambda_powertools.warnings import PowertoolsDeprecationWarning
13+
1114
from .base import BaseProvider
1215

1316
if TYPE_CHECKING:
@@ -155,15 +158,25 @@ def __init__(
155158
value_attr: str = "value",
156159
endpoint_url: Optional[str] = None,
157160
config: Optional[Config] = None,
161+
boto_config: Optional[Config] = None,
158162
boto3_session: Optional[boto3.session.Session] = None,
159163
boto3_client: Optional["DynamoDBServiceResource"] = None,
160164
):
161165
"""
162166
Initialize the DynamoDB client
163167
"""
168+
if config:
169+
warnings.warn(
170+
message="The 'config' parameter is deprecated in V3 and will be removed in V4. "
171+
"Please use 'boto_config' instead.",
172+
category=PowertoolsDeprecationWarning,
173+
stacklevel=2,
174+
)
175+
164176
if boto3_client is None:
165177
boto3_session = boto3_session or boto3.session.Session()
166-
boto3_client = boto3_session.resource("dynamodb", config=config, endpoint_url=endpoint_url)
178+
boto3_client = boto3_session.resource("dynamodb", config=boto_config or config, endpoint_url=endpoint_url)
179+
167180
self.table = boto3_client.Table(table_name)
168181
self.key_attr = key_attr
169182
self.sort_attr = sort_attr

Diff for: aws_lambda_powertools/utilities/parameters/secrets.py

+13-1
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,14 @@
77
import json
88
import logging
99
import os
10+
import warnings
1011
from typing import TYPE_CHECKING, Dict, Literal, Optional, Union, overload
1112

1213
import boto3
1314
from botocore.config import Config
1415

16+
from aws_lambda_powertools.warnings import PowertoolsDeprecationWarning
17+
1518
if TYPE_CHECKING:
1619
from mypy_boto3_secretsmanager.client import SecretsManagerClient
1720
from mypy_boto3_secretsmanager.type_defs import CreateSecretResponseTypeDef
@@ -78,15 +81,24 @@ class SecretsProvider(BaseProvider):
7881
def __init__(
7982
self,
8083
config: Optional[Config] = None,
84+
boto_config: Optional[Config] = None,
8185
boto3_session: Optional[boto3.session.Session] = None,
8286
boto3_client: Optional[SecretsManagerClient] = None,
8387
):
8488
"""
8589
Initialize the Secrets Manager client
8690
"""
91+
if config:
92+
warnings.warn(
93+
message="The 'config' parameter is deprecated in V3 and will be removed in V4. "
94+
"Please use 'boto_config' instead.",
95+
category=PowertoolsDeprecationWarning,
96+
stacklevel=2,
97+
)
98+
8799
if boto3_client is None:
88100
boto3_session = boto3_session or boto3.session.Session()
89-
boto3_client = boto3_session.client("secretsmanager", config=config)
101+
boto3_client = boto3_session.client("secretsmanager", config=boto_config or config)
90102
self.client = boto3_client
91103

92104
super().__init__(client=self.client)

Diff for: aws_lambda_powertools/utilities/parameters/ssm.py

+12-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
import logging
88
import os
9+
import warnings
910
from typing import TYPE_CHECKING, Any, Dict, List, Optional, Tuple, Union, overload
1011

1112
import boto3
@@ -26,6 +27,7 @@
2627
)
2728
from aws_lambda_powertools.utilities.parameters.exceptions import GetParameterError, SetParameterError
2829
from aws_lambda_powertools.utilities.parameters.types import TransformOptions
30+
from aws_lambda_powertools.warnings import PowertoolsDeprecationWarning
2931

3032
if TYPE_CHECKING:
3133
from mypy_boto3_ssm.client import SSMClient
@@ -108,15 +110,24 @@ class SSMProvider(BaseProvider):
108110
def __init__(
109111
self,
110112
config: Optional[Config] = None,
113+
boto_config: Optional[Config] = None,
111114
boto3_session: Optional[boto3.session.Session] = None,
112115
boto3_client: Optional[SSMClient] = None,
113116
):
114117
"""
115118
Initialize the SSM Parameter Store client
116119
"""
120+
if config:
121+
warnings.warn(
122+
message="The 'config' parameter is deprecated in V3 and will be removed in V4. "
123+
"Please use 'boto_config' instead.",
124+
category=PowertoolsDeprecationWarning,
125+
stacklevel=2,
126+
)
127+
117128
if boto3_client is None:
118129
boto3_session = boto3_session or boto3.session.Session()
119-
boto3_client = boto3_session.client("ssm", config=config)
130+
boto3_client = boto3_session.client("ssm", config=boto_config or config)
120131
self.client = boto3_client
121132

122133
super().__init__(client=self.client)

Diff for: aws_lambda_powertools/warnings/__init__.py

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
"""Shared warnings that don't belong to a single utility"""
2+
3+
4+
class PowertoolsUserWarning(UserWarning):
5+
"""
6+
This class provides a custom Warning tailored for better clarity when certain situations occur.
7+
8+
Examples:
9+
- Using development-only features in production environment.
10+
- Potential performance or security issues due to misconfiguration.
11+
12+
Parameters
13+
----------
14+
message: str
15+
The warning message to be displayed.
16+
"""
17+
18+
def __init__(self, message):
19+
self.message = message
20+
super().__init__(message)
21+
22+
def __str__(self):
23+
return self.message
24+
25+
26+
class PowertoolsDeprecationWarning(DeprecationWarning):
27+
"""
28+
This class provides a DeprecationWarning custom Warning for utilities/parameters deprecated in v3.
29+
30+
Examples:
31+
- Using development-only features in production environment.
32+
- Potential performance or security issues due to misconfiguration.
33+
34+
Parameters
35+
----------
36+
message: str
37+
The warning message to be displayed.
38+
"""
39+
40+
def __init__(self, message):
41+
self.message = message
42+
super().__init__(message)
43+
44+
def __str__(self):
45+
return self.message

Diff for: docs/utilities/parameters.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,7 @@ Bringing them together in a single code snippet would look like this:
473473

474474
### Customizing boto configuration
475475

476-
The **`config`** , **`boto3_session`**, and **`boto3_client`** parameters enable you to pass in a custom [botocore config object](https://botocore.amazonaws.com/v1/documentation/api/latest/reference/config.html){target="_blank"}, [boto3 session](https://boto3.amazonaws.com/v1/documentation/api/latest/reference/core/session.html){target="_blank"}, or a [boto3 client](https://boto3.amazonaws.com/v1/documentation/api/latest/reference/core/boto3.html){target="_blank"} when constructing any of the built-in provider classes.
476+
The **`boto_config`** , **`boto3_session`**, and **`boto3_client`** parameters enable you to pass in a custom [botocore config object](https://botocore.amazonaws.com/v1/documentation/api/latest/reference/config.html){target="_blank"}, [boto3 session](https://boto3.amazonaws.com/v1/documentation/api/latest/reference/core/session.html){target="_blank"}, or a [boto3 client](https://boto3.amazonaws.com/v1/documentation/api/latest/reference/core/boto3.html){target="_blank"} when constructing any of the built-in provider classes.
477477

478478
???+ tip
479479
You can use a custom session for retrieving parameters cross-account/region and for snapshot testing.

Diff for: examples/parameters/src/custom_boto_config.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from aws_lambda_powertools.utilities import parameters
44

55
boto_config = Config()
6-
ssm_provider = parameters.SSMProvider(config=boto_config)
6+
ssm_provider = parameters.SSMProvider(boto_config=boto_config)
77

88

99
def handler(event, context):

0 commit comments

Comments
 (0)