Deploying a Django app on AWS Lightsail: A Step-by-Step Guide

Posted by

How to Deploy a Django app to AWS Lightsail

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:

  1. Sign in to your AWS account and navigate to the Lightsail console.
  2. Create a new Lightsail instance and select the Django blueprint as your instance image.
  3. Give your instance a unique name and select an instance plan that meets your needs.
  4. Once your Lightsail instance is up and running, connect to it using SSH.
  5. Clone your Django app repository onto the Lightsail instance.
  6. Create a virtual environment for your Django app using the following command:
  7. python3 -m venv venv

  8. Activate the virtual environment by running:
  9. source venv/bin/activate

  10. Install the required dependencies for your Django app using pip:
  11. pip install -r requirements.txt

  12. Configure your Django app settings to run in production mode by setting DEBUG to False and specifying the ALLOWED_HOSTS.
  13. Collect static files for your Django app by running:
  14. python manage.py collectstatic

  15. Create a systemd service file to run your Django app as a service:
  16. [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

  17. Enable and start the systemd service:
  18. sudo systemctl enable your_django_service.service
    sudo systemctl start your_django_service.service

  19. Finally, open port 80 on your Lightsail instance and access your Django app in a web browser.

Congratulations! You have successfully deployed your Django app to AWS Lightsail. Your app is now accessible to users on the internet.

0 0 votes
Article Rating
10 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
@Sports-Made
5 months ago

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?

@rishabhdugar2
5 months ago

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

@dagneassefa4138
5 months ago

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👍

@ClearVista
5 months ago

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?

@yooujiin
5 months ago

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."

@user-qw7wh3fl7s
5 months ago

You are amazing!!

@tatemo_labs
5 months ago

Great effort! Thank you for sharing your knowledge.

@rommelrodriguez8376
5 months ago

Thanks, was waiting for this video. I attended the live, but still wanted to have this reference in case I forgot anything.

@williamsa51
5 months ago

Thanks very much for this. Sorry I missed it live.

@adammisiak4082
5 months ago

Thanks for the video!
What is the average cost of this kind of setup?