“Amazon Elastic Compute Cloud (Amazon EC2) provides scalable computing capacity in the Amazon Web Services (AWS) cloud. Using Amazon EC2 eliminates your need to invest in hardware up front, so you can deploy and deploy applications faster. You can use amazon EC2 to launch as many or as few virtual servers as you need. configure security and networking, manage storage. Amazon EC2 enables you to scale up or down to handle changes in requirements or spikes in popularity, reducing your need to forecast traffic.”
Simplified: Think of EC2 as your basic desktop computer.
EC2 Instance Components
- AMIs (Linux/Windows)
- Instance Type (Processing Power)
- EBS (Local Storage)
- IP Addressing (Internet Access)
- Security Groups (Security)
Common Purchasing Options
On-demand purchasing allows you to choose any instance type you like and provision/terminate it at any time (on-demand)
- Is the most expensive purchasing option.
- Is the most flexible purchasing option.
- You are only charged when the instance is running (and billed by the hour).
- You can provision/terminate an on-demand instance at anytime.
Reserved purchasing allows you to purchase an instance for a set time period of one (1) or three (3) years.
- This allows for a significant price discount over using on-demand.
- You can select to pay upfront, partial upfront, no upfront.
- Once you buy a reserved instance, you own it for the selected time period and are responsible for the entire price – regardless of how often you use it.
Spot pricing is a way for you to “bid” on an instance type and only pay for and use that instance when the spot price is equal to or below your “bid” price.
- This option allows amazon to sell the use of unused instances, for short amounts of time, at a substantial discount.
- Spot prices fluctuate based on supply and demand in the spot marketplace.
- You are charged by the minute.
- When you have an active bid, an instance is provisioned for you when the spot price is equal to or less than you bid price.
- A provisioned instances automatically terminate when the spot price is greater than your bid price.
Free Tier use is avaiable for EC2.
- Purchased Options: (most common – not an inclusive list)
- Instance Type – the instance’s processing capacity (think CPU);
- General Purpose
- Compute optimized
- GPU optimized
- Memory optimized
- Storage Optimized
- EBS Optimized: (an option for higher IOPS performance)
- AMI Type – (think operating system):
- Linux (price varies based on distro/software packages)
- windows (price varies based on version/software packages)
- Data Transfer – in/out of the instance.
- Region the instance is provisioned in.
Amazon Machine Image (AMI)
“An Amazon Machine Image (AMI) provides the information required to launch an instance, which is a virtual server in the cloud. You specify an AMI when you launch an instance, and you can launch as many instances from the AMI as you need. You can also launch instances from as many different AMIs as you need.”
Simplified: A preconfigured package required to launch and EC2 instance; includes an operating system, software packages and other required settings.
AMIs come in three main categories:
Note:When you lanuch an EC2 Instance, the first thing you do is select an AMI
- Community AMIs:
- Free to use
- Generally, with these AMIs you are just selecting the OS you want
- AWS Marketplace AMIs:
- Pay to use
- Generally comes packaged with additional, licensed software
- My AMIs:
- AMIs that you create yourself
“When you launch an instance, the instance type that you specify determines the hardware of the host computer used for your instance. Each instance type offers different compute, memory and storage capabilities and are grouped in instance families based on those capabilities. select an instance type based on the requirements or software that you plan to run on your instance.”
Simplified: The Instance Type is the CPU (computer power) of your instance.
Instance Type Components
- A way of categorizing instance types based on the what they are optimized to do
- Subcategory for each family type
- The number of virtual CPUs the instances type uses
- Memory (GiB):
- The amount of RAM the instance type uses
- Instance Storage (GB):
- The local instance storage volume (your hard drive)
- EBS-Optimized Available:
- Indicates is EBS-Optimized is an option for the instance type
- Network Performance:
- Network Performance rating based on its data transfer rate (bandwidth capability)
“Amazon Elastic Block Store (Amazon EBS) provides block level storage volumes for use with EC2 instances. EBS volumes are highly available and reliable storage volumes that can be attached to any running instance that is in the same Availability Zone. EBS volumes that are attached to an EC2 instance are exposed as storage volumes that persist independently from the life of the instance.”
Simplified: EBS is a storage volume for an EC2 instance. (Think of it as a hard drive)
“IOPS are a unit of measure representing Input/Output Operations per Second. The operations are measured in KiB, and the underlying drive determines the maximum amount of data that a volume type counts as a single I/O. I/O size is capped at 256 KiB for SSD volumes and 1,024 KiB for HDD volumes because SSD volumes handle small or random I/O much more efficiently than HDD volumes.”
The amount of data that can be written to or retrieved from EBS per second.
More IOPS means better volume performance (faster read/write speeds)
The larger the storage size (in GiB), the more IOPS the volume has – EBS volume size.
“Root” vs. Additional EBS Volumes
- Every EC2 instance MUST have a “root” volume, which may or may not be EBS.
- By default, EBS “root” volumes are set to be deleted when the instance is terminated. However, you can choose to have EBS volumes persist after termination.
- During the creation of an EC2 instance (or anytime afterward) you can add additional EBS Volumes to the instance.
- any additional volume can be attached or detach from the instance at any time, and is NOT deleted (be default) when the instance is terminated.
Note:This means that you can “swap” EBS volumes between different EC2 instances, by “detaching” it from one and “attaching” it to another.
- A snapshot is an “image” of an EBS volume that can be stored as a backup of the volume OR used to create a duplicate.
- A snapshot is NOT an active EBS volume. You cannot attach or detach a snapshot to an EC2 instance.
- To restore a snapshot, you need to create a new EBS volume using the snapshot as its template.
“A security group acts as a virtual firewall that controls the traffic for one or more instances. When you launch an instance one or more security groups with the instance. You add rules to each security group that allow traffic to or from its associated instances. You 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 instance.”
Simplified: Securiy Groups are very similar to NACLs in that they allow/deny traffic. However, security groups are found on the instance level (as opposed to the subnet level). In addition, the way allow/deny “rules” work are different from NACLs.
Inbound and Outbound Rules
- All traffic is DENIED unless there is an EXPLICIT ALLOW rule for it.
- There are no DENY rules – only ALLOW rules.
“Amazon EC2 and Amazon VPC support both the IPv4 and IPv6 addressing protocols. By default, Amazon EC2 and Amazon VPC use the IPv4 addressing protocol; you can’t disable this behavior. When you create a VPC, you must specify an IPv4 CIDR block (a range of private IPv4 addresses). You can optionally assign an IPv6 CIDR block to your VPC and subnets, and assign IPv6 addresses from that block to instances in your subnet. IPv6 addresses are reachable over the Internet.”
- Providing an EC2 instance with public IP address.
- An IP address is the instance’s “address” on the network.
- IPv6 is not supported for the EC2-Classic platform. IPv6 is currently supported in the US East (Ohio) region only.
Public vs. Private IP Addresses
Private IP Address
- By default, All EC2 instances have a private IP address.
- Private IP addresses allow for instances to communicate with each other as long as they are located in the same VPC (or broader private network).
Public IP Address
- EC2 Instances can be launched with our without a public IP address (by default), depending on VPC/subnet settings.
- Public IP addresses are REQUIRED for the instance to communicate with the Internet.
Note:The “default” VPC and subnets are configured so that any new instance that is provisioned has a public IP address,
Launching an EC2 Instance
- Select an AMI
- Select an Instance Type
- Configure Instance Details:
- We are going to use this opportunity to run a Bash Script that installs Apache.
12345#!/bin/bashyum update -yyum update -yyum install -y httpdservice httpd start
- We are going to use this opportunity to run a Bash Script that installs Apache.
- Add Storage
- Add a Tag (give the instance a name)
- Configuration/assign a Security Group
- Review & Launch
- Create & download a Key Pair
Logging in to Instance (SSH)
- Select the instance
- Under “Action”, choose “Connect”
- Follow the instructions
- Open a terminal to access the command line
- Navigate to the directory that contains the key pair downloaded
- Run the chmod command on the key pair to change its permissions
- Run the “example” command
You should now be connected to the instance