Skip to content
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

feat(event_handler): Allow the ApiGatewayResolver to support an existing subclass of BaseProxyEvent #3268

Open
wants to merge 1 commit into
base: v2
Choose a base branch
from
Open
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
27 changes: 12 additions & 15 deletions aws_lambda_powertools/event_handler/api_gateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -1252,7 +1252,7 @@ def lambda_handler(event, context):

def __init__(
self,
proxy_type: Enum = ProxyEventType.APIGatewayProxyEvent,
proxy_type: Optional[Enum] = ProxyEventType.APIGatewayProxyEvent,
cors: Optional[CORSConfig] = None,
debug: Optional[bool] = None,
serializer: Optional[Callable[[Dict], str]] = None,
Expand All @@ -1262,8 +1262,8 @@ def __init__(
"""
Parameters
----------
proxy_type: ProxyEventType
Proxy request type, defaults to API Gateway V1
proxy_type: Optional[ProxyEventType]
Proxy request type, defaults to API Gateway V1. Passing None will use an existing ProxyEvent
cors: CORSConfig
Optionally configure and enabled CORS. Not each route will need to have to cors=True
debug: Optional[bool]
Expand Down Expand Up @@ -1557,7 +1557,7 @@ def resolve(self, event, context) -> Dict[str, Any]:

Parameters
----------
event: Dict[str, Any]
event: Union[Dict[str, Any], BaseProxyEvent]
Event
context: LambdaContext
Lambda context
Expand All @@ -1567,18 +1567,15 @@ def resolve(self, event, context) -> Dict[str, Any]:
Returns the dict response
"""
if isinstance(event, BaseProxyEvent):
warnings.warn(
"You don't need to serialize event to Event Source Data Class when using Event Handler; "
"see issue #1152",
stacklevel=2,
)
event = event.raw_event

if self._debug:
print(self._json_dump(event))
BaseRouter.current_event = event
if self._debug:
print(self._json_dump(event.raw_event))
else:
# Populate router(s) dependencies without keeping a reference to each registered router
BaseRouter.current_event = self._to_proxy_event(event)
if self._debug:
print(self._json_dump(event))

# Populate router(s) dependencies without keeping a reference to each registered router
BaseRouter.current_event = self._to_proxy_event(event)
BaseRouter.lambda_context = context

response = self._resolve().build(self.current_event, self._cors)
Expand Down