Deploy Django Application to Elastic Beanstalk

, , 196 Comments

Ensure the EC2 Instance Allows Traffic

Launch a Docker Container and Update

  1. docker run -it -p 80:80 ubuntu /bin/bash
  2. apt-get update
  3. apt-get upgrade
  4. apt-get dist-upgrade

Install Python 2.7, Pip, Amazon Command Line Interface (AWS CLI) and

  1. apt-get install python2.7
  2. apt-get install curl
  3. curl -O https://bootstrap.pypa.io/get-pip.py
  4. python2.7 get-pip.py
  5. apt-get install python-cryptography
  6. pip isntall aws
  7. pip install –upgrade –user awsebcli
  8. PATH=$PATH:~/.local/bin; export PATH

Install and Create Virtualenv

  1. pip install virtualenv
  2. ~/eb-virt
  3. virtualenv ~/eb-virt
  4. source ~/eb-virt/bin/activate

Install Django

  1. pip install django==1.9.2

Start a Django Project

  1. django-admin startproject ebdjango

Deploy Your Site

  1. pip freeze > requirements.txt
  2. mkdir .ebextensions
  3. vi .ebextensions/django.config
option_settings:
  aws:elasticbeanstalk:container:python:
    WSGIPath: ebdjango/wsgi.pyo
  1. eb init -p python2.7 django-tutorial # you’ll be asked for your keys
  2. eb create django-env
  3. eb open