This is an open-source repository containing code and setup instructions for an Amazon price-matching tool. The tool compares product prices to other online storefronts and utilizes a LAMP stack through EC2 instances on AWS.
The below instructions detail how to recreate the stack for this tool in AWS. Each folder in this repository has the necessary .html, .php, and .sql code for each instance.
Repeat all of the steps in this section for 3 separate instances (webserver, apiserver, databaseserver)
- From "AWS Console Home", click the menu in the top-left
- Click "All services", then click "EC2" under "Compute"
- In the left menu, click "Instances" under its category of the same name
- Click "Launch instances" in the top-right
- Set a name for the instance (webserver, apiserver, databaseserver)
- Under "Quick Start", click "Ubuntu"
- Under "Key pair (login)", click "Create a new key pair" and enter a key pair name
- Make sure the private key file format is .pem
- Click "Create key pair" and save it to your local machine
- Under "Network settings", check "Allow HTTP traffic from the internet"
- Under "Summary", click "Launch instance"
By default, AWS dynamically assigns a public IP to EC2 instances, which will break code referencing public IP addresses.
- Under "Network & Security" in the left menu, click "Elastic IPs"
- Click "Allocate Elastic IP address"
- At the bottom of the page, click "Allocate"
- Click the underlined link for the IP in the list that shows up
- In the top-right, click "Associate Elastic IP address"
- Under "Instance", select the instance to be associated with this IP
- Click "Associate" in the bottom-right
- In the left menu, click "Instances" under its category of the same name
- Click the underlined instance ID for the server instance in the list that shows up
- In the top-right, click "Connect", then the following "Connect" button in the bottom-right
- If not already done, connect to the web server instance (see above on View instance details/connect)
- Run the following lines of code in the Ubuntu CLI to install Apache:
sudo apt update
sudo apt install apache2
sudo apt install php libapache2-mod-php
- Run this to change directories to the html for the instance:
cd /var/www/html
- Run this to replace the default Apache index.html with a blank copy:
sudo rm index.html
sudo nano index.html
- Copy-paste (ctrl + shift + v) the code from webserver/index.html from this repo to the instance.
- Replace
API_Server_Public_IPin the code to the public IP of the API server - Exit the nano text editor and save changes (ctrl + x, then y)
- Run this line to create a file for displaying the data in html from the API:
sudo nano api-link.html
- Repeat steps 3-5 except using webserver/api-link.html
- If not already done, connect to the database server instance (see above on View instance details/connect)
- Run this to install and launch MySQL:
sudo apt update
sudo apt install mysql-server
sudo mysql
- Copy-paste and run all the SQL from databaseserver/data.sql to create the database
- Run this to create a MySQL user for the database (you may change the username and password):
CREATE USER 'username'@'%' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON PriceData.* TO 'username'@'%';
FLUSH PRIVILEGES;
- Click the underlined ID for the database server instance in the list that shows up
- Click the "Security" tab in the menu below the instance summary
- Click the blue link under "Security groups"
- In the top-right of the "Inbound rules" section, click "Edit inbound rules"
- Click "Add rule" at the end of the list
- Click the text input for "Type", then search for "MYSQL/Aurora"
- Click the text input for "Source", then select "0.0.0.0/0"
- Click "Save rules"
- If not already done, connect to the API server instance (see above on View instance details/connect)
- Run the following to install Apache, PHP, and the MySQL client:
sudo apt update
sudo apt install apache2 php php-mysql
- Run this to change directories to the html for the instance:
cd /var/www/html
- Run this to remove the default index.html:
sudo rm index.html
- Run this to create a new file for the data.php:
sudo nano data.php
- Copy-paste the code from apiserver/data.php from this repo to the instance
- Replace
Database_Server_Private_IPwith the private IP of the database server - Replace
"username"and"password"with the username and password of the MySQL user - Exit nano (ctrl + x, then y)
- Repeat steps 3-7 except using apiserver/api.php