I struggled with this for a long time. Here's my solution (there might be a better way):
setup your helper function in your file system like this:
pathToSomewhere/my_helper/helper_functions.py
pathToSomewhere/my_helper/__init__.py
pathToSomewhere/setup.py
Where __init__.py
is:
from .helper_functions import *
and setup.py
is
from setuptools import setup
setup(name='my_helper',
version='0.10000',
description='My helper functions',
url='http://github.com/user/example',
license='Proprietary',
author='Null',
author_email='[email protected]',
packages=['my_helper'],
install_requires=['boto3'],
zip_safe=False)
Now let's package up my_helper
. From pathToSomewhere/
run:
python setup.py sdist
I'm assuming you already know how to create and upload a virtual environment for running your lambda function. If not, let me know.
Now let's install my_helper
into the virtual env of your lambda function. Let's assume your virtual environment is called worker_env
./worker-env/bin/pip install file://pathToSomewhere/my_helper
Now zip up worker-env
and your actual lambda script and upload that.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…