[英]AWS Lambda not finding Shared Object File in Layer
I'm trying to create a Lambda function that runs Selenium tests in Java as part of a CI/CD pipeline in AWS.我正在尝试创建一个 Lambda function,它在 Java 中运行 Selenium 测试,作为 AWS 中 CI/CD 管道的一部分。 However, after the function installs Chromedriver, it fails because a.so file that Chromedriver requires is missing:
但是function安装完Chromedriver后失败,因为缺少Chromedriver需要的一个.so文件:
/tmp/chrome_driver7811961600494562711/chromedriver: error while loading shared libraries: libglib-2.0.so.0: cannot open shared object file: No such file or directory
I have read that you can include native libraries via Software Layers in Lambda, and I understand that you have to compile it in an Amazon Linux environment, as described here .我读到您可以通过 Lambda 中的软件层包含本机库,并且我知道您必须在 Amazon Linux 环境中编译它,如此处所述。
However, after zipping the file, and creating my layer, it's still not picking up the library, and giving the same error.然而,在压缩文件并创建我的层之后,它仍然没有选择库,并给出同样的错误。 I've also tried putting it in various directories in the zip file, like
/opt
, /opt/lib
, and also setting the LD_LIBRARY_PATH
variable in the function, but still no luck.我也试过将它放在 zip 文件的不同目录中,例如
/opt
、 /opt/lib
,并在 function 中设置LD_LIBRARY_PATH
变量,但仍然没有成功。 Any help appreciated.任何帮助表示赞赏。
OK, I finally figured it out.好的,我终于明白了。 After reading through more of the documentation, I found 2 key points:
在阅读了更多文档之后,我发现了 2 个关键点:
First, from https://docs.aws.amazon.com/lambda/latest/dg/configuration-envvars.html , the LD_LIBRARY_PATH
by default is set to:首先,从https://docs.aws.amazon.com/lambda/latest/dg/configuration-envvars.html 开始,
LD_LIBRARY_PATH
默认设置为:
/lib64:/usr/lib64:$LAMBDA_RUNTIME_DIR:$LAMBDA_RUNTIME_DIR/lib:$LAMBDA_TASK_ROOT:$LAMBDA_TASK_ROOT/lib:/opt/lib
And second, from https://docs.aws.amazon.com/lambda/latest/dg/configuration-layers.html#configuration-layers-path :其次,来自https://docs.aws.amazon.com/lambda/latest/dg/configuration-layers.html#configuration-layers-path :
Layers are extracted to the
/opt
directory in the function execution environment.图层解压到function执行环境的
/opt
目录下。
So putting these 2 facts together, I reasoned that if I put the dependencies in /lib
within the layer, they will end up in /opt/lib
, which is in LD_LIBRARY_PATH
, and voila - it worked.因此,将这两个事实放在一起,我推断如果我将依赖项放在层中的
/lib
中,它们将最终位于/opt/lib
中,它位于LD_LIBRARY_PATH
中,瞧 - 它起作用了。
I encountered this problem while trying to use pysodium, which relies on finding libsodium at runtime.我在尝试使用 pysodium 时遇到了这个问题,它依赖于在运行时查找 libsodium。
Even though libsodium was there in the LD_LIBRARY_PATH
, this line was still failing:即使 libsodium 在
LD_LIBRARY_PATH
中,这条线仍然失败:
sodium = ctypes.cdll.LoadLibrary(ctypes.util.find_library('sodium') or ctypes.util.find_library('libsodium'))
I ended up explicitly loading the library from the place where I'd put it (as a layer):我最终从我放置它的地方明确地加载了库(作为一层):
sodium = ctypes.cdll.LoadLibrary(
ctypes.util.find_library('sodium')
or ctypes.util.find_library('libsodium')
or "/opt/lib/libsodium.so" # layers are deployed here
)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.