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

how does this work #6

Open
Jfeng3 opened this issue Mar 1, 2017 · 6 comments
Open

how does this work #6

Jfeng3 opened this issue Mar 1, 2017 · 6 comments

Comments

@Jfeng3
Copy link

Jfeng3 commented Mar 1, 2017

Hi

  1. thanks for making this, it really helps!
  2. New to lambda, May I ask when you"to use them add your handler file to the zip, and add the lib directory so it can be used for shared libs" How exactly does it work? say I create a main.py with handler function, where do I place the main.py?
@markcampanelli
Copy link

markcampanelli commented Mar 2, 2017

I put my "main.py" file the same level as the lib (and other) directories in the example at https://github.com/ryansb/sklearn-build-lambda/blob/master/sample-site-packages-2016-02-20.zip. You also must specify the handler function in that file in the Amazon Lambda config.

@markcampanelli
Copy link

markcampanelli commented Mar 2, 2017

Also, I don't use sklearn, just numpy and scipy, and ever since AWS Lambda started supporting the lib directory on the default search path, I have found NO NEED for this (slowish) loading step from the README.md example:

import ctypes

for d, _, files in os.walk('lib'):
    for f in files:
        if f.endswith('.a'):
            continue
        ctypes.cdll.LoadLibrary(os.path.join(d, f))

@ryansb
Copy link
Owner

ryansb commented Jun 23, 2017

Oh, really? Thanks @thunderfish24 I'll have to test that out. I'd love to dump that hack 😄

@jmarrietar
Copy link

@thunderfish24 How the import section of your lambda handler looks like? Cheers,

@markcampanelli
Copy link

markcampanelli commented Jun 28, 2017

The directory structure for the lambda deploy looks like (recall that I don't use sklearn):

  • lambda_function_package
    • main.py
    • lib/
      • libatlas.a
      • ...
    • numpy/
      • compat/
      • ...
    • scipy/
      • _build_utils/
      • ...
    • my_package/
      • ...

After some other deploy pre-processing for my specific application, I use this bash command to zip up all the files FROM WITHIN THE lambda_function_package DIRECTORY:

# Zip it up at maximum compression
zip -r9 ../lambda_function_package.zip * -x "*.pyc" -x "*tests*"

The handler function main.py looks like:

import numpy as np
import scipy as sp

import my_package

def handler(event, context):
    ...handler code...

# Allow testing from command line
if __name__ == "__main__":
    # Create test event
    event = ...

    print(handler(event, None))

@aryahezarkhani
Copy link

aryahezarkhani commented Apr 3, 2018

This is great. Thanks.

I cannot figure why, though, my directory structure looks so different after running the build.sh:

lambda_function_package
---main.py
---lib/
------python2.7/
---------site-packages/
------------sklearn/
------------...
---lib64/
------python2.7/
---------site-packages/
------------sklearn/
------------...

Any idea how to bring the packages (opencv-python, sklearn, etc...) to the top level?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants