Skip to content
Advertisement

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. However, after the function installs Chromedriver, it fails because a .so file that Chromedriver requires is missing:

/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.

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. Any help appreciated.

Advertisement

Answer

OK, I finally figured it out. After reading through more of the documentation, I found 2 key points:

First, from https://docs.aws.amazon.com/lambda/latest/dg/configuration-envvars.html, the LD_LIBRARY_PATH by default is set to:

/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 :

Layers are extracted to the /opt directory in the function execution environment.

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.

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement