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

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

import sys


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.