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
- Log in to the AWS console (or create your account)
- Go to the EC2 page, or you can use LightSail
- Lanch a New Instance
- Select t2.micro unless you want a higher-end dev environment. This size should be fine for most development efforts.
- 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.
- Install the extras: sudo amazon-linux-extras install epel -y
- Load pip. sudo yum install python3-pip -y
- Install django and node
sudo pip3 install djangosudo yum install nodejs
- Create your first Django app. For example: django-admin startproject myProject
- Note that a folder has now been created with your project name.
- Install the database and set it up.
run this: sudo yum install python-devel gcc mariadb-server mariadb-develthen this: sudo systemctl start mariadbthen this: sudo systemctl enable mariadband this: sudo mysql_secure_installation
- Enter the requested information to configure your database.
- Setup the database packages.
sudo pip3 install mysqlclientsudo yum install python3-devel
- Create a database:
MySQL -u root -pcreate 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.