Hi,
I have a problem when using RSAKey.from_private_key_file. I followed the steps in this tutorial (https://aws.amazon.com/blogs/compute/scheduling-ssh-jobs-using-aws-lambda/)
The code is like that:
import boto3
import paramiko
def worker_handler(event, context):
s3_client = boto3.client('s3')
#Download private key file from secure S3 bucket
s3_client.download_file('s3-bucket-with-key','keys/devenv-key.pem', '/tmp/devenv-key.pem')
k = paramiko.RSAKey.from_private_key_file("/tmp/devenv-key.pem")
...
And this is the error message:
/var/task/cryptography/hazmat/bindings/_constant_time.so: invalid ELF header: ImportError Traceback (most recent call last): File "/var/task/worker_function.py", line 9, in worker_handler
k = paramiko.RSAKey.from_private_key_file("/tmp/devenv-key.pem")
File "/var/task/paramiko/pkey.py", line 196, in from_private_key_file key = cls(filename=filename, password=password)
File "/var/task/paramiko/rsakey.py", line 45, in __init__
self._from_private_key_file(filename, password)
File "/var/task/paramiko/rsakey.py", line 164, in _from_private_key_file
self._decode_key(data)
File "/var/task/paramiko/rsakey.py", line 173, in _decode_key
data, password=None, backend=default_backend()
File "/var/task/cryptography/hazmat/backends/__init__.py", line 35, in default_backend _default_backend = MultiBackend(_available_backends())
File "/var/task/cryptography/hazmat/backends/__init__.py", line 22, in _available_backends "cryptography.backends"
File "/var/task/pkg_resources/__init__.py", line 2235, in resolve module = __import__(self.module_name, fromlist=['__name__'], level=0)
File "/var/task/cryptography/hazmat/backends/commoncrypto/__init__.py", line 7, in <module>
from cryptography.hazmat.backends.commoncrypto.backend import backend
File "/var/task/cryptography/hazmat/backends/commoncrypto/backend.py", line 11, in <module> from cryptography.hazmat.backends.commoncrypto.ciphers import ( File "/var/task/cryptography/hazmat/backends/commoncrypto/ciphers.py", line 11, in <module>
from cryptography.hazmat.primitives import ciphers, constant_time
File "/var/task/cryptography/hazmat/primitives/constant_time.py", line 9, in <module> from cryptography.hazmat.bindings._constant_time import lib
ImportError: /var/task/cryptography/hazmat/bindings/_constant_time.so: invalid ELF header
Thanks in advanced, hope someone can help me.
I opened the VPC subnet and security group for the Lambda function. The error message disappear, but my connection still can't be built. The program just stop there, without any output.
Offhand sounds to me like something might be broken with your cryptography install, ELF header errors (in my experience) typically mean something compiled incorrectly. I don't believe there is anything Paramiko can do here.
I'd check out their website (https://cryptography.io) and/or their Github tracker (https://github.com/pyca/cryptography). Good luck!
If you like me using MacOS or Linux other than RedHat based linux, or something similar, you may ran into this problem that paramiko compiled on different platform.
Lambda use AWS Linux as base machine so it will not run on Lambda if you install and pack your code with paramiko library on your Mac.
Source: Helpful solution
Not really helpful one but still have some information
Most helpful comment
If you like me using MacOS or Linux other than RedHat based linux, or something similar, you may ran into this problem that paramiko compiled on different platform.
Lambda use AWS Linux as base machine so it will not run on Lambda if you install and pack your code with paramiko library on your Mac.
Source: Helpful solution
Not really helpful one but still have some information