How to Deploy a Django app to AWS Lightsail
Deploying a Django app to AWS Lightsail is a great way to host your application in a scalable and reliable environment. Follow these steps to deploy your Django app to AWS Lightsail:
- Sign in to your AWS account and navigate to the Lightsail console.
- Create a new Lightsail instance and select the Django blueprint as your instance image.
- Give your instance a unique name and select an instance plan that meets your needs.
- Once your Lightsail instance is up and running, connect to it using SSH.
- Clone your Django app repository onto the Lightsail instance.
- Create a virtual environment for your Django app using the following command:
- Activate the virtual environment by running:
- Install the required dependencies for your Django app using pip:
- Configure your Django app settings to run in production mode by setting DEBUG to False and specifying the ALLOWED_HOSTS.
- Collect static files for your Django app by running:
- Create a systemd service file to run your Django app as a service:
- Enable and start the systemd service:
- Finally, open port 80 on your Lightsail instance and access your Django app in a web browser.
python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt
python manage.py collectstatic
[Unit]
Description=Django Application
[Service]
Type=simple
WorkingDirectory=/path/to/your/django/app
ExecStart=/path/to/your/venv/bin/python manage.py runserver 0.0.0.0:8000
[Install]
WantedBy=multi-user.target
sudo systemctl enable your_django_service.service
sudo systemctl start your_django_service.service
Congratulations! You have successfully deployed your Django app to AWS Lightsail. Your app is now accessible to users on the internet.
si was was running a django app using rds, ec2, load balancers etc.. but it was just too expensive… How is deploying to lightsail cost? wat monthly cost are we looking at?
I am facing an issue, it states:
exec /scripts/run.sh: no such file or directory
Please help me understand the issue and the way to resolve it
Thank you for this excellent video. You answered all of the questions that would have taken me weeks or even months to research. Thank you again👍
So I'm going through this with my own project and I'm getting the following error when trying to do my first "migrate"
django.db.utils.OperationalError: connection to server on socket "/tmp/.s.PGSQL.5432" failed: No such file or directory
Is the server running locally and accepting connections on that socket?
At the end, I get this error when creating superuser "[15/May/2023:19:49:40] Superuser created successfully.
[15/May/2023:19:50:00] [deployment:14] Started 1 new node
[15/May/2023:19:50:23] CommandError: Error: That username is already taken.
[15/May/2023:19:51:29] [deployment:14] Started 1 new node
[15/May/2023:19:51:54] CommandError: Error: That username is already taken" …
"Forbidden (403)
CSRF verification failed. Request aborted.
More information is available with DEBUG=True."
You are amazing!!
Great effort! Thank you for sharing your knowledge.
Thanks, was waiting for this video. I attended the live, but still wanted to have this reference in case I forgot anything.
Thanks very much for this. Sorry I missed it live.
Thanks for the video!
What is the average cost of this kind of setup?