Thursday, March 17, 2022

[SOLVED] How to keep django rest API server running automatically on AWS?

Issue

So I uploaded my Django API with Rest framework on AWS EC2 instance. However, I have to manually go to Putty and connect to my EC2 instance and turn API on whenever I want to use it by inputting python manage.py runserver 0.0.0.0:8000.

When I turn off my PC, putty closes and API cannot be accessed anymore on the ip address.

How do I keep my API on forever? Does turning it into https help? Or what can be done?


Solution

Ok I finally solved this. So when you close putty or a ssh client session, the session goes offline. However, if you run the session via daemon, the session continues in the background even when you close your clients. The code is

$ nohup python ./manage.py runserver 0.0.0.0:8000 & 

Of course you can use tmux or docker, as suggested by madi, but I think running this one code is much simpler.



Answered By - newbie81240
Answer Checked By - Candace Johnson (WPSolving Volunteer)