diff --git a/aws_lambda_powertools/event_handler/api_gateway.py b/aws_lambda_powertools/event_handler/api_gateway.py index 5d57c645b27..fad6589b3da 100644 --- a/aws_lambda_powertools/event_handler/api_gateway.py +++ b/aws_lambda_powertools/event_handler/api_gateway.py @@ -491,6 +491,8 @@ def resolve(self, event, context) -> Dict[str, Any]: dict Returns the dict response """ + if isinstance(event, BaseProxyEvent): + event = event.raw_event if self._debug: print(self._json_dump(event), end="") BaseRouter.current_event = self._to_proxy_event(event) diff --git a/tests/functional/event_handler/test_api_gateway.py b/tests/functional/event_handler/test_api_gateway.py index 9b5835c8b20..3738cd11456 100644 --- a/tests/functional/event_handler/test_api_gateway.py +++ b/tests/functional/event_handler/test_api_gateway.py @@ -31,7 +31,12 @@ ) from aws_lambda_powertools.shared import constants from aws_lambda_powertools.shared.json_encoder import Encoder -from aws_lambda_powertools.utilities.data_classes import ALBEvent, APIGatewayProxyEvent, APIGatewayProxyEventV2 +from aws_lambda_powertools.utilities.data_classes import ( + ALBEvent, + APIGatewayProxyEvent, + APIGatewayProxyEventV2, + event_source, +) from tests.functional.utils import load_event @@ -1210,3 +1215,23 @@ def handle_not_found(_) -> Response: # THEN call the @app.not_found() function assert result["statusCode"] == 404 + + +def test_event_source_compatibility(): + # GIVEN + app = APIGatewayHttpResolver() + + @app.post("/my/path") + def my_path(): + assert isinstance(app.current_event, APIGatewayProxyEventV2) + return {} + + # WHEN + @event_source(data_class=APIGatewayProxyEventV2) + def handler(event: APIGatewayProxyEventV2, context): + assert isinstance(event, APIGatewayProxyEventV2) + return app.resolve(event, context) + + # THEN + result = handler(load_event("apiGatewayProxyV2Event.json"), None) + assert result["statusCode"] == 200