Balasubramani M

@balasubramanim

Make your Amazon EC2 instance up and running.

In this part, we will be creating an Amazon account, EC2 instance and connect to that instance via SSH.

We will be using Linux OS throughout this tutorial. Windows users, don’t get annoyed. We will be working only on Amazon website with some terminal commands so System or OS doesn’t be a big issue here.

Create an AWS account @ https://aws.amazon.com/

You will be asked to provide your card details. Don’t worry, it is just for the verification purpose.

You have an option to use your AWS account in free-tier period for 1 year and you will not be charged in this period.

Once you have created your account successfully, ClickServices at the top and select EC2. Click Launch Instance or Create Instance button. You will see the below page after clicking on it.

Step 1 — Select Ubuntu Server 16.04 LTS

1. Select Ubuntu Server 16.04 LTS. You find most of the Linux images which is used to run variety of applications and used widely. Windows images are used specifically for .NET applications. So lets stick to Linux image which has a wide user base and tons of forums and communities to address any kind of issue.

2. In Step, Choose an Instance Type, select t2.micro which is enough to run multiple applications and let’s not exceed our free-tier limit. Click Next: Configure Instance Details

Step 2 — choose t2.micro

3. It is not necessary to configure any of the instance details as of now. So lets skip this step and click Next: Add Storage

4. 8 GB of an SSD is fine for us to run a normal application. So lets not change anything here and move on to next step. Click Next: Add Tags

5. Tags are used to tag your instance, specially used to filter when you have multiple instances. No changes needed as of now and click Next: Configure Security Group

6. Security Group is a config for your server. It allows you to define which port should your server allow traffic, protocol & port range etc. You can also add an description for the port you allow here. Also name your security group name meaningfully.

To run our app, we need SSH access which by default is on port 22 and Amazon makes it default for us. There is also a warning sign below allow access from known IP address alone. Keep this in mind and whenever you are required to allow any port or IP, you are allowing access to your server from that address.

The default port is 80 for any site but our browser tape that so that we couldn’t able to see it. So let’s open the port 80 which is by default and to serve an app we need HTTP so let’s create a rule by clicking,

Add Rule and select HTTP in type. Let protocol be TCP. Add 80 in port range. Select Anywhere in the source so that we are opening it to all IP address.

7. Click Review and Launch button to launch your instance successfully.

Now you will be prompted to set up an SSH key-pair which is a pem file, gives you access to connect it to your instance(we just created) from your Linux terminal. Give a proper name (I will name it as AWS-EC2-INSTANCE-LIVE), download it and keep it safe or else you will need to generate a new one if you lose.

Click Launch Instances and Click View Instances.

Hurray! You have created your remote server successfully.

Check the below image and find your running instance details below.

EC2 Running Instance

Optional — You can also move your .pem file to default .ssh folder in your MacOS. Open Finder and press Cmd+Shift+G type ~/.ssh in the search box and click Go to get into ssh key folder. It is recommended to put your .pemfile in this folder, which is hidden by default.

Note: Always remember to stop your instance when you are not using it by

RightClick on instance -> Instance State -> Stop

Now let’s connect to our instance from our terminal.

Use chmod to set permissions to your .pem file so that it can be used as a key to connect to our instance.

$ chmod 400 ~/.ssh/AWS-EC2-INSTANCE-LIVE.pem

To SSH into our server, we need three parameters.

  1. Username
  2. Domain Address
  3. Pem file

You don’t need to worry about searching for these params. AWS has formed this query string with your instance details already.

Click Connect.

Click the Connect option in the aforementioned page. You will see a popup like below.

Copy highlighted query string.

Copy paste the highlighted query string, give your .pem file location and press enter in your terminal. Type Yes when prompted so that you can add your instance as your known host (One time process).

My final query string goes below.

$ ssh -i ~/.ssh/AWS-EC2-INSTANCE-LIVE.pem ubuntu@ec2-xx-xxx-xx-xx.us-east-2.compute.amazonaws.com

Note: I have .pem file in default .ssh folder here for security reasons. Anyone having this .pem file can access your instance. Keep it safe

Yes. You are connected to your remote server securely.

In the next tutorial, let’s install and configure Nginx on this remote server and deploy the Node.js app in production. If you have already bought a domain name, let’s map it too ;)

Thank you.

More by Balasubramani M

Topics of interest

More Related Stories