Skip to content

Commit 7412bff

Browse files
addessing Ruben's feedback
1 parent 1ac1504 commit 7412bff

File tree

5 files changed

+23
-24
lines changed

5 files changed

+23
-24
lines changed

aws_lambda_powertools/event_handler/api_gateway.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -693,12 +693,8 @@ def _to_proxy_event(self, event: Dict) -> BaseProxyEvent:
693693

694694
def _resolve(self) -> ResponseBuilder:
695695
"""Resolves the response or return the not found response"""
696-
if self._proxy_type == ProxyEventType.VPCLatticeEvent:
697-
method = self.current_event.method.upper()
698-
path = self._remove_prefix(self.current_event.raw_path)
699-
else:
700-
method = self.current_event.http_method.upper()
701-
path = self._remove_prefix(self.current_event.path)
696+
method = self.current_event.http_method.upper()
697+
path = self._remove_prefix(self.current_event.path)
702698

703699
for route in self._static_routes + self._dynamic_routes:
704700
if method != route.method:

aws_lambda_powertools/utilities/data_classes/common.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -136,16 +136,6 @@ def http_method(self) -> str:
136136
"""The HTTP method used. Valid values include: DELETE, GET, HEAD, OPTIONS, PATCH, POST, and PUT."""
137137
return self["httpMethod"]
138138

139-
# VPC Lattice path
140-
@property
141-
def raw_path(self) -> str:
142-
return self.get("raw_path") or ""
143-
144-
# VPC Lattice http method
145-
@property
146-
def method(self) -> str:
147-
return self.get("method") or ""
148-
149139
def get_query_string_value(self, name: str, default_value: Optional[str] = None) -> Optional[str]:
150140
"""Get query string value by name
151141

aws_lambda_powertools/utilities/data_classes/vpc_lattice.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from aws_lambda_powertools.shared.headers_serializer import (
44
BaseHeadersSerializer,
5-
SingleValueHeadersSerializer,
5+
HttpApiHeadersSerializer,
66
)
77
from aws_lambda_powertools.utilities.data_classes.common import BaseProxyEvent
88
from aws_lambda_powertools.utilities.data_classes.shared_functions import (
@@ -58,6 +58,19 @@ def raw_path(self) -> str:
5858
"""The raw VPC Lattice request path."""
5959
return self["raw_path"]
6060

61+
# VPCLattice event has no path field
62+
# Added here for consistency with the BaseProxyEvent class
63+
@property
64+
def path(self) -> str:
65+
return self["raw_path"]
66+
67+
# VPCLattice event has no http_method field
68+
# Added here for consistency with the BaseProxyEvent class
69+
@property
70+
def http_method(self) -> str:
71+
"""The HTTP method used. Valid values include: DELETE, GET, HEAD, OPTIONS, PATCH, POST, and PUT."""
72+
return self["method"]
73+
6174
def get_query_string_value(self, name: str, default_value: Optional[str] = None) -> Optional[str]:
6275
"""Get query string value by name
6376
@@ -107,5 +120,5 @@ def get_header_value(
107120
)
108121

109122
def header_serializer(self) -> BaseHeadersSerializer:
110-
# When using the VPC Lattice integration, we just have single header.
111-
return SingleValueHeadersSerializer()
123+
# When using the VPC Lattice integration, we have multiple HTTP Headers.
124+
return HttpApiHeadersSerializer()

docs/core/event_handler/api_gateway.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ When using [VPC Lattice with AWS Lambda](https://docs.aws.amazon.com/lambda/late
124124

125125
=== "getting_started_vpclattice_resolver.py"
126126

127-
```python hl_lines="5 11" title="Using Lambda Function URL resolver"
127+
```python hl_lines="5 11" title="Using VPC Lattice resolver"
128128
--8<-- "examples/event_handler_rest/src/getting_started_vpclattice_resolver.py"
129129
```
130130

tests/functional/event_handler/test_vpc_lattice.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010

1111
def test_vpclattice_event():
12-
# GIVEN an Application Load Balancer proxy type event
12+
# GIVEN a VPC Lattice event
1313
app = VPCLatticeResolver()
1414

1515
@app.get("/testpath")
@@ -22,14 +22,14 @@ def foo():
2222
result = app(load_event("vpcLatticeEvent.json"), {})
2323

2424
# THEN process event correctly
25-
# AND set the current_event type as ALBEvent
25+
# AND set the current_event type as VPCLatticeEvent
2626
assert result["statusCode"] == 200
2727
assert result["headers"]["Content-Type"] == content_types.TEXT_HTML
2828
assert result["body"] == "foo"
2929

3030

3131
def test_vpclattice_event_path_trailing_slash(json_dump):
32-
# GIVEN an Application Load Balancer proxy type event
32+
# GIVEN a VPC Lattice event
3333
app = VPCLatticeResolver()
3434

3535
@app.get("/testpath")
@@ -62,7 +62,7 @@ def test_cors_preflight_body_is_empty_not_null():
6262

6363

6464
def test_vpclattice_url_no_matches():
65-
# GIVEN a Lambda Function Url type event
65+
# GIVEN a VPC Lattice event
6666
app = VPCLatticeResolver()
6767

6868
@app.post("/no_match")

0 commit comments

Comments
 (0)