|
15 | 15 | from aws_lambda_powertools.event_handler import content_types
|
16 | 16 | from aws_lambda_powertools.event_handler.exceptions import NotFoundError, ServiceError
|
17 | 17 | from aws_lambda_powertools.shared import constants
|
18 |
| -from aws_lambda_powertools.shared.functions import resolve_truthy_env_var_choice |
| 18 | +from aws_lambda_powertools.shared.functions import powertools_dev_is_set, strtobool |
19 | 19 | from aws_lambda_powertools.shared.json_encoder import Encoder
|
20 | 20 | from aws_lambda_powertools.utilities.data_classes import (
|
21 | 21 | ALBEvent,
|
@@ -444,9 +444,7 @@ def __init__(
|
444 | 444 | self._cors = cors
|
445 | 445 | self._cors_enabled: bool = cors is not None
|
446 | 446 | self._cors_methods: Set[str] = {"OPTIONS"}
|
447 |
| - self._debug = resolve_truthy_env_var_choice( |
448 |
| - env=os.getenv(constants.EVENT_HANDLER_DEBUG_ENV, "false"), choice=debug |
449 |
| - ) |
| 447 | + self._debug = self._has_debug(debug) |
450 | 448 | self._strip_prefixes = strip_prefixes
|
451 | 449 |
|
452 | 450 | # Allow for a custom serializer or a concise json serialization
|
@@ -511,6 +509,22 @@ def resolve(self, event, context) -> Dict[str, Any]:
|
511 | 509 | def __call__(self, event, context) -> Any:
|
512 | 510 | return self.resolve(event, context)
|
513 | 511 |
|
| 512 | + @staticmethod |
| 513 | + def _has_debug(debug: Optional[bool] = None) -> bool: |
| 514 | + # It might have been explicitly switched off (debug=False) |
| 515 | + if debug is not None: |
| 516 | + return debug |
| 517 | + |
| 518 | + # Maintenance: deprecate EVENT_HANDLER_DEBUG later in V2. |
| 519 | + env_debug = os.getenv(constants.EVENT_HANDLER_DEBUG_ENV) |
| 520 | + if env_debug is not None: |
| 521 | + warnings.warn( |
| 522 | + "POWERTOOLS_EVENT_HANDLER_DEBUG is set and will be deprecated in V2. Please use POWERTOOLS_DEV instead." |
| 523 | + ) |
| 524 | + return strtobool(env_debug) or powertools_dev_is_set() |
| 525 | + |
| 526 | + return powertools_dev_is_set() |
| 527 | + |
514 | 528 | @staticmethod
|
515 | 529 | def _compile_regex(rule: str):
|
516 | 530 | """Precompile regex pattern
|
|
0 commit comments