File tree Expand file tree Collapse file tree 4 files changed +24
-5
lines changed
aws_lambda_powertools/utilities/parser/models Expand file tree Collapse file tree 4 files changed +24
-5
lines changed Original file line number Diff line number Diff 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 ]
Original file line number Diff line number Diff line change @@ -63,9 +63,9 @@ class APIGatewayProxyEventV2Model(BaseModel):
6363 rawQueryString : str
6464 cookies : Optional [List [str ]]
6565 headers : Dict [str , str ]
66- queryStringParameters : Dict [str , str ]
66+ queryStringParameters : Optional [ Dict [str , str ] ]
6767 pathParameters : Optional [Dict [str , str ]]
6868 stageVariables : Optional [Dict [str , str ]]
6969 requestContext : RequestContextV2
70- body : str
70+ body : Optional [ str ]
7171 isBase64Encoded : bool
Original file line number Diff line number Diff line change 11import pytest
22from 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
55from aws_lambda_powertools .utilities .parser .models import APIGatewayProxyEventModel
66from aws_lambda_powertools .utilities .typing import LambdaContext
77from 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 )
Original file line number Diff line number Diff line change 1- from aws_lambda_powertools .utilities .parser import envelopes , event_parser
1+ from aws_lambda_powertools .utilities .parser import envelopes , event_parser , parse
22from aws_lambda_powertools .utilities .parser .models import (
33 APIGatewayProxyEventV2Model ,
44 RequestContextV2 ,
@@ -90,3 +90,16 @@ def test_api_gateway_proxy_v2_event_iam_authorizer():
9090 assert iam .principalOrgId == "AwsOrgId"
9191 assert iam .userArn == "arn:aws:iam::1234567890:user/Admin"
9292 assert iam .userId == "AROA2ZJZYVRE7Y3TUXHH6"
93+
94+
95+ def test_apigw_event_empty_body ():
96+ event = load_event ("apiGatewayProxyV2Event.json" )
97+ event .pop ("body" ) # API GW v2 removes certain keys when no data is passed
98+ parse (event = event , model = APIGatewayProxyEventV2Model )
99+
100+
101+ def test_apigw_event_empty_query_strings ():
102+ event = load_event ("apiGatewayProxyV2Event.json" )
103+ event ["rawQueryString" ] = ""
104+ event .pop ("queryStringParameters" ) # API GW v2 removes certain keys when no data is passed
105+ parse (event = event , model = APIGatewayProxyEventV2Model )
You can’t perform that action at this time.
0 commit comments