Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Building from a non-working directory does not include any files into the bundle #120

Open
Birne94 opened this issue Aug 7, 2018 · 0 comments · May be fixed by #121
Open

Building from a non-working directory does not include any files into the bundle #120

Birne94 opened this issue Aug 7, 2018 · 0 comments · May be fixed by #121

Comments

@Birne94
Copy link

Birne94 commented Aug 7, 2018

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)
Birne94 added a commit to Birne94/python-lambda that referenced this issue Aug 7, 2018
@Birne94 Birne94 linked a pull request Aug 7, 2018 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants