Miserlou / Zappa

Serverless Python
https://blog.zappa.io/
MIT License
11.89k stars 1.2k forks source link

ELF issues even when using "use_precompiled_packages": true #551

Open danielwhatmuff opened 7 years ago

danielwhatmuff commented 7 years ago

To resolve, I had to clone project to the amazon linux lambda AMI, run pip install -r requirements.txt and then zappa update

cscanlin commented 7 years ago

EDIT: Disregard all of this, setting "use_precompiled_packages": true DID fix it in my case. Sorry about that!


I'm having this same problem, originating from _openssl.so and the following packages:

cryptography==1.8.1
pyOpenSSL==16.2.0

I'm running Zappa on an OSX x64 machine, so all of my trouble shooting suggests that this is caused by the wrong version (non-linux) of the OpenSSL C bindings being compiled. Same as above, the use_precompiled_packages setting has no effect. Here is the full traceback from my logs:

/var/task/cryptography/hazmat/bindings/_openssl.so: invalid ELF header: ImportError
Traceback (most recent call last):
File "/var/task/handler.py", line 507, in lambda_handler
return LambdaHandler.lambda_handler(event, context)
File "/var/task/handler.py", line 238, in lambda_handler
handler = cls()
File "/var/task/handler.py", line 127, in __init__
self.app_module = importlib.import_module(self.settings.APP_MODULE)
File "/usr/lib64/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "/var/task/casatunes_controls.py", line 4, in <module>
from flask_ask import Ask, statement, request
File "/private/tmp/pip-build-JswCtu/flask-ask/flask_ask/__init__.py", line 8, in <module>
File "/private/tmp/pip-build-JswCtu/flask-ask/flask_ask/core.py", line 11, in <module>
File "/private/tmp/pip-build-JswCtu/flask-ask/flask_ask/verifier.py", line 8, in <module>
File "/private/tmp/pip-build-JswCtu/pyOpenSSL/OpenSSL/__init__.py", line 8, in <module>
File "/private/tmp/pip-build-JswCtu/pyOpenSSL/OpenSSL/rand.py", line 12, in <module>
File "/private/tmp/pip-build-JswCtu/pyOpenSSL/OpenSSL/_util.py", line 6, in <module>
File "/private/tmp/pip-build-JswCtu/cryptography/cryptography/hazmat/bindings/openssl/binding.py", line 12, in <module>
ImportError: /var/task/cryptography/hazmat/bindings/_openssl.so: invalid ELF header

For context, I'm trying to deploy a flask-ask application. Any help would be appreciated, thanks!

oliverandrich commented 7 years ago

Sadly, this problem can't be solved by using the fixed versions cryptography and pyOpenSSL or by using use_precompiled_package: true for me. Is this an issue of lambda-packages? Or flask-ask? Or Zappa?

joshua-at-aws commented 6 years ago

Hi,

ELF is Linux binary format, so looks like "use_precompiled_packages" was NOT available for the pyOpenSSL library. It isn't in the list at https://github.com/Miserlou/lambda-packages

So you need to either build on a container or using an EC2 instance locked to the base Amazon Linux AMI. If you are using the AMI, make sure to lock to the specific release (check docs for current version)

sudo sed -i 's;^releasever.*;releasever=2017.03;;' /etc/yum.conf 

Here's a couple detailed guides on these approaches:

Other common errors related to incorrect native binary libraries :

ImportError: /lib64/libcrypto.so.10: version `OPENSSL_1.0.2' not found (required by /var/task/...

not defined in file libcrypto.so.10 with link time reference