Open
Description
We are using one repository which includes multiple lambda configurations.
/dummy
config-1.yaml
config-2.yaml
handler.py
requirements.txt
/foo
config.yaml
handler.py
requirements.txt
I created a little script to create packages for each of the functions:
#!/usr/bin/env python
import aws_lambda
import os
_cwd = os.getcwd()
def build(name, config='config.yaml'):
aws_lambda.build(
os.path.join(_cwd, name),
requirements=os.path.join(_cwd, name, 'requirements.txt'),
config_file=os.path.join(_cwd, name, config)
)
build('dummy', 'config-1.yaml')
build('dummy', 'config-2.yaml')
build('foo')
The resulting packages only contain the installed requirements, but not any of the lambda handler itself.
This is caused by the isfile
check in aws_lambda.build
. It assumes that the current directory is the source directory since it does not join the directory and filename (as done 6 lines below).
possible fix:
--- /tmp/a 2018-08-07 11:28:35.000000000 +0200
+++ /tmp/b 2018-08-07 11:28:40.000000000 +0200
@@ -327,16 +327,17 @@
files = []
for filename in os.listdir(src):
- if os.path.isfile(filename):
+ abs_filename = os.path.join(src, filename)
+ if os.path.isfile(abs_filename):
if filename == '.DS_Store':
continue
if filename == config_file:
continue
print('Bundling: %r' % filename)
- files.append(os.path.join(src, filename))
+ files.append(abs_filename)
elif os.path.isdir(filename) and filename in source_directories:
print('Bundling directory: %r' % filename)
- files.append(os.path.join(src, filename))
+ files.append(abs_filename)
# "cd" into `temp_path` directory.
os.chdir(path_to_temp)