Sunday, October 9, 2022

[SOLVED] how to keep running my fastapi app even I close my aws terminal

Issue

I deploy my fast api on aws ec2 but the problem is I need to manually run python3 -m uvicorn main:app for start my fastapi app and if I close the terminal my fastapi app are not accessible from aws public ip.

here is ngnix config:

server {
    listen 80;   
    server_name aws ip;    
    location / {        
        proxy_pass http://127.0.0.1:8000;    
    }
}

Solution

You can use tmux or screen to start a long running process as described here: keep server running on EC2 instance after ssh is terminated.

These sessions will persist even after the terminal is closed.

If you need a more resilient solution (e.g. automatic restarts on failure, logging, etc.), I would look into using AWS Elastic Container Service (ECS). This will handle scaling, restarts, logging, and much more.



Answered By - Jeremypleb
Answer Checked By - Marie Seifert (WPSolving Admin)