File tree 2 files changed +13
-1
lines changed
aws_lambda_powertools/utilities/data_classes
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]:
65
65
@property
66
66
def json_body (self ) -> Any :
67
67
"""Parses the submitted body as json"""
68
- return json .loads (self [ "body" ] )
68
+ return json .loads (self . decoded_body )
69
69
70
70
@property
71
71
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():
1037
1037
assert event .decoded_body == data
1038
1038
1039
1039
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
+
1040
1052
def test_kinesis_stream_event ():
1041
1053
event = KinesisStreamEvent (load_event ("kinesisStreamEvent.json" ))
1042
1054
You can’t perform that action at this time.
0 commit comments