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.
Related
I am building a web app with a Flask backend and a React front end, and I would now like to deploy it, buy a domain, and set it up. What is the easiest way to do this?
Here's my research:
This website shows how to deploy an app on Heroku. I did this, but Heroku seems to be unavailable a lot, at least today.
This blog post seems to suggest I could create a GCE instance and run things there, though (i) it seems like a little more configuration that I'd like (ii) I would need a way to link the nginx server to my domain. I suppose the benefit is that the two apps run on the same machine?
This SO post had OP redo his work and it somehow worked. I'm not sure how to deploy Docker apps online, though.
Is there an easy way to deploy to a reliable service (Google Cloud/AWS/Azure)? My code has the following structure:
build/ # Result of `yarn build`
server/
server.py # Flask server
src/ # React code
Component/
Component.js
Component.sass
index.css
index.js
...
public/
index.html
# Images and other stuff.
I figured out how to do this using Azure. I created an App Service, then installed the Azure Tools VS Code extension. You need to move the Python server to the root directory and rename it to app.py (so the .env is also in the root folder), and then you can right-click your App Service in VS Code (in the Azure Tools tab) and then click Deploy to Web App. Easy!
Any help would be much appreciated. I created a repository here where all files are linked. I'm currently trying to learn how to deploy an ML model to Heroku. This is a pretty simple model and I was following along with a YouTube tutorial. When I run 'python app.py' on my terminal, the local server does run correctly, showing the exact interface I want.
When trying to deploy it on Heroku, I linked my GitHub repository and selected 'Deploy Branch'; Here, Heroku states that the app was successfully deployed. HOWEVER, when I then try to view, a page comes up stating Application Error.
As mentioned, I'm really not sure what's going wrong and would appreciate any guidance to get this working – I'd like to deploy other ML models I've been working on and getting this preliminary one running would be a huge help. Any advice?
Thanks!
It seems like you have forgotten to create the Procfile. This is necessary for Heroku as it tells Heroku how to startup your application on it's servers.
Since you're server file is app.py and the Flask app is app as well, the following would be the contents of the Procfile
web: gunicorn app:app
Also update your requirements.txt file by adding gunicorn, as an example what i had was
gunicorn==20.1.0
For more information about the Procfile see https://devcenter.heroku.com/articles/procfile
I have deployed this personally and it works fine now 😁
I want to deploy my website which works locally, but runs an error when it tries to have a public instance.
I am on Windows 8.1 and following the official instructions have created a Procfile.windows. It looks like this:
web: python app.py runserver 0.0.0.0:5000
The build works, but then I get this error when I run heroku ps:scale web=1:
Couldn't find that process type (web).
Repo here.
The official tutorial works, so there's definitely proof of concept of this working somehow.
I am on Windows 8.1 and following the official instructions have created a Procfile.windows
Why did you name this file Procfile.windows? The documentation is quite clear:
The Procfile is always a simple text file that is named Procfile without a file extension. For example, Procfile.txt is not valid.
Rename it to Procfile and redeploy.
Once you've got that working, install a WSGI server and use that instead of manage.py runserver, which isn't suitable for production use:
DO NOT USE THIS SERVER IN A PRODUCTION SETTING. It has not gone through security audits or performance tests. (And that’s how it’s gonna stay. We’re in the business of making Web frameworks, not Web servers, so improving this server to be able to handle a production environment is outside the scope of Django.)
Gunicorn is probably the most common choice, but I don't think it works on Windows so you won't be able to use it in your development environment. uWSGI or Waitress should work.
I installed Waitress and changed my Procfile to
web: waitress-serve --port=$PORT app:app
I also removed the .windows extension, which is meant for local development.
It works fine now!
(My equivalent to "main.py" was "app.py" so you'd likely change this for your needs to {main.py}:app)
Edit your procfile to look like
web: gunicorn --bind 0.0.0.0:$PORT app:app
And your procfile.windows filed as
web: python app.py runserver 0.0.0.0:5000
I'm having some troubles deploying this app on Heroku. The code is on a folder, where i created a git using git init, added everything to my git and then pushed everything to Heroku before running it.
I generated my requirements.txtand my procfile looks like this:
test: python "application.py" heroku ps:scale web=1
But on my webpage nothing will load, i'm assuming because i'm only running the Python part. How can i deploy it so that Heroku will know to run not only my Python script, but also the frontend part with the javascript and index.html files?
For development, you can serve static files with Flask.
For production, use cloud CDN (like Amazon's or Google's) or add a web-server to your app (Nginx or Apache or whatever).
I have built a simple blog app with Django by following a video and deployed it to Heroku by following another video.
The app works fine locally, but it is not working online.
Heroku gives me this error message:
This app has no process types yet
Add a Procfile to your app in order to define its process types.
I had already added a Proclife created with Notepad with these contents:
web: gunicorn mysite.wsgi
But how can I add another Procfile to an app already deployed to Heroku?
Where should I place it?
Yeah that's correct. It required file 'Procfile' in the project root directory. I have created one with below content
web: gunicorn <your-app.wsgi> -b 0.0.0.0:$PORT -w 10
And followed the below link https://devcenter.heroku.com/articles/procfile where everything is mentioned to deploy the code to heroku.
Its been long time for me working with heroku that too with test app so I am not sure if it got changed after that. But I think just following the link will work just fine.