How to Deploy Django Application in AWS EC2?
Last Updated :
21 Aug, 2023
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.
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.
.png)
Step 2: Make sure you allow HTTP traffic to the instance . You can also allow HTTPS if you want.
.png)
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
.png)
- Below is urls.py for the project
.png)
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.
.png)
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.
Similar Reads
How to Deploy Django Application in AWS Lambda? Pre-requisite: AWS , Python Django is a Python web framework that makes it easy to build web applications quickly and securely. It has a large and helpful community that provides support and contributes to its development. AWS Lambda is a serverless computing platform that runs your code in Docker c
7 min read
How To Deploy Python Application In AWS? In this article, we will explore how one as a Python developer can deploy the application by harnessing the capabilities of AWS. AWS, a leading cloud computing platform, offers a wide range of services to help developers build, deploy, and manage applications at scale EC2. It provides scalable compu
4 min read
Django Web Application Deployment On AWS EC2 With Windows Server 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 have knowledge about setting up EC2 in AWS. So let's proceed
4 min read
How to Deploy a Django Application in Kubernetes In this article, we will study how we can deploy Django web applications to Kubernetes. We will also see how to dockerize and build an image of the Django application using Dockerfile. For this article, you should know about setting up a VM in Azure. We will see how to deploy applications on Linux S
5 min read
Deploy an ASGI Django Application ASGI, which stands for Asynchronous Server Gateway Interface, is a big deal in Django. It basically helps Django handle lots of things at once, like requests from users. Instead of waiting for one thing to finish before starting the next, ASGI lets Django do multiple tasks simultaneously. It's like
5 min read