Mitch Garnaat

Add a list of files and directories to exclude from the zip package because they…

… are already installed in Lambda.
...@@ -30,6 +30,11 @@ LOG = logging.getLogger(__name__) ...@@ -30,6 +30,11 @@ LOG = logging.getLogger(__name__)
30 30
31 class Function(object): 31 class Function(object):
32 32
33 + excluded_dirs = ['boto3', 'botocore', 'concurrent', 'dateutil',
34 + 'docutils', 'futures', 'jmespath', 'python_dateutil',
35 + 'six']
36 + excluded_files = ['.gitignore', 'six.py', 'six.pyc']
37 +
33 def __init__(self, context, config): 38 def __init__(self, context, config):
34 self._context = context 39 self._context = context
35 self._config = config 40 self._config = config
...@@ -194,9 +199,17 @@ class Function(object): ...@@ -194,9 +199,17 @@ class Function(object):
194 relroot = os.path.abspath(lambda_dir) 199 relroot = os.path.abspath(lambda_dir)
195 with zipfile.ZipFile(zipfile_name, 'w', 200 with zipfile.ZipFile(zipfile_name, 'w',
196 compression=zipfile.ZIP_DEFLATED) as zf: 201 compression=zipfile.ZIP_DEFLATED) as zf:
197 - for root, _, files in os.walk(lambda_dir): 202 + for root, subdirs, files in os.walk(lambda_dir):
203 + excluded_dirs = []
204 + for subdir in subdirs:
205 + for excluded in self.excluded_dirs:
206 + if subdir.startswith(excluded):
207 + excluded_dirs.append(subdir)
208 + for excluded in excluded_dirs:
209 + subdirs.remove(excluded)
198 zf.write(root, os.path.relpath(root, relroot)) 210 zf.write(root, os.path.relpath(root, relroot))
199 for filename in files: 211 for filename in files:
212 + if filename not in self.excluded_files:
200 filepath = os.path.join(root, filename) 213 filepath = os.path.join(root, filename)
201 if os.path.isfile(filepath): 214 if os.path.isfile(filepath):
202 arcname = os.path.join( 215 arcname = os.path.join(
......