I'm using the cryptography library in AWS Lambda. I've compiled the package using pip in an Amazon Linux VM. I have uploaded the package as a layer. Either way, every time I call the library, I have an error which is not descriptive at all:
Unable to import module 'lambda_function': libffi-ae16d830.so.6.0.4: cannot open shared object file: No such file or directory
As you can see, the error is not about not finding the lib, is another shared module which I haven't been able to find.
Here's an example of the code I'm trying to execute on Lambda:
from cryptography.hazmat.backends import default_backend
from cryptography.hazmat.primitives import hashes
from cryptography.hazmat.primitives.kdf.pbkdf2 import PBKDF2HMAC
from cryptography.fernet import Fernet
password_provided = "test123"
password = password_provided.encode()
salt = b'test_'
kdf = PBKDF2HMAC(
algorithm=hashes.SHA256(),
length=32,
salt=salt,
iterations=100000,
backend=default_backend()
)
key = base64.urlsafe_b64encode(kdf.derive(password))
message = "message from db".encode()
f = Fernet(key)
encrypted = f.encrypt(message)
print(encrypted)
f = Fernet(key)
decrypted = f.decrypt(encrypted)
print(decrypted.decode("utf-8"))
It's not the first time I've compiled a library to work on AWS Lambda, but in this case even I compile the cryptography lib. What should I add or change?
Edit: I've found out the library was missing in the zip file I've created, as is inside a hidden folder. I zipped using '.' instead of '*' but now I'm running with a new problem: When I run the lambda, I get this:
Unable to import module 'lambda_function': /opt/cryptography/hazmat/bindings/_constant_time.so: undefined symbol: PyInt_FromLong
any idea?