|
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, |
@@ -453,9 +453,7 @@ def __init__( |
453 | 453 | self._cors = cors |
454 | 454 | self._cors_enabled: bool = cors is not None |
455 | 455 | self._cors_methods: Set[str] = {"OPTIONS"} |
456 | | - self._debug = resolve_truthy_env_var_choice( |
457 | | - env=os.getenv(constants.EVENT_HANDLER_DEBUG_ENV, "false"), choice=debug |
458 | | - ) |
| 456 | + self._debug = self._has_debug(debug) |
459 | 457 | self._strip_prefixes = strip_prefixes |
460 | 458 | self.context: Dict = {} # early init as customers might add context before event resolution |
461 | 459 |
|
@@ -527,6 +525,22 @@ def resolve(self, event, context) -> Dict[str, Any]: |
527 | 525 | def __call__(self, event, context) -> Any: |
528 | 526 | return self.resolve(event, context) |
529 | 527 |
|
| 528 | + @staticmethod |
| 529 | + def _has_debug(debug: Optional[bool] = None) -> bool: |
| 530 | + # It might have been explicitly switched off (debug=False) |
| 531 | + if debug is not None: |
| 532 | + return debug |
| 533 | + |
| 534 | + # Maintenance: deprecate EVENT_HANDLER_DEBUG later in V2. |
| 535 | + env_debug = os.getenv(constants.EVENT_HANDLER_DEBUG_ENV) |
| 536 | + if env_debug is not None: |
| 537 | + warnings.warn( |
| 538 | + "POWERTOOLS_EVENT_HANDLER_DEBUG is set and will be deprecated in V2. Please use POWERTOOLS_DEV instead." |
| 539 | + ) |
| 540 | + return strtobool(env_debug) or powertools_dev_is_set() |
| 541 | + |
| 542 | + return powertools_dev_is_set() |
| 543 | + |
530 | 544 | @staticmethod |
531 | 545 | def _compile_regex(rule: str): |
532 | 546 | """Precompile regex pattern |
|
0 commit comments