A fully provisioned environment automated using terraform on AWS. The environment contains 3 nodes as following:
- API node runs the containarized app
- DB master node (PostgresSQL)
- DB slave node replica (PostgresSQL)
- Install terraform
- Create a new key pair on AWS
- Replace halan.pem with your new private key in the Provisioning folder.
- Add your aws access/secret key and key name, a simple way to do that by editing the variables in variables.tf inside the Provisioning folder.
- Run the following commands inside Provisioning folder:
terraform init
terraform apply
Simple REST API using python that does the following:
- It responds to the URL like http:/// and returns: Halan ROCKS
- It responds to the URL like http:///?n=x and returns n*n
- It responds to the URL like http:///ip with the ip address of the client making the request and save that ip address on Postgres
- It responds to the URL like http:///allips with all of the saved ip addresses after retrieving it from Postgres.
The machine that contain the database should has PostgreSQL installed to create the database run the script create_db.sh from App directory
./create_db.sh
First we need to prepare the app environment. Run the following commands from App directory
python -m venv env
source env/bin/activate
sudo apt-get install -y python-pip python-dev libpq-dev
pip install -r requirements.txt
To run the app file from App directory there are two methods
python app.py halan
OR
python app.py halan postgres 123456789 test@test.com
where "halan" is the database name, "postgres" is the database user, "123456789" is the database password and "test@test.com" is the database host
to get the docker image, there are two methods. the firs one is to run the Dockerfile from App directory
docker build -t halan .
and the second one is to pull it from docker hub
docker pull aymanazzam/halantest:halan
then to run the image use one of the following methods based on your case local/production
docker run -p 5000:5000 halan python app.py halan
OR
docker run -p 5000:5000 aymanazzam/halantest:halan python app.py halan postgres 123456789 test@test.com
where "halan" is the database name, "postgres" is the database user, "123456789" is the database password and "test@test.com" is the database host