Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 23160

Having diffuclties deploying my fast-api to aws lambda?

$
0
0

this is the code which i am trying to host on AWS, ->[https://github.com/Husseinmdarman/BookContentToYoutubeVideos][code base]

However for the life of me I am struggling, so what i have tried to do is create a lambda function on AWS then once that was created, the mangum handler which is wrapped around my fast-api app

with in my main.py file I have the following code written to handle all the lambda wrapping

app = FastAPI()handler = Mangum(app)

Now on AWS lambda you would have to configure the handler, so through reading i assumed since my file is main.py and the handler is just called handler, that i would be okay to just select main.handler. However the problems i soon ran into were

{"errorMessage": "Unable to import module 'main': No module named 'main'","errorType": "Runtime.ImportModuleError","requestId": "3f597b25-74db-4db5-9c9a-788782883812","stackTrace": []}

Could it be because i'm just directly ziping up my code base and uploading a zip on to lambda, the only issue I cannot see on the inline code bit because my zipped file is 8mb, yeah i believe it might be the way i zipped my files, i jsut ran the normal compress on windows [Update this didn't work]

So instead what i tried was

  1. pip freeze > requirements.txt
  2. Then went to my WSL terminal and did sudo apt install python3-pip
  3. (cd dep; zip ../lambda_artifact.zip -r .) which downloads all the external dependaces and zips it into a lambda artifact4.zip lambda_artifact.zip -u main.py Then added my main file to the artifact, same way with all my other .py files

Now the new error i'm getting is

"Unable to import module 'main': No module named 'pydantic_core._pydantic_core'",

which suggests that there is not _pydantic_core but when i have a look at the installed dependicies i do see it in the folder

dependcies

By checking the lambda zip, I can see it in there toolambda zip


Viewing all articles
Browse latest Browse all 23160

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>