How to deploy Python Application on AWS EC2 instance. ~Part4 Environment setting~

First of all

In my previous article,  PostgreSQL is installed on AWS EC2 instance. In this article, let’s deploy your application and make it public online.

Environment setting

Firstly, install pip. pip is a package management system provided by Python officially.

Next, please install virtualenv. It is a tool to create isolated Python environment.

Then, create python virtual environment by using virtualenv command as below.


Next, install Django with related packages.

~~

Finally, let’s install git for clone your application from remote repository.

~~

After installation, please check if git is installed successfully by the following command.

OK.  Environment preparation is completed.

Clone Web Application

Clone your application updated on your Github repository to AWS EC2 environment by executing ‘git clone’ command as below.

Connection setting between Application to Database

Move to your application folder and edit setting.py. In the setting.py file, you need to set your public IP address of your EC2 instance.

In the setting.py file, database connection setting  is also described. Change the setting according to your postgresSQL database setting as below.

Database migration

In this section, let me describe how to migrate database created your local environment to AWS EC2 environment. Firstly, please make an intermediate file for migration. By executing “makemigrations” command, the setting described in model.py will be written down in the intermediate file.


After creating the intermediate file, execute “migrate” command to reflect data to your database.


It seems OK because there are no NG.

Finally
That’s all for environment preparation. In my next article, let’s start your application and access it finally. Please check it !!

コメント