Deploy Django website using AWS Elastic Beanstalk CLI in windows

 

Prerequisites:

  1. Python
  2. pip
  3. virtualenv
  4. awsebcli

To deploy a Django website, first create a virtual environment using below commands in cmd terminal…

  1. >mkdir demo
  2. >cd demo
  3. demo> virtualenv <name_virtualenv>
  4. demo> %HOME_Path%\ <name_virtualenv> \Scripts\activate To check enviroment is now active like below: (<name_virtualenv>) C:\>

Now, Install django in virtual environment

  1. (<name_virtualenv>) C:\> pip install django
  2. (<name_virtualenv>) C:\> pip freeze

Next step is to create django project

  1. (<name_virtualenv>) C:\> django-admin startproject <project-name>

After this execution you will find below directory in project folder

2. cd <project-name>

3. python manage.py startapp <folder-name>

After this execution you will find below directory in project folder

4. python manage.py runserver

5. pip freeze > requirements.txt

6. mkdir .ebextensions

7. In the .ebextensions directory, add a configuration file named django.config with the following text.

option_settings:
aws:elasticbeanstalk:container:python:
WSGIPath: <project-name>/wsgi.py

8. Download the code from this zip file

mysite.zip

9. Extract the zip file and copy “tem” folder in your <project-name> directory.

10. Now make the following changes in your directory.

  1. In settings.py file makes these two changes.
  1. In views.py copy the code from the given zip folder
  2. In urls.py file, copy this code make sure you change the <folder-name> as per your project

from django.contrib import admin
from django.urls import path
from <folder-name> import views
from django.conf import settings

urlpatterns = [
path(‘admin/’, admin.site.urls),
path(”,views.home, name=’index’),
]

Now Our Django website is ready to deploy on AWS Elastic Beanstalk

  1. eb init
  2. eb create <environment-name>
  3. eb deploy
  4. eb open

OUTPUT:

Comments

Popular posts from this blog

Install terraform on ubuntu and Create EC2 instance on AWS using terraform script

Deployment of Website Using AWS CICD pipeline & Fargate