Create AWS infrastructure and deploy React frontend & Node/Express backend using Terraform.
Source Code Repo for this Project: https://github.com/mleager/instagram-mern
ORIGINAL PROJECT BY: Jigar Sable
- Project was modified to use Postmark instead of SendGrid.
VPC
- and accompanying IGW, NAT, Routing Tables, etc.
2 Application Load Balancers
- 1 Internet-Facing ALB for Frontend, 1 Internal ALB for Backend
2 Autoscaling Groups
- 1 for each of the Frontend & Backend
MongoDB
- MongoDB resources for storing site data
DNS
- ACM and Route53 records for DNS
Security Groups
- Security Groups for AWS resources
Apply Terraform config files
NOTE:
* MongoDB Provider requires Public and Private Access Keys.
* The 0-provider.tf
file shows 2 options for using the Keys:
Set Keys as ENV Varibles using your Local Terminal
- MONGODB_ATLAS_PUBLIC_KEY=xxxxxxxx
- MONGODB_ATLAS_PRIVATE_KEY=xxxxxxxxxxxxxxxxxxxx
Set Keys are Terraform variables in `terraform.tfvars`
- Make sure this file is not commited to Public Repos and stored properly
Start the Backend Server
- SSM into instance (allowed by IAM Instance Profile)
- cd /usr/share/nginx/backend
- Add MongoDB Connection String to '/backend/config/config.env'
* Must append "/?retryWrites=true&w=majority" to connect MongoDB with Node.js Backend *
MONGO_URI=mongodb+srv://<username>:<password>@mongo-cluster.abcdefg.mongodb.net/?retryWrites=true&w=majority
<mongo_connection_string>/?retryWrites=true&w=majority
$ sudo npm start
Start Frontend Server
- SSM into instance (allowed by IAM Instance Profile)
- confirm Nginx is running
sudo systemctl status nginx
- cd /usr/share/nginx/frontend
$ sudo npm start