The Fake Dev

Importing a Python package in an AWS Lambda from a Lambda Layer

September 24, 2022

If you have a lambda layer with a package named “X”, at the top of your function, write:

import sys

sys.path.append('/opt/X/')

AWS attaches the layer under the /opt directory. The above code adds that to the list of directories that the Python interpreter will search through when trying to find packages.


Profile picture

Written by a dev who lives on planet Earth.