File tree Expand file tree Collapse file tree 2 files changed +13
-1
lines changed
aws_lambda_powertools/utilities/data_classes Expand file tree Collapse file tree 2 files changed +13
-1
lines changed Original file line number Diff line number Diff line change @@ -65,7 +65,7 @@ def body(self) -> Optional[str]:
6565 @property
6666 def json_body (self ) -> Any :
6767 """Parses the submitted body as json"""
68- return json .loads (self [ "body" ] )
68+ return json .loads (self . decoded_body )
6969
7070 @property
7171 def decoded_body (self ) -> str :
Original file line number Diff line number Diff line change @@ -1037,6 +1037,18 @@ def test_base_proxy_event_decode_body_encoded_true():
10371037 assert event .decoded_body == data
10381038
10391039
1040+ def test_base_proxy_event_json_body_with_base64_encoded_data ():
1041+ # GIVEN a base64 encoded json body
1042+ data = {"message" : "Foo" }
1043+ data_str = json .dumps (data )
1044+ encoded_data = base64 .b64encode (data_str .encode ()).decode ()
1045+ event = BaseProxyEvent ({"body" : encoded_data , "isBase64Encoded" : True })
1046+
1047+ # WHEN calling json_body
1048+ # THEN then base64 decode and json load
1049+ assert event .json_body == data
1050+
1051+
10401052def test_kinesis_stream_event ():
10411053 event = KinesisStreamEvent (load_event ("kinesisStreamEvent.json" ))
10421054
You can’t perform that action at this time.
0 commit comments