From bea8764b4926773b1e628e68cb63b9a45643bc8a Mon Sep 17 00:00:00 2001 From: Golda Velez Date: Wed, 22 May 2024 01:48:11 -0700 Subject: [PATCH] log the data in case of error --- logs-to-tsdb/kinesis-lambda.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/logs-to-tsdb/kinesis-lambda.py b/logs-to-tsdb/kinesis-lambda.py index da36be6..8586563 100644 --- a/logs-to-tsdb/kinesis-lambda.py +++ b/logs-to-tsdb/kinesis-lambda.py @@ -5,7 +5,8 @@ import psycopg2.extras from base64 import b64decode, b64encode from datetime import datetime, timezone -from pprint import pprint +from pprint import pprint, pformat +from warnings import warn # Database connection parameters DB_HOST = os.environ['DB_HOST'] @@ -35,7 +36,12 @@ def handler(event, context): for record in event['Records']: # Decode the Kinesis data - payload = b64decode(record['kinesis']['data']).decode('utf-8') + try: + payload = b64decode(record['kinesis']['data']).decode('utf-8') + except Exception as e: + warn("Exception: " + str(e)) + warn("The data was: " + pformat(record)) + raise e data = json.loads(payload) for ev in data['logEvents']: