Skip to content

Commit

Permalink
Fix bad data output: JSON encode dictionaries
Browse files Browse the repository at this point in the history
  • Loading branch information
Torgayev Tamirlan committed Feb 10, 2020
1 parent acbc56e commit d0c718e
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lambda/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,12 +161,18 @@ def bad_data_save(data: list, reason: str):
key += str(uuid.uuid4()) + ".gz"

logger.info(f"Saving failed records to S3: s3://{FAILED_LOG_S3_BUCKET}/{key}")
data = '\n'.join(str(f) for f in data)
data = '\n'.join(to_str(f) for f in data)
put_to_s3(key, FAILED_LOG_S3_BUCKET, data)

xray_recorder.end_subsegment()


def to_str(a):
if type(a) == dict:
return json.dumps(a)
return a


# noinspection PyUnusedLocal
def handler(event, context):
raw_records = event['Records']
Expand Down

0 comments on commit d0c718e

Please sign in to comment.