diff --git a/aws_lambda_powertools/utilities/data_classes/kinesis_stream_event.py b/aws_lambda_powertools/utilities/data_classes/kinesis_stream_event.py index 6af1484f155..ec45bfbd0b2 100644 --- a/aws_lambda_powertools/utilities/data_classes/kinesis_stream_event.py +++ b/aws_lambda_powertools/utilities/data_classes/kinesis_stream_event.py @@ -31,9 +31,13 @@ def sequence_number(self) -> str: """The unique identifier of the record within its shard""" return self["kinesis"]["sequenceNumber"] + def data_as_bytes(self) -> bytes: + """Decode binary encoded data as bytes""" + return base64.b64decode(self.data) + def data_as_text(self) -> str: """Decode binary encoded data as text""" - return base64.b64decode(self.data).decode("utf-8") + return self.data_as_bytes().decode("utf-8") def data_as_json(self) -> dict: """Decode binary encoded data as json""" diff --git a/tests/functional/test_data_classes.py b/tests/functional/test_data_classes.py index 72db667041f..c9e6f592439 100644 --- a/tests/functional/test_data_classes.py +++ b/tests/functional/test_data_classes.py @@ -1077,6 +1077,7 @@ def test_kinesis_stream_event(): assert kinesis.partition_key == "1" assert kinesis.sequence_number == "49590338271490256608559692538361571095921575989136588898" + assert kinesis.data_as_bytes() == b"Hello, this is a test." assert kinesis.data_as_text() == "Hello, this is a test."