本文介绍了Lamnda Python 3.8 GPG解密找不到gpg二进制文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用lambda函数来解密S3上的文件,我下载了文件没有问题,但是当我尝试对它们进行解密时,找不到gpg.我曾尝试同时使用 python-gnupg gnupg ,但是都没有提到gnupg在操作系统上不可用.在我的以下代码中,用于在python中识别GPG它在python 3.7上运行良好,但是如果我升级到3.8,Lambda使用AMazon Linux 2,而后者不是gpg附带的.我如何才能在Lambda中使用python 3.8来实现cna?

I'm trying to use a lambda function to decrypt files coming to S3, I download the files without issues, but when I try to decrypt them the gpg can not be found. I;ve tried using both python-gnupg and gnupg but both failed mentioning that gnupg is not available on the OS. Below my code for isntantiating GPG in pythonIt works well with python 3.7, but if I upgrade to 3.8, Lambda uses AMazon Linux 2, which doesn't come with gpg. How cna I make it work with python 3.8 in Lambda?

gpg = gnupg.GPG(gnupghome ='/tmp')

错误:

OSError: Unable to run gpg (gnupg) - it may not be available

我发现的所有示例似乎都没有做任何额外的事情.我正在为我的函数包装python-gnugp包和所有其他python包

All the examples I've found don't seem to do anything extra. I'm packaging the python-gnugp package and all other python packages for my function

Lambda中是否提供gpg二进制文件?我该如何进行这项工作?

is the gpg binary available in Lambda? how can I make this work?

推荐答案

您必须捆绑gpg二进制文件及其依赖项,并将其交付到您的包中.在我的程序包中,我将它们捆绑到一个名为"gpg"的文件夹中,然后当我在Lambda函数中使用gpg时,我会这样做:

You have to bundle the gpg binary and its dependencies and deliver them in your package. In my package i bundle them into a folder named 'gpg', then when I use gpg in my Lambda function, I do this:

def lambda_handler(event, context):
    old = os.environ.get("LD_LIBRARY_PATH")
    if old:
        os.environ["LD_LIBRARY_PATH"] = "./gpg" + ":" + old
    else:
        os.environ["LD_LIBRARY_PATH"] = "./gpg"

    gpg = gnupg.GPG(gnupghome='/tmp', gpgbinary='./gpg/gpg2', verbose=False)

这篇关于Lamnda Python 3.8 GPG解密找不到gpg二进制文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-22 17:28