This tutorial is a quick start to a Python-Django environment using the AWS environment and related services.  It is a stand-alone tutorial or can be used to get started on our video series.  This is technical but aimed at getting you set up quickly by following the steps laid out.  If you have any challenges with this then leave a comment or contact us so we can make adjustments and make this as easy as possible.

The Goals

Our goal in this series of steps is to create a full-featured development environment.  Many of the details will be explored in our video series.  However, this should be a good start for anyone that wants to stand up a Django on AWS environment with MySQL/MariaDB.  The core technologies we will utilize are below.

  • Python 3.x
  • Current Django
  • MariaDB
  • A virtual development environment (on EC2)

Getting Started

We will start by getting the AWS pieces in place.  This is mostly free tier accessible features.  However, heavy usage may cause some fees to be charged.  Keep an eye on your usage.  We will discuss pricing in more detail later in the series.
  1. Log in to the AWS console (or create your account)
  2. Go to the EC2 page, or you can use LightSail
  3. Lanch a New Instance
  4. Select t2.micro unless you want a higher-end dev environment. This size should be fine for most development efforts.
  5. Refill your coffee while the environment is created.

Python/Django Install

Once the EC2 environment is up, connect to it.  We will skip the details of this but it is well-documented.  Now we can get to work on the Python/Django piece.

  1. Install the extras: sudo amazon-linux-extras install epel -y
  2. Load pip. sudo yum install python3-pip -y
  3. Install django and node
    sudo pip3 install django
    sudo yum install nodejs
  4. Create your first Django app.  For example: django-admin startproject myProject
  5. Note that a folder has now been created with your project name.
  6. Install the database and set it up.
    run this: sudo yum install python-devel gcc mariadb-server mariadb-devel
    then this: sudo systemctl start mariadb
    then this: sudo systemctl enable mariadb
    and this: sudo mysql_secure_installation
  7. Enter the requested information to configure your database.
  8. Setup the database packages.
    sudo pip3 install mysqlclient
    sudo yum install python3-devel
  9. Create a database:
    MySQL -u root -p
    create database [projectname];

Connect to the Database

Change the DATABASES section of the settings.py file in your project.

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': '[your database]',
'USER': '[username]',
'PASSWORD' : '[password]'
}
}

Setup the database tables: python3 manage.py migrate

Now you can run the server:

python3 manage.py runserver 9090

Make sure you configure EC2 security to open the defined port.

Congratulations, you can now start working on your server and joining in our Python/Django series.  If you have any questions contact us and we will be glad to help or leave a comment here.

Rob Broadhead

Rob is a founder of, and frequent contributor to, Develpreneur. This includes the Building Better Developers podcast. He is also a lifetime learner as a developer, designer, and manager of software solutions. Rob is the founder of RB Consulting and has managed to author a book about his family experiences and a few about becoming a better developer. In his free time, he stays busy raising five children (although they have grown into adults). When he has a chance to breathe, he is on the ice playing hockey to relax or working on his ballroom dance skills.

Leave a Reply