Skip to content

refactor(parameters): deprecate the config parameter in favor of boto_config #4893

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 6, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion aws_lambda_powertools/utilities/feature_flags/appconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def __init__(
self.config = sdk_config
self.envelope = envelope
self.jmespath_options = jmespath_options
self._conf_store = AppConfigProvider(environment=environment, application=application, config=sdk_config)
self._conf_store = AppConfigProvider(environment=environment, application=application, boto_config=sdk_config)

@property
def get_raw_configuration(self) -> Dict[str, Any]:
Expand Down
13 changes: 12 additions & 1 deletion aws_lambda_powertools/utilities/parameters/appconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
"""

import os
import warnings
from typing import TYPE_CHECKING, Any, Dict, Optional, Union

import boto3
from botocore.config import Config

from aws_lambda_powertools.utilities.parameters.types import TransformOptions
from aws_lambda_powertools.warnings import PowertoolsDeprecationWarning

if TYPE_CHECKING:
from mypy_boto3_appconfigdata import AppConfigDataClient
Expand Down Expand Up @@ -74,6 +76,7 @@ def __init__(
environment: str,
application: Optional[str] = None,
config: Optional[Config] = None,
boto_config: Optional[Config] = None,
boto3_session: Optional[boto3.session.Session] = None,
boto3_client: Optional["AppConfigDataClient"] = None,
):
Expand All @@ -83,11 +86,19 @@ def __init__(

super().__init__()

if config:
warnings.warn(
message="The 'config' parameter is deprecated in V3 and will be removed in V4. "
"Please use 'boto_config' instead.",
category=PowertoolsDeprecationWarning,
stacklevel=2,
)

self.client: "AppConfigDataClient" = self._build_boto3_client(
service_name="appconfigdata",
client=boto3_client,
session=boto3_session,
config=config,
config=boto_config or config,
)

self.application = resolve_env_var_choice(
Expand Down
14 changes: 13 additions & 1 deletion aws_lambda_powertools/utilities/parameters/dynamodb.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@
Amazon DynamoDB parameter retrieval and caching utility
"""

import warnings
from typing import TYPE_CHECKING, Dict, Optional

import boto3
from boto3.dynamodb.conditions import Key
from botocore.config import Config

from aws_lambda_powertools.warnings import PowertoolsDeprecationWarning

from .base import BaseProvider

if TYPE_CHECKING:
Expand Down Expand Up @@ -156,17 +159,26 @@ def __init__(
value_attr: str = "value",
endpoint_url: Optional[str] = None,
config: Optional[Config] = None,
boto_config: Optional[Config] = None,
boto3_session: Optional[boto3.session.Session] = None,
boto3_client: Optional["DynamoDBServiceResource"] = None,
):
"""
Initialize the DynamoDB client
"""
if config:
warnings.warn(
message="The 'config' parameter is deprecated in V3 and will be removed in V4. "
"Please use 'boto_config' instead.",
category=PowertoolsDeprecationWarning,
stacklevel=2,
)

self.table: "Table" = self._build_boto3_resource_client(
service_name="dynamodb",
client=boto3_client,
session=boto3_session,
config=config,
config=boto_config or config,
endpoint_url=endpoint_url,
).Table(table_name)

Expand Down
14 changes: 13 additions & 1 deletion aws_lambda_powertools/utilities/parameters/secrets.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,14 @@
import json
import logging
import os
import warnings
from typing import TYPE_CHECKING, Any, Dict, Literal, Optional, Union, overload

import boto3
from botocore.config import Config

from aws_lambda_powertools.warnings import PowertoolsDeprecationWarning

if TYPE_CHECKING:
from mypy_boto3_secretsmanager import SecretsManagerClient

Expand Down Expand Up @@ -79,6 +82,7 @@ class SecretsProvider(BaseProvider):
def __init__(
self,
config: Optional[Config] = None,
boto_config: Optional[Config] = None,
boto3_session: Optional[boto3.session.Session] = None,
boto3_client: Optional["SecretsManagerClient"] = None,
):
Expand All @@ -88,11 +92,19 @@ def __init__(

super().__init__()

if config:
warnings.warn(
message="The 'config' parameter is deprecated in V3 and will be removed in V4. "
"Please use 'boto_config' instead.",
category=PowertoolsDeprecationWarning,
stacklevel=2,
)

self.client: "SecretsManagerClient" = self._build_boto3_client(
service_name="secretsmanager",
client=boto3_client,
session=boto3_session,
config=config,
config=boto_config or config,
)

def _get(self, name: str, **sdk_options) -> str:
Expand Down
13 changes: 12 additions & 1 deletion aws_lambda_powertools/utilities/parameters/ssm.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import logging
import os
import warnings
from typing import TYPE_CHECKING, Any, Dict, List, Optional, Tuple, Union, overload

import boto3
Expand All @@ -26,6 +27,7 @@
)
from aws_lambda_powertools.utilities.parameters.exceptions import GetParameterError, SetParameterError
from aws_lambda_powertools.utilities.parameters.types import PutParameterResponse, TransformOptions
from aws_lambda_powertools.warnings import PowertoolsDeprecationWarning

if TYPE_CHECKING:
from mypy_boto3_ssm import SSMClient
Expand Down Expand Up @@ -109,6 +111,7 @@ class SSMProvider(BaseProvider):
def __init__(
self,
config: Optional[Config] = None,
boto_config: Optional[Config] = None,
boto3_session: Optional[boto3.session.Session] = None,
boto3_client: Optional["SSMClient"] = None,
):
Expand All @@ -118,11 +121,19 @@ def __init__(

super().__init__()

if config:
warnings.warn(
message="The 'config' parameter is deprecated in V3 and will be removed in V4. "
"Please use 'boto_config' instead.",
category=PowertoolsDeprecationWarning,
stacklevel=2,
)

self.client: "SSMClient" = self._build_boto3_client(
service_name="ssm",
client=boto3_client,
session=boto3_session,
config=config,
config=boto_config or config,
)

def get_multiple( # type: ignore[override]
Expand Down
45 changes: 45 additions & 0 deletions aws_lambda_powertools/warnings/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
"""Shared warnings that don't belong to a single utility"""


class PowertoolsUserWarning(UserWarning):
"""
This class provides a custom Warning tailored for better clarity when certain situations occur.

Examples:
- Using development-only features in production environment.
- Potential performance or security issues due to misconfiguration.

Parameters
----------
message: str
The warning message to be displayed.
"""

def __init__(self, message):
self.message = message
super().__init__(message)

def __str__(self):
return self.message


class PowertoolsDeprecationWarning(DeprecationWarning):
"""
This class provides a DeprecationWarning custom Warning for utilities/parameters deprecated in v3.

Examples:
- Using development-only features in production environment.
- Potential performance or security issues due to misconfiguration.

Parameters
----------
message: str
The warning message to be displayed.
"""

def __init__(self, message):
self.message = message
super().__init__(message)

def __str__(self):
return self.message
2 changes: 1 addition & 1 deletion docs/utilities/parameters.md
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ Bringing them together in a single code snippet would look like this:

### Customizing boto configuration

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.
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.

???+ tip
You can use a custom session for retrieving parameters cross-account/region and for snapshot testing.
Expand Down
2 changes: 1 addition & 1 deletion examples/parameters/src/custom_boto_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from aws_lambda_powertools.utilities import parameters

boto_config = Config()
ssm_provider = parameters.SSMProvider(config=boto_config)
ssm_provider = parameters.SSMProvider(boto_config=boto_config)


def handler(event, context):
Expand Down
Loading
Loading