For this project, we will build the web app with Python Flask first, and we will check if it works in the local host.
Then, we will create a repo in github and upload all the files in that repo.
Also, we will use AWS Beanstalk to integrate the project.
Finally, we will create a project in Jenkins, link it to the calculator repo.
The calculator built in this repository is not complete yet. It is an ongoing project.
The resources used to build the simple calculator are from this link.
There are three features:
- BMI Calculator: returns BMI (Body Mass Index).
- Simple Calculator: as said, this is a simple calculator that do basic calculation. You can only input two values per operation.
- Unites Converter (under construction)
Installation Flask in Python using visio code (Windows 10) Flask requires Python 3
Setup virtual environment
Create an environment
$ mkdir app_directory
$ cd app_directory
$ py -3 -m venv virtual
Activate the environment
$ .\virtual\Scripts\activate
Install Flask
$ pip install Flask
In the app_directory folder, create a folder application_app and a Python file where the code will be displayed.
Create a static and templates folder in application_app folder. In the static folder, create a CSS file for the style if needed. In the templates folder, create a HTML file(s).
Once the setup is done, import your codes in the correct files. Now you can check locally if your web app works.
-
Create your AWS account user.
-
After you log in into your AWS root account, add a IAM user account with AWS Beanstalk privilages. Make sure to attach existing policies and save both access and secret key for future use.
-
Log out from the root account, and log in into the IAM account.
-
Go to Amazon Elastic Beanstalk and create an application.
-
In create a web app, put the application name, add tag(s), and select python platform.
Select sampke application > create application. -
It may take few minutes to set up th environment. Be patient!
-
See AWS Elastic Beanstalk for more set up information.
-
You should see this after the set up is done.
-
Create an EC2 on AWS and set up Jenkins. Here is a tutorial from AWS.
-
Log in to your Jenkins account.
-
Go to Plugins Manager > Type AWSEB under Avalaible plugins.
-
Select AWSEB Deployment and Cloubees Creadentials > Install.
-
After updating the plugins, create a new project with github and AWS Beanstalk linked to the Jenkins project.
-
When the project is done, build it on Jenkins.
-
Go back to Elastic Beanstalk > Environments > Simplecalc-env, and launch the web application by following the URL highlighted in red.
Then it will take you to the web application home page.
First, the BMI calculator looks like this:
And the simple, edited calculator looks like this:
From the source codes vr025, I was able to add two new features which are calculating the square root of a number and square a number.
This was easy to add because the syntax of the source code remains the same. I just had to copy/paste the line code and update the different variables.
For this, it is possible to upgrade this Simple Calculator into a Scientific one with more features.
The errors I ran into was mostly indentation of the lines in the codes.
Source: