-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Web3.py on AWS Lambda #554
Comments
I don't know much about the lambda options. Is it py2-only? If so, web3.py v4 won't work on it anyway, and v3 is in only being maintained with critical security patches. This suggests that CPython was compiled without a necessary flag (not necessarily that cytoolz needs to be compiled): |
Actually, I'm doing both Python 3.6 and Python 2.7 builds. I just reported the 2.7. Here's the 3.6 output from lambda: Unable to import module 'sparq.lambdas.rates': No module named '_pysha3' Now, the pysha3 stuff is actually installed:
|
Is The full stack trace and code is needed to debug further. I'm guessing some kind of module naming conflict issue, but don't have enough information. |
Yeah. I went ahead and created a new handler that looks like this:
And I got the same: Unable to import module 'hello': No module named '_pysha3' |
As far as a stack trace, it's not even loading the handler module, so it's not getting to a stack trace point. |
Reading this SO post made me think about the environment. Maybe it can't import because it was built with the wrong target environment? I'm trying to guess the target build environment based on the file name:
I'm a newb at python C extensions, but I'm guessing the 35 in there means Python 3.5 and you mentioned that your Lambda is running in Py3.6. Everything else looks right, I assume Lambda it runs in linux, on a 64-bit cpu with cpython (not pypy). |
Good catch. I'll have a look at that. |
This may take longer than I'd like. For some reason, when installing ethereum, I am getting the no Python.h thing, but python3-dev is installed. Grrrr... |
Hm, well we're inching toward completely removing the dependency on |
OK, that last one was me failing to realize I needed a python3.6-dev specific to 3.6. I am still getting the C compiler issue in Python 3: Unable to import module 'sparq.lambdas.rates': /var/task/cytoolz/functoolz.cpython-36m-x86_64-linux-gnu.so: undefined symbol: PyFPE_jbuf |
So back to my first comment: looks like you need a CPython that is compiled with |
This gets beyond my Python skill set. I've done some googling, but can't figure out how to do that. Any quick instructions? Thanks. |
I've never had to compile CPython on my machines, so I'm guessing it's actually a default setting. Either try to download the python binaries instead of using whatever is coming default, or you could try this guide (which I imagine works for 3.6 just fine as well): https://passingcuriosity.com/2015/installing-python-from-source/ |
Thanks! Also, I found a more detailed description of the issue here: https://bugs.python.org/issue29137 I'll pass on exact instructions in this thread when I get this working. For now, it appears certain there's no web3.py issue. |
The short answer is that I have it working. It requires a cytools build from source. The long answer: The Python environment within AWS lambda is 3.6 and built WITHOUT --with-fpectl, but most environments are built with it. To build a proper lambda environment, here are the steps:
git clone https://github.com/pytoolz/cytoolz.git
cd cytoolz
git checkout release
make for file in VITUALENVROOT/lib/python3.6/site-packages/cytoolz/*; do
cp -R cytoolz/`basename $file`VIRTUALENVROOT/lib/python3.6/site-packages/cytoolz/;
done
Building cytoolz on your Ubuntu system with figure it all out. |
Closing this out as it isn't web3.py issue. |
Great, thanks for posting the writeup here! |
Thank you for your post. |
I tried this approach, albeit using an older version of Ubuntu 16.04 but was able to get everything to compile and work locally by installing python3.6-dev, build-essential, and libssl-dev. However, unless I'm misreading, doesn't your script assume that cytoolz is already in the virtualenv and copies files that exist in the new build directory to overwrite existing files in the virtualenv? Did you run the make command within the virtualenv? I tried Also the snippet appears to be missing a space between $file and VIRTUALENVROOT unless again I'm in error. for file in VITUALENVROOT/lib/python3.6/site-packages/cytoolz/*; do
cp -R cytoolz/`basename $file` VIRTUALENVROOT/lib/python3.6/site-packages/cytoolz/;
done |
I was able to get this working simply by starting with an Ubuntu 18.04 image and adding the following packages via
Then just ran virtualenv and pip as usually and all was well. |
hey @iteratelance, @greese, running into the same issue, and I do have a basic question on how to resolve this. Here is what I did so far:
What I am having difficulty understanding is how do we make this EC2 environment available for a given AWS Lambda function? Do we just take the zip, copy it over from EC2 to my local machine, and then upload it to AWS Lambda? Should we be using Docker instead (i.e. https://docs.aws.amazon.com/lambda/latest/dg/images-create.html)? |
Was able to figure this out. For anyone else that may be running into the same issue:
|
@0xRadix Thanks for coming back and posting! |
There is a more easy way to do it now. https://aws.amazon.com/premiumsupport/knowledge-center/lambda-import-module-error-python/ |
@GraphicalDot I tried that in addition to all the other approaches mentioned yet nothing seemed to work, what might be the issue? |
What was wrong?
Dependencies on cytoolz (which depends on a C compiler) make deployment on AWS lambda not work, whereas web3.js is able to deploy on AWS lambda.
The specific error is:
Unable to import module 'mylambda': /var/task/cytoolz/functoolz.so: undefined symbol: PyFPE_jbuf
How can it be fixed?
No clue. Not sure what the dependency on cytoolz does.
The text was updated successfully, but these errors were encountered: