From b6506221f1cce852a8d24bc72ecb262a64e050b5 Mon Sep 17 00:00:00 2001 From: Peter Dannemann Date: Thu, 30 May 2019 12:57:16 -0400 Subject: [PATCH] Remove file when complete This will prevent errors when the file persists on lambda --- extract_knack/cli.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/extract_knack/cli.py b/extract_knack/cli.py index 5ca91e4..3d8d8de 100644 --- a/extract_knack/cli.py +++ b/extract_knack/cli.py @@ -135,6 +135,10 @@ def load_to_s3(s3_bucket, s3_key, file_path): s3 = boto3.resource('s3') s3.Object(s3_bucket, s3_key).put(Body=open(file_path, 'rb')) +def clean_up(file_path): + if os.path.isfile(file_path): + os.remove(file_path) + @click.group() def main(): pass @@ -194,6 +198,7 @@ def extract_records_inner(knack_app_id, writer.writerow(out_record) load_to_s3(s3_bucket, s3_key, output_file) + clean_up(output_file) else: writer = csv.DictWriter(sys.stdout, fieldnames=headers)