8

I am trying to make a deployment package for the service Pusher in Python on AWS Lambda.

When I run simple code like this

from pusher import Pusher
def pusherTest(context, event):
    mypusher = Pusher(app_id=u'***', key=u'***', secret=u'***')
    mypusher.trigger('testchannel', 'testevent', {u'some': u'data'})

I'm getting this stack trace:

libssl.so.1.0.0: cannot open shared object file: No such file or directory: ImportError
Traceback (most recent call last):
  File "/var/task/Lambda.py", line 3, in pusherTest
    mypusher = Pusher(app_id=u'***', key=u'***', secret='***')
  File "/var/task/pusher/pusher.py", line 42, in __init__
    from pusher.requests import RequestsBackend
  File "/var/task/pusher/requests.py", line 12, in <module>
    import urllib3.contrib.pyopenssl
  File "/var/task/urllib3/contrib/pyopenssl.py", line 54, in <module>
    import OpenSSL.SSL
  File "/var/task/OpenSSL/__init__.py", line 8, in <module>
    from OpenSSL import rand, crypto, SSL
  File "/var/task/OpenSSL/rand.py", line 12, in <module>
    from OpenSSL._util import (
  File "/var/task/OpenSSL/_util.py", line 6, in <module>
    from cryptography.hazmat.bindings.openssl.binding import Binding
  File "/var/task/cryptography/hazmat/bindings/openssl/binding.py", line 15, in <module>
    from cryptography.hazmat.bindings._openssl import ffi, lib
ImportError: libssl.so.1.0.0: cannot open shared object file: No such file or directory

I believe libssl is a C library and since I don't have access to the Lambda machine to install these types of dependencies, how could I make this work?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
jamesmpw
  • 515
  • 5
  • 16
  • On what Linux distro are you building the deployment package? – helloV Apr 07 '16 at 12:04
  • Hi @jamesmpw, Did you use Pusher in lambda? I installed pusher in the amazon-linux, but I still have this problem: `"errorType": "ImportError", "errorMessage": "No module named cryptography.hazmat.bindings.openssl.binding"`, Did you have this problem before ? – José Castro Sep 12 '16 at 21:48
  • Hmm I kind of remember that but I can't recall what I did to fix it. are you using virtualenv? – jamesmpw Sep 12 '16 at 21:50
  • Yes, for install all reqs, even I install cryptography, but still fail – José Castro Sep 13 '16 at 15:42
  • 1
    This question looks like a special case of: https://stackoverflow.com/questions/57894698/can-aws-lambda-use-python-that-calls-c – Att Righ Sep 23 '21 at 10:25
  • 1
    Also it's ind of a special case of this one: https://stackoverflow.com/questions/45044358/specifying-c-dependencies-for-python-packages-for-use-in-aws-lambda – Att Righ Sep 23 '21 at 10:33
  • This was used in a mock up in blog post *"[Announcing more ways to learn and grow your skills](https://stackoverflow.blog/2023/02/01/announcing-more-ways-to-learn-and-grow-your-skills/)"* (2023-02-01). – Peter Mortensen Mar 25 '23 at 04:44

2 Answers2

9

I had the same problem and I had the chance to really understand what is the hint here. The follow error is clearing say to us that the library libssl.so is not there...

ImportError: libssl.so.1.0.0: cannot open shared object file: No such file or directory

I would expect that it is there ... After all Amazon Linux is a linux distro and libssl should be there. But I do not know ... may be it is not directly accessible from the lambda function.

To solve the problem I added the library in the zip bundle

cd /usr/lib64
zip -u /tmp/lambda.zip libssl.so.1.0.0

I redeployed and the error was different. Eureka!

Another library was missed. The libcrypto. I did the same task and now my lambda function is working as expected.

cd /usr/lib64
zip -u /tmp/lambda.zip libcrypto.so.1.0.0
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Zioalex
  • 3,441
  • 2
  • 33
  • 30
  • This is brilliant! As a footnote: I could not locate libssl.so.1.0.0 in miniconda3/envs/xxx/lib/. But i found it in /home/ubuntu/miniconda3/lib/ – human Dec 20 '17 at 06:12
  • Your answer has been used (anonymised) to demo a new feature on [meta](https://meta.stackexchange.com/questions/370640/version-labels-for-answers) (see point 3 of original post) ;-) – trincot Oct 12 '21 at 11:42
  • Also here: https://meta.stackoverflow.com/questions/422723/we-re-bringing-advertisements-for-technology-courses-to-stack-overflow?cb=1 – GrafiCode Jan 19 '23 at 11:27
1

So for me the fix was to move the libraries files into the root folder like so:

The files in question were in PIL > .libs

enter image description here

Jack
  • 2,891
  • 11
  • 48
  • 65