Sunday, 28 February 2016

Launching and connecting to your new EC2 instance of your Amazon web service


In AWS you can start your own virtual machine and work with it. All you have to do is go to -
and create your free account. Note you will have to provide your credit card details and as a part of the verification process, they will cut 2/- rs from your account. But don't worry it will get refunded to your account within 3-4 business days. I am going to skip this part where you create your account - it is very straightforward after you visit above URL. In this post, we will see how to get the EC2 instance which is the basic free tier up and running.

EC2 stands for Elastic compute cloud and it is essentially virtual machines in the cloud.

Launching EC2 instance

Once you log in your dashboard should look as below - 

Click on the EC2 (Virtual server in the cloud). You should see EC2 dashboard

Click on "Launch Instance" to start the launch configuration. Note the "instances" link on the left. We will visit it once our EC2 instance is up and running.

Next, you will have to choose which OS to boot up. I am selecting Ubuntu server 14.04 LTS which is a part of the free tier. You can choose the OS you want.

Next, you will have to select the instance type. Select t2.micro  with 1 CPU and 1GB mem.

NOTE: t2.micro is eligible for free tier. You can try others as well but they will incur you some cost. So if you are experimenting with free tire stick to t2.micro. They can be of following families -

Family            Speciality                                  Use case
D2                Desne storage                                File servers/Data warehousing/Hadoop
R4                Memory optimized                        Memory intensive apps/DBS
M4               General purpose                             Application servers
C4                Compute optimized                        CPU intensive apps/DBs
G2                Graphics intensive                         Video encoding/3d Application streaming
I2                 High speed storage                         No sql dbs/data warehousing
F1                Field programmable gate array      Hardware acceleration for your code
T2                Lowest cost general purpose          web servers/small dbs
P2                Graphics/General purpose GPU     Machine learning
X1               Memory optimized                         SAP hana/ apache spark

Now click on Configure Instance Details.

 Keep number if instances to 1 as we just need 1 instance. There are multiple EC2 payment options available -
  1. On demand - Fixed rate by hour (by the second only for Linux)
  2. Reserved - Same as On demand but for 1 year or 3 year terms so that you get some discount
    1. Standard RIs (Up to 75% off on demand)
    2. Convertible RIs (Up to 54% off on demand)
    3. Scheduled RIs 
  3. spot - Enables you to bid whatever price you want if your start and end times are flexible. If the cost goes below your bid price your EC2 instances are provisioned and when it goes above they are canceled.
    1. If you terminate the instance you pay for the hour
    2. If AWS terminates the SPOT instance you get the hour it was terminated for free
  4. Dedicated host - Physical EC2 server dedicated for use. Can reduce cost by allowing to use our existing server bound software license like Oracle or VMware.
Purchase option shows an option to go for spot option.  This may not be available in your region so check that out. You can also go to tenancy and choose between shared and dedicated host.

We saw on demand, Spot and dedicated host. For reserved instances, you can see under instances section in your EC2 dashboard.

If you see network a default VPC (virtual private cloud is selected for you. You can create one if you need).  Don't worry if you don't understand these terminologies. We don't require these to run our EC2. Just keep defaults. Also, you can see a subnet assigned to you. This is basically an IP range. Subnet is per availability zone -

Also, select the option to auto-assign IP (It should be checked by default). To select static IP refer -

Keep the defaults you see and proceed to storage settings.

Here you can select the type of EBS volume. General types of EBS volumes are -

  1. General purpose SSD (GP2)
    • Up to 10000 IOPS  (I/O per second)
  2. Provisioned IOPS SSD (IO1)
    • Designed for IO intensive applications like large relational DB or No Sql db.  
    • 10000 IOPS ~ 20000 IOPS
  3. Throughput optimized HDD (ST1)
    • Use cases Eg. Big data, Data warehousing
    •  Cannot be a boot volume
    • Frequently accessed workloads
  4. Cold HDD (SC1)
    • Lowest cost storage for infrequently accessed workloads
    • Cannot be a boot volume
    • Use case Eg. File server
  5. Magnetic (standard)
    • Lowest cost per GB
    • Bootable
As you can probably see from above types only types that are available for booting and hence qualified for root EBS volume are -
  1. GP2
  2. IO1
  3. Magnetic

You can also add new volumes (Other that Root which is bootable volume). Here you can see all types of EBS instances.

NOTE: Your EBS volume will get deleted by default on termination your EC2 instance. This is a setting under Add storage section while configuring your EC2 instance.

Next, go to Tag Instance. This is where you name your EC2 instance.

I have named it athakur-webserver. You can name it whatever you want. You will see this in instances tab later.

Next, go to configure security groups. Here you can configure which IPs can access the EC2 instance. The default group is which mean all IPs can access it. I am going to keep it as such. Also, not this settings are per Protocol/Port. By default port 22 is allowed which is your SSH.

If you want to host your site and be able to access it you can open HTTP or HTTPS types as well.

Next click on "Review And Launch". You will get a screen with details of all configurations you have done so far. Review it and select Launch.

Before your instance is actually launched you will need to create a pair of the public and the private key that will enable you to connect to your EC2 instance. Basically, you will have the private key (used on the machine you use to connect remotely to your EC2 server) and EC2 server has the public key. You can download your private key (it will be a .pem file) and save it on your local machine.

 So create your key and "Download Key Pair" and finally launch your instance.

It may take some time for your EC2 instance. Once it is up you are good to go. You can go to dashboard and select the instances link I referred to in 2nd screenshot.

You should see your instance details here. You can also note the public DNS that is basically your hostname.

Connecting to your EC2 instance

Now you can SSH to your EC2 instance from your local machine. To know the steps right click on your running instance and select connect. You should see steps to connect via ssh.

Follow the steps provided in -
to connect to your EC2 instance via putty. You will have to convert your pem file to ppk file and give it as input to putty for connecting. PuTTY has a tool named PuTTYgen, which can convert keys to the required PuTTY format (.ppk). You must convert your private key into this format (.ppk) before attempting to connect to your instance using PuTTY.

 Once you are done you should be able to connect -

For windows use putty and in auth section give this new private key create -


In Linux or Mac you can simply SSH to your machine.

NOTE: You can do "sudo su" to get root access.

Note you will have to provide appropriate permissions for your pem file. For details, you can refer -
NOTE: Your public DNS or your hostname will change every time you reboot your instance. To get a permanent IP address, click Elastic IPs in the AWS Management Console (left navigation bar), allocate a new IP address and associate it with your instance.

Related Links

t> UA-39527780-1 back to top