Skip to content

refactor(apigateway): remove POWERTOOLS_EVENT_HANDLER_DEBUG env var #1620

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
Show file tree
Hide file tree
Changes from all 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
14 changes: 2 additions & 12 deletions aws_lambda_powertools/event_handler/api_gateway.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import base64
import json
import logging
import os
import re
import traceback
import warnings
Expand All @@ -26,9 +25,8 @@

from aws_lambda_powertools.event_handler import content_types
from aws_lambda_powertools.event_handler.exceptions import NotFoundError, ServiceError
from aws_lambda_powertools.shared import constants
from aws_lambda_powertools.shared.cookies import Cookie
from aws_lambda_powertools.shared.functions import powertools_dev_is_set, strtobool
from aws_lambda_powertools.shared.functions import powertools_dev_is_set
from aws_lambda_powertools.shared.json_encoder import Encoder
from aws_lambda_powertools.utilities.data_classes import (
ALBEvent,
Expand Down Expand Up @@ -459,7 +457,7 @@ def __init__(
cors: CORSConfig
Optionally configure and enabled CORS. Not each route will need to have to cors=True
debug: Optional[bool]
Enables debug mode, by default False. Can be also be enabled by "POWERTOOLS_EVENT_HANDLER_DEBUG"
Enables debug mode, by default False. Can be also be enabled by "POWERTOOLS_DEV"
environment variable
serializer : Callable, optional
function to serialize `obj` to a JSON formatted `str`, by default json.dumps
Expand Down Expand Up @@ -552,14 +550,6 @@ def _has_debug(debug: Optional[bool] = None) -> bool:
if debug is not None:
return debug

# Maintenance: deprecate EVENT_HANDLER_DEBUG later in V2.
env_debug = os.getenv(constants.EVENT_HANDLER_DEBUG_ENV)
if env_debug is not None:
warnings.warn(
"POWERTOOLS_EVENT_HANDLER_DEBUG is set and will be deprecated in V2. Please use POWERTOOLS_DEV instead."
)
return strtobool(env_debug) or powertools_dev_is_set()

return powertools_dev_is_set()

@staticmethod
Expand Down
2 changes: 0 additions & 2 deletions aws_lambda_powertools/shared/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@

METRICS_NAMESPACE_ENV: str = "POWERTOOLS_METRICS_NAMESPACE"

EVENT_HANDLER_DEBUG_ENV: str = "POWERTOOLS_EVENT_HANDLER_DEBUG"

SERVICE_NAME_ENV: str = "POWERTOOLS_SERVICE_NAME"
XRAY_TRACE_ID_ENV: str = "_X_AMZN_TRACE_ID"
LAMBDA_TASK_ROOT_ENV: str = "LAMBDA_TASK_ROOT"
Expand Down
21 changes: 10 additions & 11 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ You can include Lambda Powertools Lambda Layer using [AWS Lambda Console](https:

=== "x86_64"

| Region | Layer ARN |
| ---------------- | -------------------------------------------------------------------------------------------------------- |
| Region | Layer ARN |
| ---------------- | --------------------------------------------------------------------------------------------------------- |
| `af-south-1` | [arn:aws:lambda:af-south-1:017000801446:layer:AWSLambdaPowertoolsPythonV2:1](#){: .copyMe}:clipboard: |
| `ap-east-1` | [arn:aws:lambda:ap-east-1:017000801446:layer:AWSLambdaPowertoolsPythonV2:1](#){: .copyMe}:clipboard: |
| `ap-northeast-1` | [arn:aws:lambda:ap-northeast-1:017000801446:layer:AWSLambdaPowertoolsPythonV2:1](#){: .copyMe}:clipboard: |
Expand All @@ -81,8 +81,8 @@ You can include Lambda Powertools Lambda Layer using [AWS Lambda Console](https:

=== "arm64"

| Region | Layer ARN |
| ---------------- | -------------------------------------------------------------------------------------------------------- |
| Region | Layer ARN |
| ---------------- | --------------------------------------------------------------------------------------------------------------- |
| `af-south-1` | [arn:aws:lambda:af-south-1:017000801446:layer:AWSLambdaPowertoolsPythonV2-Arm64:1](#){: .copyMe}:clipboard: |
| `ap-east-1` | [arn:aws:lambda:ap-east-1:017000801446:layer:AWSLambdaPowertoolsPythonV2-Arm64:1](#){: .copyMe}:clipboard: |
| `ap-northeast-1` | [arn:aws:lambda:ap-northeast-1:017000801446:layer:AWSLambdaPowertoolsPythonV2-Arm64:1](#){: .copyMe}:clipboard: |
Expand Down Expand Up @@ -377,7 +377,7 @@ Serverless Application Repository (SAR) App deploys a CloudFormation stack with
Despite having more steps compared to the [public Layer ARN](#lambda-layer) option, the benefit is that you can specify a semantic version you want to use.

| App | ARN | Description |
|----------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------|
| -------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------- |
| [aws-lambda-powertools-python-layer-v2](https://serverlessrepo.aws.amazon.com/applications/eu-west-1/057560766410/aws-lambda-powertools-python-layer-v2) | [arn:aws:serverlessrepo:eu-west-1:057560766410:applications/aws-lambda-powertools-python-layer-v2](#){: .copyMe}:clipboard: | Contains all extra dependencies (e.g: pydantic). |
| [aws-lambda-powertools-python-layer-v2-arm64](https://serverlessrepo.aws.amazon.com/applications/eu-west-1/057560766410/aws-lambda-powertools-python-layer-v2-arm64) | [arn:aws:serverlessrepo:eu-west-1:057560766410:applications/aws-lambda-powertools-python-layer-v2-arm64](#){: .copyMe}:clipboard: | Contains all extra dependencies (e.g: pydantic). For arm64 functions. |

Expand Down Expand Up @@ -625,7 +625,6 @@ Core utilities such as Tracing, Logging, Metrics, and Event Handler will be avai
| **POWERTOOLS_LOGGER_LOG_EVENT** | Logs incoming event | [Logging](./core/logger) | `false` |
| **POWERTOOLS_LOGGER_SAMPLE_RATE** | Debug log sampling | [Logging](./core/logger) | `0` |
| **POWERTOOLS_LOG_DEDUPLICATION_DISABLED** | Disables log deduplication filter protection to use Pytest Live Log feature | [Logging](./core/logger) | `false` |
| **POWERTOOLS_EVENT_HANDLER_DEBUG** | Enables debugging mode for event handler | [Event Handler](./core/event_handler/api_gateway.md#debug-mode) | `false` |
| **POWERTOOLS_DEV** | Increases verbosity across utilities | Multiple; see [POWERTOOLS_DEV effect below](#increasing-verbosity-across-utilities) | `0` |
| **LOG_LEVEL** | Sets logging level | [Logging](./core/logger) | `INFO` |

Expand All @@ -638,11 +637,11 @@ Whether you're prototyping locally or against a non-production environment, you

When `POWERTOOLS_DEV` is set to a truthy value (`1`, `true`), it'll have the following effects:

| Utility | Effect |
| ----------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **Logger** | Increase JSON indentation to 4. This will ease local debugging when running functions locally under emulators or direct calls while not affecting unit tests |
| **Event Handler** | Enable full traceback errors in the response, indent request/responses, and CORS in dev mode (`*`). This will deprecate [`POWERTOOLS_EVENT_HANDLER_DEBUG`](https://awslabs.github.io/aws-lambda-powertools-python/latest/core/event_handler/api_gateway/#debug-mode) in the future. |
| **Tracer** | Future-proof safety to disables tracing operations in non-Lambda environments. This already happens automatically in the Tracer utility. |
| Utility | Effect |
| ----------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| **Logger** | Increase JSON indentation to 4. This will ease local debugging when running functions locally under emulators or direct calls while not affecting unit tests |
| **Event Handler** | Enable full traceback errors in the response, indent request/responses, and CORS in dev mode (`*`). |
| **Tracer** | Future-proof safety to disables tracing operations in non-Lambda environments. This already happens automatically in the Tracer utility. |

## Debug mode

Expand Down
10 changes: 0 additions & 10 deletions tests/functional/event_handler/test_api_gateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -793,16 +793,6 @@ def raises_error():
assert e.value.args == ("Foo",)


def test_debug_mode_environment_variable(monkeypatch):
# GIVEN a debug mode environment variable is set
monkeypatch.setenv(constants.EVENT_HANDLER_DEBUG_ENV, "true")
app = ApiGatewayResolver()

# WHEN calling app._debug
# THEN the debug mode is enabled
assert app._debug


def test_powertools_dev_sets_debug_mode(monkeypatch):
# GIVEN a debug mode environment variable is set
monkeypatch.setenv(constants.POWERTOOLS_DEV_ENV, "true")
Expand Down