This post details my experience with creating a simple two-tier app using Google Cloud Platform (GCP) as well as Amazon Web Services (AWS) by taking advantage of the free tier accounts for each service.
GCP has a few easy-to-follow tutorials for their main services. For Google Compute Engine (GCE), the tutorial walks you through creating a two-tier app in which the Frontend VM is a Node.js ToDo Web app and the Backend VM runs MongoDB. For either service, I followed these steps:
- Create and configure VMs in GCE or AWS Elastic Cloud Compute (EC2)
- Connect via SSH to each VM to install appropriate packages and run the relevant services.
In GCP, I started by creating each VM instance separately.
In AWS, however, EC2 let me specify 2 instances to create simultaneously with the identical settings other than the IP addresses.
First, I created the Backend VM that ran MongoDB. The only customizations required were to select a Micro instance (to incur the fewest charges on my Free Tier account), specifying Ubuntu 14.04 LTS as the OS, and opening up HTTP for the Frontend and Backend VMS to communicate. In AWS, I did this by applying a Security Group to the instances that opened up port 80.
Next, I created the Frontend VM that runs the Node.js ToDo application with the same customizations that I applied for the Backend VM.
Once both VM instances were created, I connected to them via SSH.
GCP offers a built-in browser-based terminal utility called Cloud Shell as an alternative to Terminal (Mac OS) or PuTTY (Windows).
gcloud compute --project "pakdude713" ssh --zone "us-east1-b" "backend"
But, for AWS, I used Terminal on my Macbook:
hoodbu@macbook-pro /AWS (502) ssh email@example.com -i my-us-east-keypair.pem
From there, I updated the packages first:
umairhoodbhoy@backend:~$ sudo apt-get update
Then, I installed MongoDB:
umairhoodbhoy@backend:~$ sudo apt-get install mongodb
Next, I configured MongoDB. But first, I had to stop the service:
umairhoodbhoy@backend:~$ sudo service mongodb stop
Create a directory for MongoDB and then run the MongoDB service in the background on port 80.
umairhoodbhoy@backend:~$ sudo mkdir $HOME/db
umairhoodbhoy@backend:~$ sudo mongod --dbpath $HOME/db --port 80 --fork --logpath /var/tmp/mongodb
That concludes the work needed on the Backend VM. For the Frontend VM, I SSH’d to the instance and updated the packages first:
umairhoodbhoy@frontend:~$ sudo apt-get update
Next, I installed Git and Node.js on the Frontend VM:
umairhoodbhoy@frontend:~$ sudo apt-get install git nodejs
Then, I installed and ran the Frontend web app by cloning the sample application. The sample application exists in a GCP repository on Github and I used it for the GCP experiment as well as the AWS one:
umairhoodbhoy@frontend:~$ git clone https://github.com/GoogleCloudPlatform/todomvc-mongodb.git
Next, I installed application dependencies and prepared the web server for port 80 instead of the default 8080:
umairhoodbhoy@frontend:~$ cd todomvc-mongodb; npm install
umairhoodbhoy@frontend:~/todomvc-mongodb$ sed -i -e 's/8080/80/g' server.js
Finally, I was ready to run the ToDo app on the Frontend VM:
umairhoodbhoy@frontend:~/todomvc-mongodb$ sudo nohup nodejs server.js --be_ip 10.142.0.2 --fe_ip 10.142.0.3 &
These IP addresses are the private IP addresses generated by the GCE instances. For AWS, I replaced the IP addresses with the ones generated by AWS EC2 instances.
And that’s it! In GCP, I launched the ToDo app by visiting http://126.96.36.199.
In AWS, I launched the same app by visiting http://188.8.131.52.