Skip to content

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



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

First, from, the LD_LIBRARY_PATH by default is set to:


And second, from :

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