Lab4: Introduction to Amazon Elastic Compute Cloud (EC2) with Linux Server

Amazon Elastic Compute Cloud (Amazon EC2)  is virtual computing environment, known as an instance. Amazon EC2)provides scalable computing capacity in the Amazon Web Services (AWS) cloud.The concept of designed Amazon EC2 to make web-scale cloud computing flexible and easier to the developer.

Amazon EC2 gives you an opportunity to eliminate your Hardware up front invest, you can develop and deploy applications faster.Amazon EC2 instance has not limitation. You can launch as many or as few virtual servers as you need by using Amazon EC2. You can configure your own security and networking, manage storage separately for each Ec2 instance or group of EC2 instance together. 

Benefits: Amazon EC2 allow you to quickly scale up or down to handle changes in requirements or spikes in popularity, reducing your need to forecast traffic. The benefit of Amazon EC2 is that is re-sizable and elastic. It reduces the time to obtain and boot new server instance to a minute. You only pay for capacity you actually use, Amazon EC2 provide that economics of computing.

As Amazon Ec2 is a web service interface that allows you to obtain, configure and manage your instance anywhere in the world with a minimal friction. You can kill you instance any time when your demand is fulfilled. You will be charged to kill any EC2 instances.

This lab I will demonstrate the following contents:

  • Create an Amazon  Linux  Instance from an Amazon Machine Image (AMI)
  • Connecting to Amazon EC2 instance via SSH

Steps for the task: Create an Amazon  Linux  Instance from an Amazon Machine Image (AMI)

The important concern is before creating amazon EC2 instance. You have to figure out what type of EC2 instance you want. Amazon EC2 provides a wide selection of instance types optimised to fit different use cases. You have the freedom to choose the exact mix of resources for your system based on the combination of hardware, storage, network and memory capacity. You can distribute your workload because each instance type includes one or more instance size. It also allows you to build failure resilient of your application and scale your resource based on your workload.

In this lab, We are going to select instance type: General purpose, t2.small, vCPU: 1, Memory- 2 GB, and Storage: EBS only.

  1. On the services menu, click EC2 in the Management console. Then Launch Instance.Untitled.jpg
  2. Choose an  Amazon Linux AMI instance from the quick start. Then click Select2.jpg
  3. Now we have to choose Instance type. We selected lowest-cost general purpose instance type t2.small for this lab practice. But you can choose your instance based on your application system capabilities and workload. 3.jpg
  4. Click Next: Configure Instance. In this wizard, You will get various options such as location, network setting, monitoring and other options. Note: In our lab 2 we already created VPC (myPVC).If you don’t have any VPC, you can select default VPC or you can make your own VPC before configuring instance.4
  5. Then click Next: Add Storage. Here we are going to select default storage but you can easily add more virtual hard drives or change the drive size as per your requirement. If you want to add more new volume into your storage, click “Add New Volume”. 5.jpg
  6. Click “Next: Add tags“. In the value, field enters the value of name: EC2LAB. Note: Access to manage Amazon EC2 instances can be controlled using tags. tags help you to organise your infrastructure and identified your instance and resources very quickly.6.jpg
  7. Click “Next: Configure Security Group”. Note: you can configure your security before launching your instance or you can leave the default security groups. As It always allows port 22 (SSH) to Linux Server.

As you see, Assign a security group has two options:  Create a new security group or Select an existing security group. In this lab, We will use our pre-created security group (WebServerSG) which we have created during our lab2 exercise.7.jpg

8. Click Review and Launch. After reviewing your configuration, Click Launch.You will get key pairs dialogue page. You will get two option here from the drop-down box: Select an existing Key pair or Create a new key pair. If you select Create a new key pair, a new key pair will be automatically created for you and Download Key Pair before you go launch your instance.

Note: You can access your instance after creating the key pair. If you don’t have a key pair, you will not able to access your instance.8.jpg

9. Click Launch Instance. You will able to see Launch Status. Now click “View Instance”.9.jpg

10. You instance configuration is complete. If you see the following status in your EC2 dashboard page: Instance state: running, Status Check column: 2/2 Checks.10.jpg

Steps for the task: Connecting to Amazon EC2 instance via SSH 

PuTTY  and PuTTY Key pair generating:

You need to Putty secure shell (SSH) client and Server’s Public DNS address or Public IP address to connect to your server from your local machines.

What is PuTTY: PuTTY is a free and open-source terminal emulator, serial console and network file transfer application. It supports several network protocols, including SCP, SSH, Telnet, login, and raw socket connection. It can also connect to a serial port. 

What is PuTTYgen: PuTTYgen is a key generator. It generates pairs of public and private keys to be used with WinSCP. PuTTYgen generates RSA, DSA, ECDSA, and Ed25519 keys.

What is PuTTY Pageant: Pageant is an SSH authentication agent. It holds your private keys in memory, already decoded so that you can use them often without needing to type a passphrase.

If you do not have Putty, go to the following website to download Putty:


As you remember, We downloaded a key-pair during our Amazon EC2 instance launch. The key pair has in two formats: .pem and .ppk. .pem extension file is used for the windows server connection RDP protocol (port 3389). We EC2 instance generated the key pair, It is by default encrypted key-pair. For RDP connection, We need to decrypt it to get the password for windows server login. The .ppk extension file is used in Putty SSH connection.

As we got .pem extension file during our EC2 Instance, for Putty SSH connection authentication, we need to convert the extension file from .pem to .ppk by using PuTTYgen.

How to convert key-pair by using PuTTYgen:

  1. Open your Puttygen (PuTTY key Generator) program. 11.jpg
  2. As we already have existing private key pair file. We will Load it to generate the private key. Click on” Load”. And load the existing key-pair file from your local machine where you save .pem file.12.jpg13
  3. Selecting the Type of Key:

PuTTYgen currently supports these types of key:
An RSA key for use with the SSH-2 protocol.
A DSA key for use with the SSH-2 protocol.
An ECDSA (elliptic curve DSA) key for use with the SSH-2 protocol.
An Ed25519 key (another elliptic curve algorithm) for use with the SSH-2 protocol.
An RSA key for use with the SSH-1 protocol.

4. Now save the key pair on your local machine as the private key and It will be saved as the .ppk file. 14.jpg


5. Now our EC2 key Pair private key is ready to authentication SSH connection. Now open your Putty Pageant. and add the ssh private key into the agent application. Putty pageant working as SSH authentication agent and it holds your key in memory.


Connect to the Amazon Ec2 instance using SSH and PuTTY:

All Amazon EC2 instance has been assigned two IP address at launch: Private address and public IP address. The public IP address that s directly connected to other network or via Internet through NAT. Private IP can only communicate within the private network and Public IP is reachable from the Internet.

Amazon Ec2 instance also provides two DNS which is mapped corresponding IP address respectively: Internal DNS for private IP and Public DNS for Public IP. The internal DNS name is only resolved within Amazon EC2 network and the public DNS name is resolved to the Public IP address outside the Amazon EC2 network and to the private IP address within the Amazon EC2 network as well.

  1. open your PuTTy.exe as your downloaded program already. Now we have to put hostname or IP address in the PuTTY program to establish an SSH connection. We can use Public DNS or Public IP address. 17.jpg
  2. Now provide the SSH authentication by uploading the private key-pair authentication file in the puTTY.18.jpg
  3. Click on Open. You will get the following message. Click on “Yes”.19.jpg
  4. The connection will be established. This is the way you will connect to the Amazon EC2 instance using SSH and PuTTY.20

Critical issues in Putty SSH connection: 

There are some critical issues you may face during your PuTTY Connection. If you are not aware of those issues we may fail to connect to your Amazon EC2 instance.

  1. Always enter your Public DNS or Public IP address in your PuTTY hostname field. You can not able to establish the connection via private IP address.
  2. Use The login username: ec2-user as login ID 
  3. You can not access your .pem file to establish PuTTY SSH connection. You have to convert the file from .pem to .ppk by PuTTYgen
  4. If everything is okay but you can not able to connect via PuTTy, check your Security Groups inbound. Allow inbound network communication for the Port number 22, SSH

Cost Analysis

Amazon EC2 Pricing: AWS provides you four option to pay Amazon EC2 price. There are  On-Demand, Reserved Instances, and Spot Instances, and Dedicated Hosts. On-Demand instances are recommended for:

  • If you prefer the low cost and flexibility of Amazon EC2 without long term commitment or any upfront payment. 
  • Short term or unpredictable workloads without interrupt in Application
  • If you are developing or testing application on Amazon EC2 for the first time.

On-Demand Pricing method: You have to pay for computing capacity by the hours without long-term commitments. Each instance type pricing is different and it varies based on regions as well. 

Spot instances are recommended for:

  • Applications that have flexible start and end times
  • Applications that are only feasible at very low computer prices
  • Users with urgent computing needs for large amounts of additional capacity

Spon instance pricing method:  The Spot price fluctuates based on the supply and demand of available unused EC2 capacity and it provides you at steep discount on unused EC2 capacity to On-Demand prices

Reserved Instances are recommended for:

  • Applications with steady state usage
  • Applications that may require reserve capacity
  • Customers that can commit to using EC2 over a 1 or 3-year term to reduce their total computing costs

Reserved Instance pricing method: Standard and Convertible Reserved Instance Pricing.

Standard Instance Pricing: It provides you with a significant discount ( up to 75% )  compare to on-demand instance pricing and can be purchased for a 1-year or 3-year term and can be purchased for a 1-year or 3-year term.

Which condition you will go with Standard pricing:  Customers have the flexibility to change the Availability Zone, the instance size, and networking type of their Standard Reserved Instances.

Convertible Reserved Instance Pricing: Convertible Reserved Instances provide you with a significant discount (up to 45%) compared to On-Demand and can be purchased for a 3-year term.

Which condition you will go with Convertible Reserved Instance Pricing: Purchase Convertible Reserved Instances if you need additional flexibility, such as the ability to use different instance families, operating systems, or tenancies over the Reserved Instance term.

Reserved Instance Payment Options: 

All Upfront option: Pay for the entire Reserved Instance term with one upfront payment.

Partial Upfront option: Make a low upfront payment first and are then charged a discounted hourly rate for the instance for the duration of the Reserved Instance term.

The No Upfront option does not require any upfront payment and provides a discounted hourly rate for the duration of the term.

Furthermore, If you reserved instance that is assigned to a specific Availability zone, AWS provide you reservation of capacity and extra confidence that you will able to get the benefit to launch your instance any time when you need. 

Dedicated host: A Dedicated Host is a physical EC2 server dedicated for your use.

  • Can be purchased On-Demand (hourly).
  • Can be purchased as a Reservation for up to 70% off the On-Demand price.

Dedication Host pricing method: The price for a Dedicated Host varies by instance family, region, and payment option. You have to pay for active dedication host per hours usage and you will not be charged for instance usage.Price is calculated based on On-Demand price method. You can also use three reservation pricing options.

Thank you 🙂


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s