How to Update AWS EC2 with the Latest Code from GitHub

I successfully deployed a Django application on AWS EC2 and used the website without issues for a while. Recently, I made some changes to the site, updated the code on my GitHub repository, restarted the Nginx server, and visited my website. However, the changes didn’t reflect on the site.

Can anyone guide me on redeploying changes from GitHub to AWS and ensuring they take effect?

How did you get your code on EC2 the first time? A git pull? If so, then you need to run git pull again on the server to get the updated code.

Also, how are you running your code on your server? I’m assuming you’re using either gunicorn or uwsgi to actually run the Django code, in which case those are the processes that need to be restarted, not nginx.

Yes, I have run git pull origin master on the EC2 shell.

Let me try restarting gunicorn now

I ran these code

<!-- Run gunicorn once till terminal is closed -->
<!-- This code stopped the guncorn and restarted it -->
/home/ubuntu/env/bin/gunicorn --workers 3 --bind unix:/home/ubuntu/app_name/app.sock ecommerce_prj.wsgi:application

<!-- Run gunicorn even after server is closed -->
nohup /home/ubuntu/env/bin/gunicorn --workers 3 --bind unix:/home/ubuntu/app_name/app.sock ecommerce_prj.wsgi:application &

I don’t know if this is a better way to keep the server running; please, I need some advice on this.

You generally want this process run and managed by the operating system. The precise manner in which you would do this depends both upon what Linux distro you’re using and what other possible packages may be installed.

For example, you could install this as a systemd process. Or, you could run this using supervisord or runit. Use whatever process manager you’re familiar with.