Skip to content

Commit 1b5494f

Browse files
committed
fix(parser): apigw body can be null
1 parent e34469a commit 1b5494f

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

aws_lambda_powertools/utilities/parser/models/apigw.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -89,4 +89,4 @@ class APIGatewayProxyEventModel(BaseModel):
8989
pathParameters: Optional[Dict[str, str]]
9090
stageVariables: Optional[Dict[str, str]]
9191
isBase64Encoded: bool
92-
body: str
92+
body: Optional[str]

tests/functional/parser/test_apigw.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import pytest
22
from pydantic import ValidationError
33

4-
from aws_lambda_powertools.utilities.parser import envelopes, event_parser
4+
from aws_lambda_powertools.utilities.parser import envelopes, event_parser, parse
55
from aws_lambda_powertools.utilities.parser.models import APIGatewayProxyEventModel
66
from aws_lambda_powertools.utilities.typing import LambdaContext
77
from tests.functional.parser.schemas import MyApiGatewayBusiness
@@ -144,3 +144,9 @@ def test_apigw_event_with_invalid_websocket_request():
144144
expected_msg = "messageId is available only when the `eventType` is `MESSAGE`"
145145
assert errors[0]["msg"] == expected_msg
146146
assert expected_msg in str(err.value)
147+
148+
149+
def test_apigw_event_empty_body():
150+
event = load_event("apiGatewayProxyEvent.json")
151+
event["body"] = None
152+
parse(event=event, model=APIGatewayProxyEventModel)

0 commit comments

Comments
 (0)