Deploying Python FastAPI to AWS Beanstalk
Question:
I have a small python FastAPI project which is completely working on my local computer. But when I try to deploy it to AWS Beanstalk (manually for now) I’ve always got a ‘502 Bad Gateway’ error when open the application in a browser.
This is my project structure:
/project
/html/
main.py
Procfile
requirements.txt
the main.py
contains the api endpoints that use some HTML files. These files are in the html/
folder.
The Procfile
looks like this:
web: uvicorn main:app --host 0.0.0.0 --port 80
and the requirements.txt
like this:
fastapi~=0.91.0
uvicorn
When I uploaded an example application from AWS to the same Beanstalk environment, it worked. And as I said, even if I execute the python project locally, it works fine. So I must have configured something wrong.
Does anybody know this problem and know how to fix it?
Answers:
Found this useful guide that solved my problem: https://testdriven.io/blog/fastapi-elastic-beanstalk/.
Maybe there is someone who needs it.
I have a small python FastAPI project which is completely working on my local computer. But when I try to deploy it to AWS Beanstalk (manually for now) I’ve always got a ‘502 Bad Gateway’ error when open the application in a browser.
This is my project structure:
/project
/html/
main.py
Procfile
requirements.txt
the main.py
contains the api endpoints that use some HTML files. These files are in the html/
folder.
The Procfile
looks like this:
web: uvicorn main:app --host 0.0.0.0 --port 80
and the requirements.txt
like this:
fastapi~=0.91.0
uvicorn
When I uploaded an example application from AWS to the same Beanstalk environment, it worked. And as I said, even if I execute the python project locally, it works fine. So I must have configured something wrong.
Does anybody know this problem and know how to fix it?
Found this useful guide that solved my problem: https://testdriven.io/blog/fastapi-elastic-beanstalk/.
Maybe there is someone who needs it.