0

I'm trying to import papermill inside an AWS python lambda function. To to this, I first ran pip3 install papermill -t Desktop/python locally, zipped the python file and uploaded this as a lambda layer.

I am now getting this error:

{
  "errorMessage": "Unable to import module 'lambda_function': No module named 'rpds.rpds'",
  "errorType": "Runtime.ImportModuleError",
  "requestId": "7f217dbf-455f-4867-a5d6-8da1f3abd356",
  "stackTrace": []
}

I haven't been able to figure it out nor find any similar issues online. Below is an image of the rpds module available in the 'python' directory, if that's useful? :

enter image description here

I hope someone can help! Thanks.

  • 2
    Make sure that you have all the dependencies of papermill installed in your lambda layer, such as ipykernel, nbformat, nbconvert, etc. – Piyush Patil Aug 20 '23 at 11:34

1 Answers1

0

assuming you have a requirements.txt file and you use python 3.10 you can try to use this script to create a lambda layer with all of yours dependencies:

#!/bin/bash 
echo "create build venv"
rm -rf temp-venv
python3.10 -m venv temp-venv
source temp-venv/bin/activate

rm -rf dist
mkdir -p dist
pip install \
    --platform manylinux2014_x86_64 \
    --target=./dist/layer/python/lib/python3.10/site-packages \
    --implementation cp \
    --python-version 3.10 \
    --only-binary=:all: --upgrade \
    --no-compile \
    -r requirements.txt


cd dist/layer
zip -r ../dep_lambda_layer.zip .
cd ..
rm -rf layer
y. bs
  • 350
  • 3
  • 14
  • Thank you. Where would I run this? – Chad Goldsworthy Aug 20 '23 at 13:46
  • where your requirements.txt file found. after you run this you will see a dist folder with "dep_lambda_layer.zip" file inside of it. use this zip as your lambda layer (uploade itvia console/ aws cli) – y. bs Aug 21 '23 at 05:13