I have an aws lambda function which has dependency on my layer, dep_1. This dep_1 layer is built from a zip called dep.zip in s3. The structure of dep_1 is:
dep.zip
|
|-python
|
|-pandas
|-pandas.1.03.dist-info
|-pkg_2
|-pkg_2.version.dist-info
|-pkg_3
|-...
In my lambda function handler file my_lambda.py, I use import pandas as pd and it fails, saying "Unable to import module 'my_lambda': No module named 'pandas'"
I had followed the official documentation, yet it fails. Documentation.
I happened across a fix. When I simply add another lambda layer with a later merge order, then the first layer starts working and I can import the modules of it. The contents of the second lambda are throwaway; I don't need them, but I make sure they don't interfere with the contents of my first lambda. So in other words, the second layer contains a module that has nothing to do with pandas, yet only after I add it can I import pandas.
What is happening in aws' merging of the layers to get this working? Do I have my directory structure correct in layer one? I can't inspect it in the lambda, because aws puts all the modules in /opt.