I have a SAM app with multiple Lambdas and some utility code I'd like to share between them. When packaging Lambdas using zip files, code sharing can be done with Lambda Layers. However, according to the AWS documentation, Lambda Layers are not supported when using containers.
Functions defined as container images do not support layers. When you build a container image, you can package your preferred runtimes and dependencies as a part of the image
I've tried copying my dependencies into a separate docker image, then pulling from that image in my lambda dockerfile, which is suggested in the AWS blog post Working with Lambda layers and extensions in container images. However, I just get the Unable to import module 'app': No module named '<my_dependency>'
error when trying to debug or run sam local invoke
. I verified in my final image that the dependencies are in the /opt/python/
directory for my python lambda, and tried other folder structure as well, but no luck.
Has anyone been able to get this to work?