Skip to content

Commit 0fde368

Browse files
Merging from develop
2 parents 53402b9 + 12aeb50 commit 0fde368

3 files changed

Lines changed: 18 additions & 128 deletions

File tree

aws_lambda_powertools/event_handler/api_gateway.py

Lines changed: 13 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1489,9 +1489,11 @@ def lambda_handler(event, context):
14891489
```
14901490
"""
14911491

1492+
_proxy_event_type: Enum = ProxyEventType.APIGatewayProxyEvent
1493+
14921494
def __init__(
14931495
self,
1494-
proxy_type: Enum = ProxyEventType.APIGatewayProxyEvent,
1496+
proxy_type: Enum | None = None,
14951497
cors: CORSConfig | None = None,
14961498
debug: bool | None = None,
14971499
serializer: Callable[[dict], str] | None = None,
@@ -1524,8 +1526,8 @@ def __init__(
15241526
function to deserialize `str`, `bytes`, `bytearray` containing a JSON document to a Python `dict`,
15251527
by default json.loads when integrating with EventSource data class
15261528
"""
1527-
self._proxy_type = proxy_type
15281529
self.dependency_overrides: dict[Callable, Callable] = {}
1530+
self._proxy_type = proxy_type or self._proxy_event_type
15291531
self._dynamic_routes: list[Route] = []
15301532
self._static_routes: list[Route] = []
15311533
self._route_keys: list[str] = []
@@ -2965,28 +2967,7 @@ class APIGatewayRestResolver(ApiGatewayResolver):
29652967
"""Amazon API Gateway REST and HTTP API v1 payload resolver"""
29662968

29672969
current_event: APIGatewayProxyEvent
2968-
2969-
def __init__(
2970-
self,
2971-
cors: CORSConfig | None = None,
2972-
debug: bool | None = None,
2973-
serializer: Callable[[dict], str] | None = None,
2974-
strip_prefixes: list[str | Pattern] | None = None,
2975-
enable_validation: bool = False,
2976-
response_validation_error_http_code: HTTPStatus | int | None = None,
2977-
json_body_deserializer: Callable[[str], dict] | None = None,
2978-
):
2979-
"""Amazon API Gateway REST and HTTP API v1 payload resolver"""
2980-
super().__init__(
2981-
ProxyEventType.APIGatewayProxyEvent,
2982-
cors,
2983-
debug,
2984-
serializer,
2985-
strip_prefixes,
2986-
enable_validation,
2987-
response_validation_error_http_code,
2988-
json_body_deserializer=json_body_deserializer,
2989-
)
2970+
_proxy_event_type = ProxyEventType.APIGatewayProxyEvent
29902971

29912972
def _get_base_path(self) -> str:
29922973
# 3 different scenarios:
@@ -3055,28 +3036,7 @@ class APIGatewayHttpResolver(ApiGatewayResolver):
30553036
"""Amazon API Gateway HTTP API v2 payload resolver"""
30563037

30573038
current_event: APIGatewayProxyEventV2
3058-
3059-
def __init__(
3060-
self,
3061-
cors: CORSConfig | None = None,
3062-
debug: bool | None = None,
3063-
serializer: Callable[[dict], str] | None = None,
3064-
strip_prefixes: list[str | Pattern] | None = None,
3065-
enable_validation: bool = False,
3066-
response_validation_error_http_code: HTTPStatus | int | None = None,
3067-
json_body_deserializer: Callable[[str], dict] | None = None,
3068-
):
3069-
"""Amazon API Gateway HTTP API v2 payload resolver"""
3070-
super().__init__(
3071-
ProxyEventType.APIGatewayProxyEventV2,
3072-
cors,
3073-
debug,
3074-
serializer,
3075-
strip_prefixes,
3076-
enable_validation,
3077-
response_validation_error_http_code,
3078-
json_body_deserializer=json_body_deserializer,
3079-
)
3039+
_proxy_event_type = ProxyEventType.APIGatewayProxyEventV2
30803040

30813041
def _get_base_path(self) -> str:
30823042
# 3 different scenarios:
@@ -3096,6 +3056,7 @@ class ALBResolver(ApiGatewayResolver):
30963056
"""Amazon Application Load Balancer (ALB) resolver"""
30973057

30983058
current_event: ALBEvent
3059+
_proxy_event_type = ProxyEventType.ALBEvent
30993060

31003061
def __init__(
31013062
self,
@@ -3135,13 +3096,12 @@ def __init__(
31353096
Enables URL-decoding of query parameters (both keys and values), by default False.
31363097
"""
31373098
super().__init__(
3138-
ProxyEventType.ALBEvent,
3139-
cors,
3140-
debug,
3141-
serializer,
3142-
strip_prefixes,
3143-
enable_validation,
3144-
response_validation_error_http_code,
3099+
cors=cors,
3100+
debug=debug,
3101+
serializer=serializer,
3102+
strip_prefixes=strip_prefixes,
3103+
enable_validation=enable_validation,
3104+
response_validation_error_http_code=response_validation_error_http_code,
31453105
json_body_deserializer=json_body_deserializer,
31463106
)
31473107
self.decode_query_parameters = decode_query_parameters

aws_lambda_powertools/event_handler/lambda_function_url.py

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,13 @@
11
from __future__ import annotations
22

3-
from typing import TYPE_CHECKING, Pattern
3+
from typing import TYPE_CHECKING
44

55
from aws_lambda_powertools.event_handler.api_gateway import (
66
ApiGatewayResolver,
77
ProxyEventType,
88
)
99

1010
if TYPE_CHECKING:
11-
from collections.abc import Callable
12-
from http import HTTPStatus
13-
14-
from aws_lambda_powertools.event_handler import CORSConfig
1511
from aws_lambda_powertools.utilities.data_classes import LambdaFunctionUrlEvent
1612

1713

@@ -52,27 +48,7 @@ def lambda_handler(event, context):
5248
"""
5349

5450
current_event: LambdaFunctionUrlEvent
55-
56-
def __init__(
57-
self,
58-
cors: CORSConfig | None = None,
59-
debug: bool | None = None,
60-
serializer: Callable[[dict], str] | None = None,
61-
strip_prefixes: list[str | Pattern] | None = None,
62-
enable_validation: bool = False,
63-
response_validation_error_http_code: HTTPStatus | int | None = None,
64-
json_body_deserializer: Callable[[str], dict] | None = None,
65-
):
66-
super().__init__(
67-
ProxyEventType.LambdaFunctionUrlEvent,
68-
cors,
69-
debug,
70-
serializer,
71-
strip_prefixes,
72-
enable_validation,
73-
response_validation_error_http_code,
74-
json_body_deserializer=json_body_deserializer,
75-
)
51+
_proxy_event_type = ProxyEventType.LambdaFunctionUrlEvent
7652

7753
def _get_base_path(self) -> str:
7854
stage = self.current_event.request_context.stage

aws_lambda_powertools/event_handler/vpc_lattice.py

Lines changed: 3 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,13 @@
11
from __future__ import annotations
22

3-
from typing import TYPE_CHECKING, Pattern
3+
from typing import TYPE_CHECKING
44

55
from aws_lambda_powertools.event_handler.api_gateway import (
66
ApiGatewayResolver,
77
ProxyEventType,
88
)
99

1010
if TYPE_CHECKING:
11-
from collections.abc import Callable
12-
from http import HTTPStatus
13-
14-
from aws_lambda_powertools.event_handler import CORSConfig
1511
from aws_lambda_powertools.utilities.data_classes import VPCLatticeEvent, VPCLatticeEventV2
1612

1713

@@ -48,28 +44,7 @@ def lambda_handler(event, context):
4844
"""
4945

5046
current_event: VPCLatticeEvent
51-
52-
def __init__(
53-
self,
54-
cors: CORSConfig | None = None,
55-
debug: bool | None = None,
56-
serializer: Callable[[dict], str] | None = None,
57-
strip_prefixes: list[str | Pattern] | None = None,
58-
enable_validation: bool = False,
59-
response_validation_error_http_code: HTTPStatus | int | None = None,
60-
json_body_deserializer: Callable[[str], dict] | None = None,
61-
):
62-
"""Amazon VPC Lattice resolver"""
63-
super().__init__(
64-
ProxyEventType.VPCLatticeEvent,
65-
cors,
66-
debug,
67-
serializer,
68-
strip_prefixes,
69-
enable_validation,
70-
response_validation_error_http_code,
71-
json_body_deserializer=json_body_deserializer,
72-
)
47+
_proxy_event_type = ProxyEventType.VPCLatticeEvent
7348

7449
def _get_base_path(self) -> str:
7550
return ""
@@ -108,28 +83,7 @@ def lambda_handler(event, context):
10883
"""
10984

11085
current_event: VPCLatticeEventV2
111-
112-
def __init__(
113-
self,
114-
cors: CORSConfig | None = None,
115-
debug: bool | None = None,
116-
serializer: Callable[[dict], str] | None = None,
117-
strip_prefixes: list[str | Pattern] | None = None,
118-
enable_validation: bool = False,
119-
response_validation_error_http_code: HTTPStatus | int | None = None,
120-
json_body_deserializer: Callable[[str], dict] | None = None,
121-
):
122-
"""Amazon VPC Lattice resolver"""
123-
super().__init__(
124-
ProxyEventType.VPCLatticeEventV2,
125-
cors,
126-
debug,
127-
serializer,
128-
strip_prefixes,
129-
enable_validation,
130-
response_validation_error_http_code,
131-
json_body_deserializer=json_body_deserializer,
132-
)
86+
_proxy_event_type = ProxyEventType.VPCLatticeEventV2
13387

13488
def _get_base_path(self) -> str:
13589
return ""

0 commit comments

Comments
 (0)