Another “Ruby on Rails Application Deployment to AWS EC2” Post — Part 1
Hello, everyone. I am writing this blog post for two main reasons first one is it’s been a long time since I wrote something and the second is this may be a guide to someone.
I am going to be deploying a very simple Rails 5 application, to an Amazon Web Services (AWS) Elastic Compute Cloud (EC2) instance.
I am going to be using my dear MacBook Pro 2015-Early for the job. Let’s get started with the basics.
1. Get an AWS account.
If you don’t already have one, then follow this link to get one. If you already have one, feel free to skip this step.
2. Launch your EC2 Instance.
After you logged in (or just signed up), you are going to have access to AWS Console which is a pretty simple page with a search bar. Type in EC2 and select EC2 to access EC2 dashboard.
After selecting EC2, you are going to see a screen with a cool looking “Launch Instance” button.
Click on “Launch Instance” and select the Operating System you want for your server. I am going to select Ubuntu Server 16.04 LTS (HVM), SSD Volume Type.
Next, you are going to be asked to pick an instance type out of many options all having different specifications in terms of vCPUs (virtual central processing unit), memory sizes and so on. A General Purpose instance type is going to meet our needs for the sake of this tutorial. I suggest you pick t2.micro if you are just trying out this for the first time and you are not doing this for a production release because you can benefit from “Free Tier”.
The next page is about configurations, we can leave it as it is for now.
In the next page, you can add more storage up to 30 GB instead of 8 GB and still be using Free Tier option. But for this post 8 GB should be enough.
We are going leave the next part “Add Tags” as it is too.
Configure Security Group, this part is important. This is the set of firewall rules that control the traffic of our instance. The rules defined here will protect our instance from unexpected access. Here we are going to add new rule to allow our laptops to access the instance.
Finally, we can review our configurations, selections and launch our instance!
Oops, what? Oh so I just built a new door to my house and forgot get the keys for it? Okay, okay… So we defined a new door (tcp connection on port 80) but we did not get the keys (key pair). This key will allow us to SSH into our instance. As Amazon defines it “A key pair consists of a public key that AWS stores, and a private key file that you store. Together, they allow you to connect to your instance securely.”
Set a name for your key pair, and just follow the instructions in the dialog.
Now we can see our instance is running and “initializing” state, it should be up in minutes. Copy the IPv4 address of your instance, we are going to need it.
3. Connect to your new instance from terminal
First you need to change your .pem file permission to 400:
sudo chmod 400 your_key_pair_name.pem
Run the following command on your terminal to get into your instance:
ssh -i your_key_pair_name.pem ubuntu@your_ipv4_address
Type “yes” when you see the question “Are you sure you want to continue connecting (yes/no)?”
Done! Now you have successfully accessed your brand new EC2 instance.
That’s all for this part. In the next part, we are going to deploy a Rails 5 application to the instance we just created.