Django Deployment to AWS Elastic Beanstalk Django.How

Author avatar wrote on 26/05/2022

What is AWS Elastic Beanstalk?

https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/Welcome.html

1.Preparing for AWS

Prepare to use AWS virtual environment

pip3 install virtualenv awsebcli

Create virtual environment outside the project

cd ..

virtualenv eb-vert

Activate virtual environment

C:\projects\python\lewhdk\eb-vert\Scripts\activate.ps1

DID NOT WORK

You should try executing Set-ExecutionPolicy Unrestricted -Force in Your Power Shell.

NB: Remember to launch Power Shell as administrator.

Also make sure you use Scripts\Activate.PS1

https://stackoverflow.com/questions/18713086/virtualenv-wont-activate-on-windows

Prepare the Virtual environment

pip install django pillow psycopg2

2. Deployment to AWS

Follow the official documentation https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/create-deploy-python-django.html

Check the list of installed apps

pip freeze

Prepare the requirement file

pip freeze > requirements.txt

Note: To check/change the file contents nano filename.txt on mac Linux notepad filename.txt on windows

Prepare .ebextensions for AWS

inside your project type mkdir .ebextensions

type ls to see it, if you could not see it type ls -a

Configure Django in .ebextensions

Create a file notepad .ebextensions/django.config

Add code


option_settings:
  aws:elasticbeanstalk:container:python:
    WSGIPath: prject-name/wsgi.py
Collect Static

python manage.py collectstatic

then deactivate

Deploy your site with the EB CLI

Make sure Built-in SSH in Windows 10 is activated

settings → updates and security → for developers → Developer Mode

Activate SSH client: settings → apps → Optional features → add a feature → OpenSSH Server & OpenSSH Client → Install

https://www.youtube.com/watch?v=xIfzZXHaCzQ

Initialze AWS Project

eb init -p python-3.6 project-name

CRUDgen Django CRUD generator