|
9 | 9 | import time
|
10 | 10 | from imp import load_source
|
11 | 11 | from shutil import copy
|
12 |
| -from shutil import copyfile |
| 12 | +from shutil import copyfile, copytree |
13 | 13 | from tempfile import mkdtemp
|
| 14 | +from collections import defaultdict |
14 | 15 |
|
15 | 16 | import boto3
|
16 | 17 | import botocore
|
@@ -246,24 +247,36 @@ def build(src, requirements=False, local_package=None):
|
246 | 247 | else output_filename
|
247 | 248 | )
|
248 | 249 |
|
| 250 | + # Allow definition of source code directories we want to build into our zipped package. |
| 251 | + build_config = defaultdict(**cfg.get('build', {})) |
| 252 | + build_source_directories = build_config.get('source_directories', '') |
| 253 | + build_source_directories = build_source_directories if build_source_directories is not None else '' |
| 254 | + source_directories = [d.strip() for d in build_source_directories.split(',')] |
| 255 | + |
249 | 256 | files = []
|
250 | 257 | for filename in os.listdir(src):
|
251 | 258 | if os.path.isfile(filename):
|
252 | 259 | if filename == '.DS_Store':
|
253 | 260 | continue
|
254 | 261 | if filename == 'config.yaml':
|
255 | 262 | continue
|
256 |
| - # TODO: Check subdirectories for '.DS_Store' files |
257 |
| - print('Bundling: %r' % filename) |
258 |
| - files.append(os.path.join(src, filename)) |
| 263 | + print('Bundling: %r' % filename) |
| 264 | + files.append(os.path.join(src, filename)) |
| 265 | + elif os.path.isdir(filename) and filename in source_directories: |
| 266 | + print('Bundling directory: %r' % filename) |
| 267 | + files.append(os.path.join(src, filename)) |
259 | 268 |
|
260 | 269 | # "cd" into `temp_path` directory.
|
261 | 270 | os.chdir(path_to_temp)
|
262 | 271 | for f in files:
|
263 |
| - _, filename = os.path.split(f) |
| 272 | + if os.path.isfile(f): |
| 273 | + _, filename = os.path.split(f) |
264 | 274 |
|
265 |
| - # Copy handler file into root of the packages folder. |
266 |
| - copyfile(f, os.path.join(path_to_temp, filename)) |
| 275 | + # Copy handler file into root of the packages folder. |
| 276 | + copyfile(f, os.path.join(path_to_temp, filename)) |
| 277 | + elif os.path.isdir(f): |
| 278 | + destination_folder = os.path.join(path_to_temp, f[len(src) + 1:]) |
| 279 | + copytree(f, destination_folder) |
267 | 280 |
|
268 | 281 | # Zip them together into a single file.
|
269 | 282 | # TODO: Delete temp directory created once the archive has been compiled.
|
@@ -527,8 +540,13 @@ def function_exists(cfg, function_name):
|
527 | 540 | 'lambda', aws_access_key_id, aws_secret_access_key,
|
528 | 541 | cfg.get('region'),
|
529 | 542 | )
|
530 |
| - functions = client.list_functions().get('Functions', []) |
531 |
| - for fn in functions: |
532 |
| - if fn.get('FunctionName') == function_name: |
533 |
| - return True |
534 |
| - return False |
| 543 | + |
| 544 | + # Need to loop through until we get all of the lambda functions returned. It appears |
| 545 | + # to be only returning 50 functions at a time. |
| 546 | + functions = [] |
| 547 | + functions_resp = client.list_functions() |
| 548 | + functions.extend([f['FunctionName'] for f in functions_resp.get('Functions', [])]) |
| 549 | + while('NextMarker' in functions_resp): |
| 550 | + functions_resp = client.list_functions(Marker=functions_resp.get('NextMarker')) |
| 551 | + functions.extend([f['FunctionName'] for f in functions_resp.get('Functions', [])]) |
| 552 | + return function_name in functions |
0 commit comments