Add a list of files and directories to exclude from the zip package because they…
… are already installed in Lambda.
Showing
1 changed file
with
19 additions
and
6 deletions
... | @@ -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,14 +199,22 @@ class Function(object): | ... | @@ -194,14 +199,22 @@ 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: |
200 | - filepath = os.path.join(root, filename) | 212 | + if filename not in self.excluded_files: |
201 | - if os.path.isfile(filepath): | 213 | + filepath = os.path.join(root, filename) |
202 | - arcname = os.path.join( | 214 | + if os.path.isfile(filepath): |
203 | - os.path.relpath(root, relroot), filename) | 215 | + arcname = os.path.join( |
204 | - zf.write(filepath, arcname) | 216 | + os.path.relpath(root, relroot), filename) |
217 | + zf.write(filepath, arcname) | ||
205 | 218 | ||
206 | def _zip_lambda_file(self, zipfile_name, lambda_file): | 219 | def _zip_lambda_file(self, zipfile_name, lambda_file): |
207 | LOG.debug('_zip_lambda_file: lambda_file=%s', lambda_file) | 220 | LOG.debug('_zip_lambda_file: lambda_file=%s', lambda_file) | ... | ... |
-
Please register or login to post a comment