This is Node.js REST API that connects to an Amazon RDS Aurora MySQL database, hosted on an Ubuntu-based EC2 instance. The app uses Express.js for routing and PM2 for production process management.
- REST API built with Node.js + Express.js
- Database: Amazon RDS (Aurora MySQL)
- Secure configuration using
.env - EC2 (Ubuntu 22.04+) host
- Managed with PM2
Client β EC2 (Node.js App) β RDS (Aurora MySQL)
Base URL:
http://<your-ec2-ip>:3000or Mine:http://54.217.181.120:3000
| Endpoint | Description |
|---|---|
/ |
Root route β confirms API is live |
/api/topCustomer |
Get the top customer(s) by Spending |
/api/monthlySalesReport |
Get the monthly sales report |
/api/productsNeverOrdered |
List products that were never ordered |
/api/countryAverageOrderValue |
Get average order value by country |
/api/frequentBuyers |
Get customers with frequent purchases |
Note: Replace
<your-ec2-ip>with your actual EC2 public IP or public DNS hostname.
- Go to AWS RDS > Create Database
- Choose:
- Engine: Amazon Aurora
- Edition: Aurora MySQL-Compatible
- Capacity: Provisioned
- DB cluster identifier:
zeth-ecommercedb - Master username:
admin - Password: your secure password
- Connectivity settings:
- Make it publicly accessible
- Choose/select a VPC and security group that allows access from EC2
- After creation, note the endpoint URL and port (3306)
- Launch an EC2 instance (Ubuntu 22.04 or similar)
- Allow inbound traffic on:
- SSH (22) for access
- HTTP (80) if needed
- Custom TCP 3000 for API (or use NGINX)
- SSH into instance:
ssh -i your-key.pem ubuntu@your-ec2-public-ip
sudo apt update && sudo apt upgrade -y
sudo apt install -y git nodejs npm mysql-client
sudo npm install -g pm2git clone https://github.com/your-username/eCommerceLab.git
cd eCommerceLabOr Clone mine:
git clone https://github.com/Zapwap123/eCommerceLab.git
cd eCommerceLabtouch .env nano .env
Example content:
DB_HOST=your-rds-endpoint.amazonaws.com DB_USER=admin DB_PASS=yourpassword DB_NAME=ecommerce
If you have a SQL script (ecommerce_init.sql):
mysql -h your-rds-endpoint.amazonaws.com -u admin -p < ecommerce_init.sqlTo import into specific DB:
mysql -h your-rds-endpoint.amazonaws.com -u admin -p ecommerce < ecommerce_init.sqlnpm install
pm2 start index.js --name ecommerce-api pm2 save pm2 startup
curl http://your-ec2-public-ip:3000/
eCommerceLab/
βββ config/
β βββ db.js
βββ routes/
β βββ customers.js
βββ ecommerce_init.sql
βββ .env
βββ index.js
βββ package.json
βββ README.md
pm2 list pm2 logs ecommerce-api pm2 restart ecommerce-api pm2 delete ecommerce-api
- Donβt commit your
.envfile β ensure.gitignoreincludes it - Use a strong password for your RDS admin
- Limit inbound access to RDS using security group rules