AWS Compute

Basic Computer Components

Operating System (linux, MAC, Windows, Ubuntu), CPU (Processing Power), Hard Drive (Local Storage), Network Card (Internet Access), Firewall (Security), RAM (Random Access Memory)

What is EC2 (Elastic Compute Cloud)?

EC2 provides scalable computing capacity in the AWS cloud. Using EC2 eliminates our need to invest in hardware up-front, so we can develop and deploy applications faster. We can use EC2 to launch as many or as few virtual servers as we need, configure security and networking and manage storage. EC2 enables us to scale up or down to handle changes in requirements or spikes in data and system usage, reducing our need to forecast traffic.

EC2 Instance Components

  • AWS Machine Image (Operating System, Linux or Windows)
  • Instance Type (Processor Power)
  • EBS (Elastic Block Storage - Local Storage)
  • IP Address (Internet Access)
  • Security Groups (Security)
  • RAM

EC2 Instance Purchasing Options

On Demand: On-demand purchasing allows us to choose any instance type we like and provision/terminate it at any time (on-demand).

  1. This is most expensive and most flexible purchasing option.
  2. We are only charged when the instance is running (and billed by the hour)
  3. We can provision/terminate an on-demand instance at anytime.

Reserved: Reserved purchasing allows us to purchase an instance for a set time period of one or three years.

  1. This allows for a significant price discount over using on demand.
  2. We can select to pay upfront, partial upfront, no upfront.
  3. Once we buy a reserved instance, we own it for the selected time period and are responsible for the entire price - regardless of how often we use it.

Spot: Spot pricing is a way for us to bid on an instance type, and then only pay for and use that instance when the spot price is equal to or below our bid price.

  1. This option allows Amazon to sell the use of unused instances, for short amounts of time, at a substantial discount.
  2. Spot prices fluctuate based on supply and demand in the spot marketplace.
  3. We are charged by the minute.
  4. When we have an active bid, an instance is provisioned for us when the spot price is equal to or less than our bid price.
  5. A provisioned instance automatically terminates when the spot price is greater than our bid price.

Benefits and Use Cases

Additional Benefits

  1. Elastic web-scale computing
  2. Full root control of the server
  3. Flexible options (many instance types, AMIs to choose from)
  4. Integrates with almost all other AWS services
  5. Extremely reliable
  6. High level of built-in security
  7. Inexpensive
  8. Very easy to start (create an EC2 instance within minutes)

Primary Use Cases

  1. Multi-tier web applications
  2. Web servers
  3. Batch processing
  4. Video processing
  5. GPU intensive workloads

Amazon Machine Image (AMI)

An AMI provides the information required to launch an instance, which is virtual server in the cloud. We specify an AMI when we launch an instance, and we can launch as many instances from AMI as we need. We can also launch instances from as many different AMIs as we need.

Instance Type

When we launch an instance, the instance type that we specify determines the hardware of the host computer used for our instance. Each instance type offers different compute, memory and storage capabilities and are grouped in instance families based on these capabilities. Select an instance type based on the requirements of the application or software that we plan to run on our instance.

Elastic Block Storage - EBS

  1. Every EC2 Instance MUST have a root volume, which may or may not be EBS.
  2. By default, EBS root volumes are set to be deleted when the instance is terminated. However, we can choose to have EBS volumes persist after termination.
  3. During the creation of an EC2 instance, we can add additional EBS volumes to the instance.
  4. Any additional volume can be attached or detached from the instance at any time, and is NOT deleted (the default) when the instance is terminated.

Security Groups

An SG acts as a virtual firewall that controls the traffic for one or more instances. When we launch an instance, we associate one or more security groups with the instance. We add rules to each security group that allow traffic to or from its associated instances. we can modify the rules for a security group at any time; the new rules are automatically applied to all instances that are associated with the security group. When we decide whether to allow traffic to reach an instance, we evaluate all the rules from all the security groups that are associated with the instance.

Launching a virtual server - Elastic Cloud Compute (EC2)

In services, search EC2 and Click EC2. Next page, in Create Instance, Click Launch Instance.

Step 1: Choose an Amazon Machine Image (AMI)

Select a machine image as per your requirements. We are selecting Amazon Linux AMI 2018.03.0 (HVM) machine for this instance.

Step 2: Choose an Instance Type

Select an instance as per your requirements. We are selecting t2 micro for this instance.

Step 3: Configure Instance Details

We will be selecting Number of Instances = 1

Keeping default values for Network, Subnet, Auto-assign Public IP, Capacity Reservation, Shutdown behavior, and Tenancy.

For IAM role, right click and open Create new IAM role in a new browser tab.

In the IAM Role tab, Click Create role.

Next page, select EC2 and click Next: Permissions

Next page, in Filter policies search bar, type ssm and select AmazonEC2RoleforSSM. SSM stands for Simple Systems Manager which will be the role for our login to EC2. Click Next: Tags.

Next page is optional so we will click Next: Review.

Next page, we will input Role name: EC2Role and Click Create role. We will close this Create Role tab now and go back to EC2 instance tab.

On EC2 instance - Step 3 page, hit refresh symbol for IAM role. Now in the drop down of IAM role, we can see our newly created role. Select that role. Click Next: Add Storage

Step 4: Add Storage

We will stick with default settings for storage and click Review and Launch.

Note: We have skipped Step 5: Add Tags and Step 6: Configure Security Group.

Step 7: Review Instance Launch

Click Launch

A pop will be asking to Select an existing key pair or create a new key pair.

Since we have created SSM role in step 3 above, we do not need a key pair. Select Proceed without a key pair in the drop down. Click Launch Instances.

Next Page, Click View Instances.

Next Page, When instance state shows green light, our instance is Up and running.

In order to terminate or stop our instance, we can click Actions-->Instance State-->stop or terminate. This is recommended when we are not using our instance.

Next we will explore our newly created instance.

Connecting EC2 using Windows (putty)

  1. Open PuTTYgen. Make sure RSA is selected. Click Load and find the .pem file downloaded while creating EC2 Instance and click Open.
    • Note: We did not download private key in above EC2 instance.
  2. Click Save Private Key. A pop up will ask to save the key without a pass phrase. Click Yes and save the file in the desired location.
  3. Copy Public DNS link (NOT just the IP) from EC2 instance. In Putty, goto Session, and input ec2-user@public DNS links copied earlier in Host sections. In Putty, goto SSH-->auth, click Browse, Locate the file saved in Step 2 and select the file. Click Session-->Save, and SSH-->auth, click open.
  4. A command prompt pop will open. Type ifconfig to check various information for the EC2 instance.

Next: Auto Scaling Groups