01 - AWS Basics - Creating EC2 Instances - 20130517
01 - AWS Basics - Creating EC2 Instances - 20130517
Table of Contents
Introduction ................................................................................................................................................................ 3
Objectives .............................................................................................................................................................. 3
Prerequisites .......................................................................................................................................................... 3
Background................................................................................................................................................................ 4
Amazon EC2 .......................................................................................................................................................... 4
Amazon Machine Images (AMIs) ........................................................................................................................... 4
Instance Types and Families ................................................................................................................................. 4
Regions and Availability Zones (AZs) .................................................................................................................... 5
Amazon Simple Storage Service (S3) ................................................................................................................... 6
Amazon Elastic Block Store (EBS) ........................................................................................................................ 6
Instance Store and EBS-Backed Instances ........................................................................................................... 6
Amazon Virtual Private Cloud (VPC) ..................................................................................................................... 7
EC2-Classic and EC2-VPC .................................................................................................................................... 7
Security Groups ..................................................................................................................................................... 7
Public and Private IP Addresses............................................................................................................................ 7
Amazon EC2 Instance IP Addressing .................................................................................................................... 7
Elastic IP Addresses (EIPs) ................................................................................................................................... 8
EC2 Overview Diagram ......................................................................................................................................... 8
Additional Information ............................................................................................................................................ 8
Hands-On Exercise.................................................................................................................................................... 9
Start your qwikLAB™ ............................................................................................................................................. 9
AWS Management Console................................................................................................................................. 10
Launch a Linux Instance ...................................................................................................................................... 11
Configure the Linux Instance ............................................................................................................................... 18
Connect to the web server ................................................................................................................................... 19
Assign a Static IP Address................................................................................................................................... 19
Summary ................................................................................................................................................................. 23
Appendix A - Connecting to your EC2 Instance via SSH ........................................................................................ 24
Windows .................................................................................................................................................................. 24
OS X and Linux........................................................................................................................................................ 26
Copyright © 2013 Amazon Web Services, Inc. or its affiliates. All rights reserved.
This work may not be reproduced or redistributed, in whole or in part,
without prior written permission from Amazon Web Services, Inc.
Commercial copying, lending, or selling is prohibited.
© 2013 Amazon Web Services, Inc. or its affiliates. All rights reserved. Page 2
AWS Basics: Creating EC2 Instances (with Linux)
Introduction
Objectives
This lab leads you through the steps to launch and configure your first virtual machine in the Amazon cloud.
At the end of this lab you will have deployed a simple web server which includes an informational page to display
details of your virtual web server instance.
Prerequisites
To successfully complete this lab, you should be familiar with basic Linux server administration and comfortable
using the Linux command-line tools.
© 2013 Amazon Web Services, Inc. or its affiliates. All rights reserved. Page 3
AWS Basics: Creating EC2 Instances (with Linux)
Background
Amazon EC2
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.
Amazon EC2’s simple web service interface allows you to obtain and configure capacity with minimal friction. It
provides you with complete control of your computing resources and lets you run on Amazon’s proven computing
environment. Amazon EC2 reduces the time required to obtain and boot new server instances to minutes,
allowing you to quickly scale capacity, both up and down, as your computing requirements change. Amazon EC2
changes the economics of computing by allowing you to pay only for capacity that you actually use. Amazon EC2
provides developers the tools to build failure resilient applications and isolate themselves from common failure
scenarios.
An AMI contains all information necessary to boot an Amazon EC2 instance with your software. An AMI is like a
template of a computer's root volume. For example, an AMI might contain the software to act as a web server
(Linux, Apache, and your web site) or it might contain the software to act as a Hadoop node (Linux, Hadoop, and
a custom application). You launch one or more instances from an AMI. An instance might be one web server
within a web server cluster or one Hadoop node.
Amazon Elastic Compute Cloud (Amazon EC2) instance types are grouped into the general families described in
the following table.
Family Description
Micro Provide a small amount of consistent CPU resources and enable you to burst CPU capacity when
additional cycles are available. They're well-suited for lower throughput applications and websites
that consume significant compute cycles periodically.
Cluster Have a very large amount of CPU coupled with increased networking performance. They're well-
Compute suited for High Performance Compute (HPC) applications and other demanding network-bound
applications.
© 2013 Amazon Web Services, Inc. or its affiliates. All rights reserved. Page 4
AWS Basics: Creating EC2 Instances (with Linux)
Family Description
High CPU Have proportionally more CPU resources than memory (RAM). They're well-suited for compute-
intensive applications.
High I/O Provide tens of thousands of low-latency, random I/O operations per second (IOPS) to an
application. They're well-suited for NoSQL databases, clustered databases, and OLTP (online
transaction processing) systems.
High Have proportionally more memory resources. They're well suited for high-throughput applications,
Memory such as database and memory caching applications.
High Provide very high storage density and high sequential read and write performance per instance.
Storage They are well-suited for data warehousing, Hadoop/MapReduce, and parallel file systems.
Cluster GPU Provide general-purpose graphics processing units (GPUs), with proportionally high CPU and
increased network performance for applications that benefit from highly parallelized processing.
They're well-suited for HPC applications as well as rendering and media processing applications.
High- Have large amounts of memory coupled with high CPU and network performance. These
Memory instances are well suited for in-memory analytics, graph analysis, and scientific computing
Cluster applications.
Each region is completely independent. Each Availability Zone is isolated, but the Availability Zones in a region
are connected through low-latency links. The following diagram illustrates the relationship between regions and
Availability Zones.
© 2013 Amazon Web Services, Inc. or its affiliates. All rights reserved. Page 5
AWS Basics: Creating EC2 Instances (with Linux)
Instances that use instance store for the root device automatically have instance store volumes available, with
one serving as the root device volume. When an instance is launched, the image that is used to boot the instance
is copied to the root volume. Any data on the instance store volumes persists as long as the instance is running
and is deleted when the instance fails or terminates.
Instances that use Amazon EBS for the root device automatically have an Amazon EBS volume attached. When
you launch an Amazon EBS-backed instance, we create an Amazon EBS volume for each EBS snapshot
referenced by the AMI you use. You can optionally use other Amazon EBS volumes or instance store volumes.
© 2013 Amazon Web Services, Inc. or its affiliates. All rights reserved. Page 6
AWS Basics: Creating EC2 Instances (with Linux)
A virtual private cloud (VPC) is a virtual network dedicated to your AWS account. It is logically isolated from other
virtual networks in the AWS cloud. You can launch your AWS resources, such as Amazon EC2 instances, into
your VPC. You can configure your VPC; you can select its IP address range, create subnets, and configure route
tables, network gateways, and security settings.
Your AWS account is capable of launching instances either into both platforms or only into EC2-VPC, on a region
by region basis. If you can launch instances only into EC2-VPC, we create a default VPC for you. Then, when
you launch an instance, we launch it into your default VPC, unless you create a non-default VPC and specify it
when you launch the instance.
A default VPC combines the benefits of the advanced features provided by EC2-VPC with the ease of use of
EC2-Classic. If you have a default VPC and don't specify a subnet when you launch an instance, the instance is
launched into your default VPC. You can launch instances into your default VPC without needing to know
anything about Amazon VPC.
Security Groups
A security group acts as a firewall that controls the traffic allowed to reach one or more instances. When you
launch an instance, you assign it one or more security groups. You add rules to each security group that control
traffic for the instance. You can modify the rules for a security group at any time; the new rules are automatically
applied to all instances to which the security group is assigned.
Security groups for EC2-VPC have additional capabilities that aren't supported by security groups for EC2-
Classic.
Amazon EC2 also provides an internal DNS name and a public DNS name that map to the private and public IP
addresses respectively. The internal DNS name can only be resolved within Amazon EC2. The public DNS
name resolves to the public IP address outside the Amazon EC2 network and the private IP address within the
Amazon EC2 network.
When you launch an instance, we allocate a private IP address for the instance using DHCP. Private IP
addresses are not reachable from the Internet. Each instance that you launch into a VPC has a default network
© 2013 Amazon Web Services, Inc. or its affiliates. All rights reserved. Page 7
AWS Basics: Creating EC2 Instances (with Linux)
interface. The network interface specifies the primary private IP address for the instance. If you don't select a
primary private IP address, we select an available IP address in the subnet's range.
Each instance is provided an internal DNS hostname that resolves to the private IP address of the instance in
EC2-Classic or your VPC. We can't resolve the DNS hostname outside the network that the instance is in.
When you launch an instance in EC2-Classic or a default subnet in EC2-VPC, we allocate a public IP address for
the instance. We provide each instance that has a public IP address with an external DNS hostname. We
resolve an external DNS hostname to the public IP address of the instance outside the network of the instance,
and to the private IP address of the instance from within the network of the instance.
Additional Information
This lab guide gives a brief overview of Amazon EC2 concepts. For additional information, please refer to the
official Amazon Web Services Documentation for EC2 at: https://aws.amazon.com/documentation/ec2/
© 2013 Amazon Web Services, Inc. or its affiliates. All rights reserved. Page 8
AWS Basics: Creating EC2 Instances (with Linux)
Hands-On Exercise
Start your qwikLAB™
a. Duration - The time the lab will run for before shutting itself down.
b. Setup Time - The estimated lab creation time on starting the lab.
c. AWS Region - The AWS Region the lab resources are being created in.
2)
4. Copy the Password provided.
a. Hint: selecting the value shown and using Ctrl+C works best
© 2013 Amazon Web Services, Inc. or its affiliates. All rights reserved. Page 9
AWS Basics: Creating EC2 Instances (with Linux)
6. Make sure that you are not logged into any other instances of the AWS console (in a student account or your
own account), as this may cause conflicts when you open the console and log in below for this lab.
Enter the User Name ‘awsstudent’ and paste the password you copied from the lab details in qwikLAB™
into the Password field.
In this step you logged into the AWS Management Console using login credentials for a user provisioned
via AWS Identity Access Management in an AWS account by qwikLAB™.
2. Select or confirm that the same AWS Region that you saw in your QwikLab lab screen is already set in the
AWS Management Console
© 2013 Amazon Web Services, Inc. or its affiliates. All rights reserved. Page 10
AWS Basics: Creating EC2 Instances (with Linux)
© 2013 Amazon Web Services, Inc. or its affiliates. All rights reserved. Page 11
AWS Basics: Creating EC2 Instances (with Linux)
3. Depending upon the resources or OS your instance requires, you may select another type. As we require a
Linux instance, select the Basic 64-bit Amazon Linux AMI.
© 2013 Amazon Web Services, Inc. or its affiliates. All rights reserved. Page 12
AWS Basics: Creating EC2 Instances (with Linux)
5. In the next screen, copy & paste the following initialization script (you may need to type this into a text editor
and copy & paste the results) into the User Data field (this will automatically install and start Apache on
launch). Then click Continue.
#!/bin/sh
yum -y install httpd php
chkconfig httpd on
/etc/init.d/httpd start
© 2013 Amazon Web Services, Inc. or its affiliates. All rights reserved. Page 13
AWS Basics: Creating EC2 Instances (with Linux)
© 2013 Amazon Web Services, Inc. or its affiliates. All rights reserved. Page 14
AWS Basics: Creating EC2 Instances (with Linux)
7. Next, choose a “friendly name” for your instance. This name, more correctly known as a tag, will appear in
the console once the instance launches. It makes it easy to keep track of running machines in a complex
environment. We named ours “Self-Paced_Lab_1”; however the only thing that matters is whether the name
is meaningful to you. Put the name you choose in the Value field (see below). Then click Continue.
8. The Wizard will select the only EC2 Instance Key Pair in the account, the one created by qwikLAB™.
9. Click Continue.
© 2013 Amazon Web Services, Inc. or its affiliates. All rights reserved. Page 15
AWS Basics: Creating EC2 Instances (with Linux)
10. Create a Security Group, which will be your firewall rules. We named this one “Self-Paced_Lab_1”. Again,
the name is up to you.
a. Make sure to open two ports: 22 (SSH) and 80 (HTTP).
b. Port 22 is there by default.
c. Select Custom TCP Rule, Enter 80 in port range/click add rule.
d. Your TCP Port (Services) list should look like this when complete.
© 2013 Amazon Web Services, Inc. or its affiliates. All rights reserved. Page 16
AWS Basics: Creating EC2 Instances (with Linux)
12. You will receive a popup window notifying you your instances are launching. Click “Close” to continue.
© 2013 Amazon Web Services, Inc. or its affiliates. All rights reserved. Page 17
AWS Basics: Creating EC2 Instances (with Linux)
1. Log in to your instance using SSH. For instructions, see Appendix A - Connecting to your EC2 Instance.
2. The following must be typed at the $ prompt of your SSH session
cd /var/www/html
sudo vi index.php
3. If you are an experienced Linux user, you should know the basics of vi, the default text editor. Otherwise you
may want to check out a vi tutorial. Here’s a tutorial that has everything you’ll need in a single HTML page:
http://www.tjhsst.edu/~dhyatt/superap/vi.html. More documentation is available from then VIM project, the
most popular implementation of vi: http://vimdoc.sourceforge.net/.
4. After starting vi, to start editing, press “i” to turn on insert mode.
6. In insert mode, you can place the cursor where you want to paste your copied text, and click the right-mouse
button.
© 2013 Amazon Web Services, Inc. or its affiliates. All rights reserved. Page 18
AWS Basics: Creating EC2 Instances (with Linux)
<?php
$url = "http://169.254.169.254/latest/meta-data/instance-id";
$instance_id = file_get_contents($url);
echo "Instance ID: <b>" . $instance_id . "</b><br/>";
$url = "http://169.254.169.254/latest/meta-data/placement/availability-zone";
$zone = file_get_contents($url);
echo "Zone: <b>" . $zone . "</b><br/>";
?>
Note: If for some reason vi is interrupted in the middle of editing (for example through a reboot), then it
will salvage the currently edited file. After starting vi again, it will offer to recover the file for you. Just
follow the instructions and proceed with the instructions above. You may or may not need to change or
delete existing lines using the “i” or “dd” commands in vi.
2. Enter the DNS name of your instance into your browser and connect to the server.
a. If successful, you will see your instance ID and Zone appear:
© 2013 Amazon Web Services, Inc. or its affiliates. All rights reserved. Page 19
AWS Basics: Creating EC2 Instances (with Linux)
4. After confirmation, you’ll see your newly allocated EIP. Right-click on it and choose Associate from the pop-
up menu.
5. A popup will allow you to associate the EIP with one of your running instances. Choose the instance that you
just launched and click Yes, Associate:
© 2013 Amazon Web Services, Inc. or its affiliates. All rights reserved. Page 20
AWS Basics: Creating EC2 Instances (with Linux)
7. And your instance should now report its new IP address in the console:
© 2013 Amazon Web Services, Inc. or its affiliates. All rights reserved. Page 21
AWS Basics: Creating EC2 Instances (with Linux)
© 2013 Amazon Web Services, Inc. or its affiliates. All rights reserved. Page 22
AWS Basics: Creating EC2 Instances (with Linux)
Summary
Congratulations! You now have successfully:
Learned about the basic concepts and terminology of the Amazon Elastic Compute Cloud (EC2) service,
Created your own Amazon EC2 server instance running Linux in the AWS cloud,
Modified it to run a web server with a page that displays machine-specific information,
Assigned a fixed public IP address (Elastic IP) to your instance.
We hope you enjoyed working through this tutorial and that you now have everything you need to start using EC2
for your own projects. Please feel free to explore our other self-paced labs to learn more about Amazon Web
Services.
© 2013 Amazon Web Services, Inc. or its affiliates. All rights reserved. Page 23
AWS Basics: Creating EC2 Instances (with Linux)
Windows
Download PuTTY
1. Download PuTTY to a location of your choice unless you already have PuTTY.
http://the.earth.li/~sgtatham/putty/latest/x86/putty.exe
4. Save the file to your Downloads directory (or some other directory of your choice.)
4. Select the Auth category by clicking on it (not the + symbol next to it).
© 2013 Amazon Web Services, Inc. or its affiliates. All rights reserved. Page 24
AWS Basics: Creating EC2 Instances (with Linux)
5. Click Browse and locate the PPK file (ending in .ppk) in your Downloads directory or whatever other
location you chose.
6. Click Open
Click Yes when prompted to allow a first connection to this remote SSH server.
© 2013 Amazon Web Services, Inc. or its affiliates. All rights reserved. Page 25
AWS Basics: Creating EC2 Instances (with Linux)
OS X and Linux
Download your EC2 Key Pair private key file
1. Go back to your lab in qwikLAB™.
2. Download the qwikLAB™ provided EC2 Key Pair private key file in the PEM format by clicking on the
Download PEM option in the “Download PEM/PPK” drop-down.
3. Save the file to your Downloads directory (or some other directory of your choice.)
chmod 600 ~/Downloads/qwiklab‐l33‐5018.pem
ssh –i ~/Downloads/qwiklab‐l33‐5018.pem ec2‐user@ec2‐23‐22‐87‐238.compute‐1.amazonaws.com
© 2013 Amazon Web Services, Inc. or its affiliates. All rights reserved. Page 26