Steps to Deploy Django Application in AWS EC2 with Ubuntu Server

Step 1: First, we have to create an Amazon EC2 instance running any Linux distribution of your choice. Under launch instance on AWS give your instance a name and select Ubuntu Server as OS. Specify other options as per your choice.

Step 2: Make sure you allow HTTP traffic to the instance . You can also allow HTTPS if you want.

Step 3: After specifying all options correctly click launch instance. Once the instance is started successfully copy the public IP address assigned you will need it later. You may have assigned an elastic ip address which is also fine. Connect to the instance using PuTTY or OpenSSH.Once you connect to the instance download and install Python and other Django requirements according to your project. Ubuntu may have already installed Python. If it is not there install it using the below command.

sudo apt install python3

Step 4: Install nginx using the below command.

sudo apt install nginx
  • After installing Python add your project to the instance or you can create a new project. For the tutorial, I have created a simple Django project that displays “Hello World” on the home page route.
  • Here is the views.py file for the project

  • Below is urls.py for the project

Step 6: Start the server to test the application. Note down the address at which the server is started by default it is 127.0.0.1:8000. You should be able to access the page at 127.0.0.1:8000/home.

How to Deploy Django Application in AWS EC2?

In this article, we will study how we can deploy our existing Django web application to Windows Server in AWS EC2. We will also see how to use the public IP of the EC2 instance to access the Django application. For this article, you should know about setting up EC2 in AWS. We will see how to deploy applications on Linux As Well as Windows OS.

Similar Reads

Introduction to Django

Django is a Python framework for developing and building web applications in Python. It supports rapid development and Scalability. It follows MVC architecture for developing web apps. You can read more about Django in this article what is Django?...

Benefits of Deploying Django Applications on EC2

Amazon EC2 provides a simple and efficient option for the deployment of applications It supports high scalability and throughput. It can be scaled up or down as per requirement. Supports different OS for deployment....

Steps to Deploy Django Application in AWS EC2 with Ubuntu Server

Step 1: First, we have to create an Amazon EC2 instance running any Linux distribution of your choice. Under launch instance on AWS give your instance a name and select Ubuntu Server as OS. Specify other options as per your choice....

Troubleshooting

If you can’t access the landing page make sure your Nginx server is allowed on the firewall. If not add Nginx to the allowed apps in the firewall. If you get an access denied error make sure HTTP access is enabled for the EC2 instance....

FAQs On Django Application in AWS EC2

1. Can We Deploy Django On Lambda?...