Deploying Rendertron on AWS EC2
I wanted to deploy Rendertron on AWS EC2 for my production app written in Angular 5 frontend and node/express backend and did not find any tutorial so here is my stab at it. I did not want to dive into Angular Universal for Angular server side rendering for SEO and sincerely thought Rendertron is a much better and easier alternative.
Log in to your AWS Console and Fire up a brand new Ubuntu 16.04 LTS instance.
I am going to choose a m4.large instance since I presume we will need a little bit of that memory and power that t2 instances lack. This will cost you about $0.10 per hour.
I am not going to go into the VPC details as this might be different for each AWS account. You can choose your default VPC and leave all the other Configure Instance details to default. Next go to the storage screen and leave the storage at default 8 GiB, Volume Type GP2 at 100/3000 IOPS.
Go to security group and allow SSH on Port 22 from your IP or anywhere for now and allow traffic on port 80 and 3000. We can change this later to allow traffic from any specific security group only from your server that will reroute traffic to rendertron.
Go to the next screen, review details and choose your EC2 Key Pair that you will use to ssh into the instance. Launch the bad boy!
Now go to your AWS EC2 console and select the instance that you just launched and copy the public dns. This will be something like ec2–xx–xxx–xxx–x.compute-1.amazonaws.com. We will use this public dns to set up a subdomain something like: http://yourapp.yourdomain.com using AWS Route 53 CNAME configuration. This is only applicable if you have a hosted zone. You can skip this step and once the instance configuration is done, just use the public dns to reach the rendertron instance.
Lets ssh into the instance and say hello to him.
If you are on a mac you will just do a simple ssh with your keypair to the instance.
ssh -i ~/.ssh/yourkeypair.pem user@ec2–xx–xxx–xxx–x.compute-1.amazonaws.com
Lets start by updating the local package index on the instance.
sudo apt-get update
Then install git. If its already installed it will tell you git is already on the newest version.
sudo apt-get install git
Next Let’s get nodejs.
curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash -
sudo apt-get install -y nodejs
Now lets clone the rendertron repo and get it into our EC2 instance.
Now cd into the rendertron directory.
Lets install all the packages.
If all goes well you will see node_modules directory under rendertron with all package dependencies installed.
Next Steps are to Install Chrome.
wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | sudo apt-key add -
sudo sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list'
sudo apt-get updatesudo apt-get install google-chrome-stable
Alright we are now ready to run rendertron on our own AWS EC2 instance.
npm run start
Exactly why we opened port 3000 for all traffic in our EC2 Security group for the rendertron instance.
Cool…so lets head over to the browser and hit the Public DNS of the instance : 3000 and see if we get the app up and running on the browser.
Option 1: You can hit <Your ec2 instance public dns>:3000
Option 2: That subdomain you configured in AWS route 53 — http://yourapp.yourdomain.com:3000
Voila! You will see rendertron is up and running. I will post the next story on how I am going to use this instance to do Service Side Rendering and SEO purposes for my Angular 5 app playing nicely along with the Node/Express backend. Until later…