http://docs.python-guide.org/en/latest/dev/virtualenvs/ http://docs.aws.amazon.com/lambda/latest/dg/lambda-python-how-to-create-deployment-package.html
To create a virtualenv
inside your project directory
virtualenv venv
To activate virtualenv
source venv/bin/activate
While active, install packages
pip install requests
When you are finished deactivate
deactivate
zip the python files
zip package.zip some_script.py
Add the site-packages files
cd venv/lib/python2.7/site-packages
zip -ur ../../../../package.zip *
Your handler function should be named as filename.module_name
In this case
some_script.lambda_handler
import os
os.environ['THUNDERSTONE_URL']
When using locally with virtualenv
you can add the environment variable to the bottom of the venv/bin/activate
file.
THUNDERSTONE_URL=https://search.ramseysolutions.net/texis/search/main.xml
export THUNDERSTONE_URL
Because
lxml
must be built with C extensions forlibxml2
andlibxslt
in a way that plays well with the Amazon Lambda execution environment.
Using Python’s LXML in Amazon Lambda
Generally what we've done is use a python dependency file and let the build process handle building it into the correct CPU architecture
for instance: https://github.com/lampo/authx-lambda-functions/blob/master/src/requirements.txt
I believe (and I could be mistaken at this point) that requirements file should work locally as well for development. I know the build server understands those files...
I was able to get my script running on Lambda by duping my site-packages directory and replacing the LXML directory with the lambda-packages repo LXML directory. I think zipped and uploaded that.