From d0c718e1149f15e34fd55c0462d202c6d7e9da6e Mon Sep 17 00:00:00 2001 From: Torgayev Tamirlan Date: Mon, 10 Feb 2020 15:53:56 +0900 Subject: [PATCH] Fix bad data output: JSON encode dictionaries --- lambda/main.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lambda/main.py b/lambda/main.py index b927602..4a453a9 100644 --- a/lambda/main.py +++ b/lambda/main.py @@ -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']