Explore Courses Blog Tutorials Interview Questions
0 votes
in AWS by (19.1k points)

So I'm trying to create an aws lambda function, to log in to an instance and do some stuff. And the script works fine outside of lambda, but when I package it using the same instructions as this it doesn't work. It throws this error. cannot open shared object file: No such file or directory: ImportError

Traceback (most recent call last):

  File "/var/task/", line 12, in lambda_handler

    key = paramiko.RSAKey.from_private_key(key)

  File "/var/task/paramiko/", line 217, in from_private_key

    key = cls(file_obj=file_obj, password=password)

  File "/var/task/paramiko/", line 42, in __init__

    self._from_private_key(file_obj, password)

  File "/var/task/paramiko/", line 168, in _from_private_key


  File "/var/task/paramiko/", line 173, in _decode_key

    data, password=None, backend=default_backend()

  File "/var/task/cryptography/hazmat/backends/", line 35, in default_backend

    _default_backend = MultiBackend(_available_backends())

  File "/var/task/cryptography/hazmat/backends/", line 22, in _available_backends


  File "/var/task/pkg_resources/", line 2236, in resolve

    module = __import__(self.module_name, fromlist=['__name__'], level=0)

  File "/var/task/cryptography/hazmat/backends/openssl/", line 7, in <module>

    from cryptography.hazmat.backends.openssl.backend import backend

  File "/var/task/cryptography/hazmat/backends/openssl/", line 15, in <module>

    from cryptography import utils, x509

  File "/var/task/cryptography/x509/", line 7, in <module>

    from cryptography.x509.base import (

  File "/var/task/cryptography/x509/", line 15, in <module>

    from cryptography.x509.extensions import Extension, ExtensionType

  File "/var/task/cryptography/x509/", line 19, in <module>

    from cryptography.hazmat.primitives import constant_time, serialization

  File "/var/task/cryptography/hazmat/primitives/", line 9, in <module>

    from cryptography.hazmat.bindings._constant_time import lib

ImportError: cannot open shared object file: No such file or directory

1 Answer

0 votes
by (44.4k points)

In the tutorial, the ZIP commands are missing a parameter, I bumped into this exact problem today with pysftp, which is made on paramiko. is in a hidden dot directory within lib64/python2.7/site-packages/.libs_cffi_backend. Depending on how you zipped up the dependencies in your virtualenv, you may have inadvertently excluded this directory.

1. First, make sure libffi-devel and openssl-devel are installed on your Amazon Linux instance, otherwise, the cryptography module may not be compiled correctly.

sudo yum install libffi-devel openssl-devel

If those packages weren't installed before, delete and rebuild your virtualenv.

2. Make sure that after you are zipping up your site-packages that you use '.' rather than '*', otherwise, you may not be including files and directories that are hidden due to their names begin with a period.

cd path/to/my/helloworld-env/lib/python2.7/site-packages

zip -r9 path/to/zip/ .

cd path/to/my/helloworld-env/lib64/python2.7/site-packages

zip -r9 path/to/zip/ .

Related questions

0 votes
1 answer

Want to get 50% Hike on your Salary?

Learn how we helped 50,000+ professionals like you !

Browse Categories