This project involves creating a simple webpage to check a timetable. The webpage will utilize resources provided by Amazon Web Services (AWS) to ensure scalability and reliability.
-
Instance Name:
- Use your name as the instance name for easy identification.
-
Choose AMI:
- Select Ubuntu as the Amazon Machine Image (AMI).
-
Create a Key Pair:
- Create a new key pair during the instance setup to securely connect to the instance.
- Download the
.pemfile and keep it safe as it will be required for SSH access.
- While launching the instance, create or modify a security group to allow the necessary traffic:
- Port 80: For HTTP traffic (webpage access).
- Port 22: For SSH access.
- Port 443: For HTTPS traffic (secure connections).
- Port 5432: For PostgreSQL.
- Port 8000: For custom application access.
- All Traffic: (Use only for testing; restrict in production environments).
-
Choose Database Engine:
- In the RDS Console, select PostgreSQL as the database engine.
-
Select DB Instance Type:
- Choose a Single DB Instance for simplicity and cost-effectiveness.
-
DB Instance Identifier:
- Use your name as the DB Instance Identifier for easy identification.
-
Credentials Management:
- Select Self Managed for credentials management.
- Create a strong password for the database administrator (master user).
-
Connectivity:
- Configure the database to connect with an EC2 compute resource:
- Choose the EC2 instance you set up earlier for connectivity.
- Configure the database to connect with an EC2 compute resource:
-
Open MobaXterm:
- Launch MobaXterm on your system.
-
Create a New SSH Session:
- Click on
Sessionsand selectNew Session. - Choose
SSHas the session type.
- Click on
-
Remote Host:
- Enter your Public IPv4 address in the Remote host field.
- You can copy the Public IPv4 address from your EC2 instance in the AWS Console.
- Enter your Public IPv4 address in the Remote host field.
-
Advanced SSH Settings:
- Tick the box for Use private key.
- Browse and select your
.pemkey file created earlier.
-
Start the Session:
- Click OK to initiate the connection.
- Once connected, you will be prompted to login as:
- Enter
ubuntuas the username (since you are using an Ubuntu instance).
- Enter
-
Update EC2 Instance:
- Run the following command to update the package list:
sudo apt update
- Run the following command to update the package list:
-
Install Necessary Packages:
- Run the following command to install Python 3, pip, and PostgreSQL client:
sudo apt install python3 python3-pip postgresql-client -y
- Run the following command to install Python 3, pip, and PostgreSQL client:
-
Connect to the RDS Instance:
- Use the following command to connect to your RDS PostgreSQL instance:
psql -h <RDS_End_Point> -U <RDS_User> -d <RDS_Database_Name>
- Replace
<RDS_End_Point>,<RDS_User>, and<RDS_Database_Name>with your actual RDS endpoint, username, and database name. - In this case, the RDC_User and RDS_Database_Name will both be
postgres. - You can find the RDS endpoint in the RDS Console under the Connectivity & Security section. Copy the Endpoint (not the port), which is used in the connection command.
- Use the following command to connect to your RDS PostgreSQL instance:
-
Enter the Database Password:
- When prompted, enter the database password that you created during the RDS setup.
-
Create Your Database:
- If the connection is successful, you will see the prompt:
postgres=>. - Now, create a new database with your name using the following query:
CREATE DATABASE your_name;
- After creating the database, switch to it with the following command:
\c your_name;
- If the connection is successful, you will see the prompt:
-
Success Message:
- If the operation is successful, you will see the prompt:
your_name=>.
- If the operation is successful, you will see the prompt:
-
Create a Table:
- Now, create a table using
Timetableas the table name with the following query:CREATE TABLE Timetable ( course_name VARCHAR(100), room INTEGER, day VARCHAR(20), time VARCHAR(20) );
- Now, create a table using
-
Insert Data into the Table:
- Insert the following sample data into your table:
INSERT INTO Timetable (course_name, room, day, time) VALUES ('Mathematics for Computer Science', 103, 'Monday', '9:30 AM'), ('Operating Systems', 112, 'Monday', '11:30 AM'), ('Python Programming', 205, 'Tuesday', '9:30 AM'), ('Java Programming', 213, 'Tuesday', '11:30 AM'), ('IT Project Management', 308, 'Wednesday', '2:00 PM'), ('Network Principles', 312, 'Wednesday', '4:30 PM'), ('Systems Analysis and Design', 415, 'Thursday', '9:30 AM'), ('Computer Languages', 325, 'Thursday', '11:30 AM'), ('Social Engineering', 256, 'Friday', '2:00 PM'), ('Computer and Information', 309, 'Friday', '4:30 PM');
- Insert the following sample data into your table:
-
Check the Data:
- Use the following command to check if the data was successfully inserted into the table:
SELECT * FROM Timetable;
- Use the following command to check if the data was successfully inserted into the table:
-
Exit SQL:
- To exit the SQL session, use the following command:
\q
- To exit the SQL session, use the following command:
Step 7: Create Project Directory (https://github.com/Xamidulla0406/AWS-Mini-Project)
-
Create Project Directory:
- Run the following command to create a project directory and navigate into it:
mkdir my_project cd my_project
- Run the following command to create a project directory and navigate into it:
-
Create Python File:
- Create a Python file called
app.pyin themy_projectdirectory using the following command:nano app.py
- Create a Python file called
-
Create Templates Directory:
- Now, create a directory named
templatesto hold your HTML files:mkdir templates cd templates
- Now, create a directory named
-
Create HTML Files:
- Create the
index.htmlfile inside thetemplatesdirectory:nano index.html
- Similarly, create the
timetable.htmlfile:nano timetable.html
- Create the
-
Return to the Project Directory:
- Once you've created the necessary files, return to the main project directory:
cd ..
- Once you've created the necessary files, return to the main project directory:
-
Install
python3.12-venv:- First, install the
python3.12-venvpackage to ensure that you can create a virtual environment. Run the following command:sudo apt install python3.12-venv
- First, install the
-
Create and Activate Virtual Environment:
- After installing the package, create a Python virtual environment by running:
python3 -m venv venv
- Activate the virtual environment with the following command:
source venv/bin/activate
- After installing the package, create a Python virtual environment by running:
-
Install Python Dependencies:
- Upgrade
pipto the latest version:pip3 install --upgrade pip
- Install the necessary Python dependencies:
pip3 install flask psycopg2-binary
- Upgrade
-
Install
pg8000:- To use an alternative PostgreSQL database adapter, install
pg8000:pip install pg8000
- To use an alternative PostgreSQL database adapter, install
-
Disable Firewall (Optional):
- If you need to disable the firewall for testing purposes, you can run the following command:
sudo ufw disable
- If you need to disable the firewall for testing purposes, you can run the following command:
-
Run Flask Application:
- Finally, to run the Flask application, use this command:
python app.py
- The Flask development server will start, and you can access your application by opening your web browser and navigating to
http://<Public IPv4 address of your instance>:8000/.
- Finally, to run the Flask application, use this command: