I am deploying a lambda function as a container image. Here's my project structure :
All three are at the same level - /var/task
Inside lambda_handler.py I am importing the core package, but when I test it locally it says :
"errorMessage": "Unable to import module 'lambda_handler': No module named 'core'"
Dockerfile
FROM public.ecr.aws/lambda/python:3.9
# Copy requirements to container
COPY requirements.txt .
# install dependencies
RUN pip3 install -r requirements.txt --target "${LAMBDA_TASK_ROOT}"
# Copy app folders to container
COPY core ${LAMBDA_TASK_ROOT}
COPY plugins ${LAMBDA_TASK_ROOT}
COPY lambda_handler.py ${LAMBDA_TASK_ROOT}
COPY __init__.py ${LAMBDA_TASK_ROOT}
CMD ["lambda_handler.lambda_fun"]
lambda_handler.py
import json
from core.nlp.service import nlp_service
def lambda_fun(event, context):
return json.dumps(nlp_service.get_ner())
requirements.txt
pyspark==3.1.2
spacy
pymupdf
boto3
cloudpathlib
spark-nlp==3.4.1
numpy
If you just use
COPY core ${LAMBDA_TASK_ROOT}
it will copy the content of the core into ${LAMBDA_TASK_ROOT}. To copy into core folder, it should be:
COPY core ${LAMBDA_TASK_ROOT}/core
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With