Skip to content

Commit

Permalink
log the data in case of error
Browse files Browse the repository at this point in the history
  • Loading branch information
gvelez17 committed May 22, 2024
1 parent c7c698a commit bea8764
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions logs-to-tsdb/kinesis-lambda.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand Down Expand Up @@ -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']:
Expand Down

0 comments on commit bea8764

Please sign in to comment.