Skip to content

Commit

Permalink
Remove file when complete
Browse files Browse the repository at this point in the history
This will prevent errors when the file persists on lambda
  • Loading branch information
phlpeterdannemann committed May 30, 2019
1 parent ff4bae8 commit b650622
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions extract_knack/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit b650622

Please sign in to comment.