#๐Ÿ”’ Python Docker Lambda Import error

4 messages ยท Page 1 of 1 (latest)

wanton raptor
#

Hey guys,

This is my setup:

โ”œโ”€โ”€โ”€ src
โ”‚      โ”œโ”€โ”€ api
โ”‚      โ”‚   โ”œโ”€โ”€ deals.py
โ”‚      โ”‚   โ”œโ”€โ”€ messaging.py
โ”‚      โ”‚   โ”œโ”€โ”€ users.py
โ”‚      โ”‚   โ”œโ”€โ”€ __init__.py
โ”‚      โ”‚   โ”œโ”€โ”€ models
โ”‚      โ”‚   โ”‚   โ”œโ”€โ”€ chatbot.py
โ”‚      โ”‚   โ”‚   โ”œโ”€โ”€ deals.py
โ”‚      โ”‚   โ”‚   โ”œโ”€โ”€ users.py
โ”‚      โ”‚   โ”‚   โ”œโ”€โ”€ __init__.py
โ”‚      โ”‚   โ”‚   โ””โ”€โ”€ utility.py
โ”‚      โ”‚   โ””โ”€โ”€ utility
โ”‚      โ”‚       โ”œโ”€โ”€ __init__.py
โ”‚      โ”‚       โ””โ”€โ”€ utility.py
โ”‚      โ””โ”€โ”€ lambda_function.py
โ”œโ”€โ”€ Dockerfile
โ””โ”€โ”€ requirements.txt

This is my dockerfile:

FROM public.ecr.aws/lambda/python:3.11

COPY requirements.txt ${LAMBDA_TASK_ROOT}

RUN pip install -r requirements.txt

COPY src/ ${LAMBDA_TASK_ROOT}/

CMD [ "lambda_function.lambda_handler" ]

This is my lambda_function.py:

from api.users import register,
def lambda_handler(event, context):
  ...

This is my api.users.py:

from models.users import add_user_to_db
@handle_errors
def register(event, context):
 ...

This error I get:

[ERROR] Runtime.ImportModuleError: Unable to import module 'lambda_function': No module named 'models'

Why this happens? Thank you ๐Ÿ˜„

sacred portalBOT
#

@wanton raptor

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

sacred portalBOT
#

@wanton raptor

Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.