本文介绍了Lambda未加载密码共享库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用AWS Lambda中的加密库.我已经在Amazon Linux VM中使用pip编译了软件包.我已将该包上传为一层.无论哪种方式,每次调用库时,都会出现一个根本无法描述的错误:

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

如您所见,错误不是找不到lib,而是另一个我找不到的共享模块.

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.

这是我尝试在Lambda上执行的代码的示例:

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"))

这不是我第一次编译可在AWS Lambda上使用的库,但在这种情况下,即使是我也编译了加密库.我应该添加或更改什么?

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?

我发现该库在我创建的zip文件中丢失了,就像在一个隐藏文件夹中一样.我使用'.'压缩.而不是'*',但是现在我遇到了一个新问题,当我运行lambda时,我得到了:

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 got this:

Unable to import module 'lambda_function': /opt/cryptography/hazmat/bindings/_constant_time.so: undefined symbol: PyInt_FromLong

有什么主意吗?

推荐答案

即使我遇到了同样的问题,在压缩时我也忘记了将隐藏文件(.libs_cffi_backend)包含在站点包中.包含它之后,我没有看到此错误.

Even I faced the same issue, while zipping I forgot to include the hidden files(.libs_cffi_backend) in the site-packages.After Including it, I didn't see this error.

这篇关于Lambda未加载密码共享库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-06 11:32