Chapter-1 EC2 Instance Creation

Amazon EC2

General

  • Amazon Elastic Compute Cloud (Amazon EC2) is a web service that provides resizable compute capacity in the cloud.
  • It is designed to make web-scale computing easier for developers
  • You are limited to running up to a total of 20 On-Demand instances across the instance family, purchasing 20 Reserved Instances, and requesting Spot Instances per your dynamic spot limit per region (by default)
  • Amazon EC2 currently supports a variety of operating systems including: Amazon Linux, Ubuntu, Windows Server, Red Hat Enterprise Linux, SUSE Linux Enterprise Server, Fedora, Debian, CentOS, Gentoo Linux, Oracle Linux, and FreeBSD
  • EC2 compute units (ECU) provide the relative measure of the integer processing power of an Amazon EC2 instance
  • With help of EC2 you have full control at the operating system layer

Let’s understand EC2 step by step. First we will create EC2 instance and will access EC2 instance.

Points to be discussed:

  • Create EC2 Instance.
  • How to login EC2 instance through command line?
  • How to login EC2 in window environment?
  • How to check Http file through AWS EC2 Public IP?
  • Questions and Answers.
EC2 Instance Creation:

STEP 1: Login to Amazon Console. If you don’t have login access then register it and login to AWS console.

STEP 2: Click on Services-> EC2

AWS SERVICES

STEP 3: We can see Resources and can create EC2 instance. Click on Launch Instance under Launch Instance section.

STEP 4: Choose Amazon Linux 2 AMI (HVM), SSD Volume Type. We can choose any option based on our needs.

STEP 5: Next Screen, we see Instance type page.

There are multiple types of Instances:

Now we select Free Tier eligible t2.micro  andproceed.

Click on Configure Instance Details.

STEP 6: Configure Instance Details

We have to check all details and have to select appropriate option as per our need.

Number of Instances: have to select 1 now but we can select as per our need.

We have option for Auto Scaling Group which we will study later.

Purchasing option: Based on availability zones and its price, we can request for Spot Instances.

Network: Default VPC will be added. We can create New VPC as well if we want to create.

Subnet: we can select default value as well or can select any subnet.

Similarly we can select values for –

Placement group- uncheck this field.

Capacity Reservation- select Open for this or we can create new capacity Reservation.

IAM role- Select none or create IAM role.

Shutdown behavior –             Select Stop value for this.

Enable termination protection- Check this field.

Fill other fields as per below value:

Click on Add Storage tab -Next field.

STEP 7: Add Storage

We can select storage type of any volume type. Even we can provide Storage size based on our needs. By Clicking on “ADD NEW VOLUME” new Volume type can be added.

Now click on Add Tags.

STEP 8: ADD Tags: We can add tags to created EC2 instance.

We can add another tag by clicking on “Add another tag”.

STEP 9: Configure Security Group

Next click on Review and Launch.

Step 10: Review Instance Launch

Let’s review it:

Click on Launch.

After clicking on Launch, popup appears for key pair:

Let’s create new key:

Click on Download Key Pair.

Save it in any folder because it needs to connect EC2 instance.

Now launch your instance by clicking on Launch Instance.

After few seconds, we can see EC2 instance:

It is in running status.

Now we will see its more details:

  1. Description Tab:

Under Description tab, we can see EC2 instance details.

  • Status Checks:
  • Monitoring: It can be monitored by Cloud watch.
  • Tags:

            ************************************************************************

            How to login EC2 instance through command line?
  1. We have stored pem file in folder (discussed in previous steps)
  2. Open cmd and navigate to the folder where we have put pem file.

Run below command to provide full access:

CHMOD 400 LearningEC2.pem

  • Run below command to open EC2 instance:

ssh ec2-user@54.215.191.60 -i LearningEC2.pem

Type yes if any question is asked.

cloudvikas@personal  ~/Documents/AWS WEBSITE/test/SSH

$ ls

LearningEC2.pem

cloudvikas@personal  ~/Documents/AWS WEBSITE/test/SSH

$ CHMOD 400 LearningEC2.pem

$ ssh ec2-user@54.216.191.60 -i LearningEC2.pem

The authenticity of host ‘54.215.191.60 (54.215.191.60)’ can’t be established.

ECDSA key fingerprint is SHA256:w38Wj5jrEk4jhXmyMrtyuuiikih6xgn8qw.

Are you sure you want to continue connecting (yes/no/[fingerprint])? y

Please type ‘yes’, ‘no’ or the fingerprint: yes

Warning: Permanently added ‘54.216.191.60’ (ECDSA) to the list of known hosts.

       __|  __|_  )

       _|  (     /   Amazon Linux 2 AMI

      ___|\___|___|

https://aws.amazon.com/amazon-linux-2/
8 package(s) needed for security, out of 17 available

Run “sudo yum update” to apply all updates.

[ec2-user@ip-172-11-1-111 ~]$

***********************************************************************

How to login EC2 in window envioronment?

            SSH Chrome Extension: we can use SSH client extension for chrome. Let’s understand how can we use SSH Client extension?

  1. Install ssh chrome extension

  • Click on Secure Shell App
  • Navigate to AWS Console and copy IP address.

For identity , navigate to pem file folder and convert into public key. We have kept pem file in test folder and open cmd and navigate to test folder.

Run below command to convert into public key.

ssh-keygen -y -f LearningEC2.pem > LearningEC2.pub

then run ren command to convert LearningEC2.pem into LearningEC2 (w/o extension).

C:\Users\Cloudvikas\Documents\AWS WEBSITE\test>ssh-keygen -y -f LearningEC2.pem > LearningEC2.pub

C:\Users\Cloudvikas\Documents\AWS WEBSITE\test>ren LearningEC2.pem LearningEC2

C:\Users\Cloudvikas\Documents\AWS WEBSITE\test>dir

12/19/2018  01:29 PM    <DIR>          .

12/19/2018  01:29 PM    <DIR>          ..

12/18/2018  08:16 PM             1,696 LearningEC2

12/19/2018  01:28 PM               382 LearningEC2.pub

Now press keyword  ENTER   and EC2 instance will be connected in backend.

Connecting to ec2-user@54.215.191.60…

The authenticity of host ‘54.215.191.60 (54.215.191.60)’ can’t be established.

ECDSA key fingerprint is SHA256:w38Wj5jrEk4qwertyuioih6xgn8qw.

Are you sure you want to continue connecting (yes/no/[fingerprint])? yes

Warning: Permanently added ‘54.215.191.60’ (ECDA) to the list of known hosts.

       __|  __|_  )

       _|  (     /   Amazon Linux 2 AMI

      ___|\___|___|

https://aws.amazon.com/amazon-linux-2/
8 package(s) needed for security, out of 17 available

Run “sudo yum update” to apply all updates.

[ec2-user@ip-172-31-1-111 ~]$ sudo su

[root@ip-172-31-1-111 ec2-user]#

It is connected now.

            ***********************************************************************************

How to check Http file through AWS EC2 Public ip?

Steps:

  1. Type command sudo su for admin

[ec2-user@ip-172-11-1-111 ~]$ sudo su

[root@ip-172-11-1-111 ec2-user]#

  • Type below command for window update:

yum update -y

  • Type below command for http

yum install httpd -y

It will install required packages for Apache.

  • Navigate to html directory:

cd /var/www/html

  • Type something and save it through nano command.

<html><h1>welcome to cloudvikas</h1></html>

  • Type ls and check file present or not.
[root@ip-172-31-1-111 ec2-user]# cd /var/www/html

[root@ip-172-31-1-111 html]# nano index.html

[root@ip-172-31-1-111 html]#ls

Index.html

Type below command to start service:

Service httpd start

Type below command if your EC2 instance is down or not running on:

Type ip address in browser and check:

It will redirect the page through public ip address and can see

Welcome to cloudvikas.

*****************************************************************************************

Questions and Answers:
Question : Why Key pairs are used in EC2 Instances?

Key pairs are used to securely connect to EC2 instances:

  • A key pair consists of a public key that AWS stores, and a private key file that you store
  • For Windows AMIs, the private key file is required to obtain the password used to log into your instance
  • For Linux AMIs, the private key file allows you to securely SSH into your instance
  • Why Metadata and User Data are used in EC2 Instance?

Metadata and User Data:

  • User data is data that is supplied by the user at instance launch in the form of a script
  • Instance metadata is data about your instance that you can use to configure or manage the running instance
  • User data is limited to 16KB
  • User data and metadata are not encrypted.
  • The Instance Metadata Query tool allows you to query the instance metadata without having to type out the full URI or category names
Q: What is Amazon Elastic Compute Cloud (Amazon EC2)?

Amazon Elastic Compute Cloud (Amazon EC2) is a web service that provides resizable compute capacity in the cloud.

Q: How many instances can I run in Amazon EC2?

You are limited to running On-Demand Instances per your vCPU-based On-Demand Instance limit, purchasing 20 Reserved Instances, and requesting Spot Instances per your dynamic Spot limit per region. New AWS accounts may start with limits that are lower than the limits described here.
If you need more instances, complete the Amazon EC2 limit increase request form with your use case, and your limit increase will be considered.

Related Topics:

Chapter-2 EC2 Instance Termination

Chapter-3 EC2-Security Groups

Chapter-4 EC2 EBS

Chapter-5 EC2-CloudWatch

Chapter 6 AWS CLI

Chapter 7 AWS Boot Strap Scripts

EC2 Knowledge Check