'How to keep django rest API server running automatically on AWS?

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 1:[1]

You can make it live always by following means,

  • connect your ec2 instance using ssh.
  • Then deploy your backend (django) on that instance and run it at any port.
  • Once run on your desired port, you can close the terminal, please don't press ctrl+c so that your django server does not stop. you can just cross the terminal. it will be now running.

You can also run the django server on tmux (its terminal inside terminal). here is tutorial on tmux. https://linuxize.com/post/getting-started-with-tmux/

One other approach is, you can deploy the django using docker container.

I hope you will come over your problem.

Thanks.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 maadi