{"Unable to import module 'main': No module named 'main'", "errorType": "Runtime.ImportModuleError"} in Docker for Lambda (FAST API)

Viewed 490

I have created a Fastapi and now trying to deploy it using Docker container to AWS lambda. but there is a error:

{"errorMessage": "Unable to import module 'main': No module named 'main'", "errorType": "Runtime.ImportModuleError", "stackTrace": []}

I have tried everything I could. This is my main.py file:

from fastapi import FastAPI
from starlette.status import HTTP_302_FOUND,HTTP_303_SEE_OTHER
import spacy
from string import punctuation
from mangum import Mangum
import uvicorn
app = FastAPI()

@app.get('/')
def home():
    return {"answer":"Hello World"}

@app.get('/tags')
def prep_data(text):
    tag = tokens(text, nlp)
    tags = getdict(tag)
    return {
        'tags':tags
    }

handler = Mangum(app)
if __name__ == "__main__":
    # handler = Mangum(app)
    uvicorn.run('main:app', host='0.0.0.0', port=8000, reload=False, root_path="/")

The error is idicating towards the main.py file that there is no main.py file, As you can see the dockerfile:

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

COPY ./app /app

COPY ./requirements.txt /app/requirements.txt

WORKDIR /app

RUN pip install -r requirements.txt

CMD ["main.handler"]

My directory structure is like:

/app
    main.py
Dockerfile
requirements.txt
0 Answers
Related