DEV Community 👩‍💻👨‍💻

Cover image for Deploy My-Shopping-Mart Django App in AWS EC2
Sanjay Prakash
Sanjay Prakash

Posted on

Deploy My-Shopping-Mart Django App in AWS EC2

Prequisite to Build & Deploy Django App in AWS EC2

  1. OS Linux-Ubuntu (Windows ,Mac)
  2. Visual Studio Code
  3. Python
  4. Django
  5. Bootstrap

Steps to run this Shopping-Mart Website in your local host
To get this repository, run the following command inside your git enabled terminal

Step 1 $ git clone https://bit.ly/3ddPqVu

Step 2 $ python manage.py makemigrations

This will create all the migrations file (database migrations) required to run this App.

Step 3 Now, to apply this migrations run the following command

$ python manage.py migrate

Step 4

One last step and then our ecoomerce Shopping Mart website will be live. We need to create an admin user to run this App. On the terminal, type the following command and provide username, password and email for the admin user

$ python manage.py createsuperuser

Step 5

Now let's make the App live. We just need to start the server now and then we can start using our simple ecoomerce Shopping Mart. Start the server by following command

$ python manage.py runserver

Step 6

Once the server is hosted, head over to http://127.0.0.1:8000/products/ for the App.That was pretty simple, right?

Screenshot of website

How To Deploy Django Application in AWS EC2

Django comes with a development server that helps run Django projects in localhost. However, to make your web application available worldwide you will need a host machine. Amazon Web Services (AWS) provides EC2 (Elastic Compute Cloud) which is the most popular choice to host Django web applications.

Creating EC2 Instance With Ubuntu

Step 1: Select EC2 From AWS Console and click lauch Instance

Capture-ec2-2

Step 2: Name your Instance and Select Ubuntu

Capture-ec2-3

Step 3:
select instance type t2-micro (make sure free tier eligible) and create new key pair

Capture-ec2-4

Step 4:

Select launch Instance

Capture-ec2-6

Step 5:

If Instance created Succesfully you can view instance

Capture-ec2-7

Step 6:

Check instance is running and check status 2/2 passed

Capture-ec2-8

Step 7

Now select security and edit inbound rule

Capture-ec2-9
Capture-ec2-10

Step 8:

In this Security setting add rules and edit inbound rule select custom TCP--Port range 8000 and source
port 0.0.0.0 it will allow excess to anywhere click save rules

Capture-new

Step 9:

Now go back to your EC2 page select your instance and right click connect

Capture-13

Step 10:

Now open your ubuntu terminal & locate your private key file. The key used to launch this instance is YOUR_KEY_NAME.pem file

in my case my pem file is in Download folder

cd Downloads

Run this command, to ensure your key is not publicly viewable.

chmod 400 WRITE_YOUR_KEY_NAME.pem

Connect to your instance using its Public DNS:

sudo ec2-3-92-214-213.compute-1.amazonaws.com (Enter Your Public DNS)

you will connect to AWS EC2 Ubuntu server

Screenshot from 2022-08-03 00-13-12

Step 11

ls

cd My_Shopping_Mart

make sure git install into your ubuntu server before cloning github project type or copy this command in your terminal

git clone https://github.com/prakashsanjay/My-Shopping-Mart.git and find your project by typing ls command you will fimd My_Shopping_mart

Screenshot from 2022-08-03 00-23-49

Step 12

now go to settings.py file

cd pyshop

ls

vim settings.py press enter

make sure Python and Django both are installed in your AWS linux

Capture-uu

Step 13

press i to insert
than scrool down to Allowed Hosts [ ] empty box means your local host. now
enter asterisk ['*'] it will allow any ip address or [you can enter your EC2 publiv IP ]
press esc button
:wq press enter
you can also update it from vs code project folder locate settings.py file in pyshop folder
you can change allowed host from there as well.

Screenshot from 2022-08-03 11-26-13

Step 14
Run server

Python3 manage.py runserver 0.0.0.0:8000

CaptureLKJLKJ

Step 15

CTRL + CLICK 0.0.0.0:8000

Once the server is hosted, head over to http://0.0.0.0:8000/products/ for the App.and our django app now running into AWS EC2 server
That was also pretty simple, right?

Screenshot from 2022-08-03 11-20-15

thanks & regards
Happy Learning

Top comments (0)

🌚 Friends don't let friends browse without dark mode.

Sorry, it's true.