Skip to content

Commit

Permalink
Fix Miserlou#881 - Stream zip file from s3
Browse files Browse the repository at this point in the history
  • Loading branch information
mbeacom committed May 23, 2017
1 parent 42b1565 commit 64714af
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions zappa/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import datetime
import importlib
import inspect
import io
import json
import logging
import os
Expand Down Expand Up @@ -161,13 +162,18 @@ def load_remote_project_zip(self, project_zip_path):
remote_bucket, remote_file = project_zip_path.lstrip('s3://').split('/', 1)
s3 = boto_session.resource('s3')

zip_path = '/tmp/{0!s}'.format(remote_file)
s3.Object(remote_bucket, remote_file).download_file(zip_path)
zip_path = s3.Object(remote_bucket, remote_file)

# Unzip contents to project folder
with zipfile.ZipFile(zip_path, 'r') as z:
z.extractall(path=project_folder)

with io.BytesIO(zip_path.get()['Body'].read()) as tf:
tf.seek(0) # Rewind the file
# Read zip contents and extract them to the project folder
with zipfile.ZipFile(tf, 'r') as z:
z.extractall(path=project_folder)

# Add to project path
sys.path.insert(0, project_folder)

Expand Down

0 comments on commit 64714af

Please sign in to comment.