Deploy Django website using AWS Elastic Beanstalk CLI in windows
Prerequisites:
To deploy a Django website, first create a virtual environment using below commands in cmd terminal…
- >mkdir demo
- >cd demo
- demo> virtualenv <name_virtualenv>
- demo> %HOME_Path%\ <name_virtualenv> \Scripts\activate To check enviroment is now active like below: (<name_virtualenv>) C:\>
Now, Install django in virtual environment
- (<name_virtualenv>) C:\> pip install django
- (<name_virtualenv>) C:\> pip freeze
Next step is to create django project
- (<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
9. Extract the zip file and copy “tem” folder in your <project-name> directory.
10. Now make the following changes in your directory.
- In settings.py file makes these two changes.
- In views.py copy the code from the given zip folder
- 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
- eb init
- eb create <environment-name>
- eb deploy
- eb open
Comments
Post a Comment