我正在使用 AWS Lambda 中的加密库。我已在 Amazon Linux VM 中使用 pip 编译了该包。我已将包作为图层上传。不管怎样,每次我调用库时,我都会遇到一个根本不具有描述性的错误:
Unable to import module 'lambda_function': libffi-ae16d830.so.6.0.4: cannot open shared object file: No such file or directory
Run Code Online (Sandbox Code Playgroud)
正如您所看到的,错误不是因为找不到库,而是因为我找不到另一个共享模块。
以下是我尝试在 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 …Run Code Online (Sandbox Code Playgroud)