Amazon Elastic Compute Cloud
User Guide (API Version 2013-02-01)
« PreviousNext »
View the PDF for this guide.Go to the AWS Discussion Forum for this product.Go to the Kindle Store to download this guide in Kindle format.Did this page help you?  Yes | No |  Tell us about it...

Getting Started with Amazon EC2 Linux Instances

To get started using Amazon Elastic Compute Cloud (Amazon EC2) Linux instances, complete the steps shown in the following table. You'll primarily use the AWS Management Console, a point-and-click web-based interface. You can also watch this short video to get started: How to Create a Red Hat Enterprise Linux EC2 Instance.

Tip

This tutorial has you launch and connect to an Amazon EC2 Linux instance. If you'd prefer to launch and connect to an Amazon EC2 Windows instance, see this tutorial: Getting Started with Amazon EC2 Windows Instances.

For more information about Amazon EC2, see the Amazon EC2 product page.

To get started with Amazon EC2

StepDescription

Step 1: Sign Up for Amazon EC2

Create an AWS account, if you haven't done so already.

Step 2: Launch an Amazon EC2 Instance

Launch an Amazon Linux instance, which is a virtual server in the cloud.

Step 3: Connect to Your Instance

Connect to your instance.

Step 4: Explore Your Instance

Create an Amazon EC2 volume, attach it to your instance, and use Linux commands on your instance to make the volume available for use.

Step 5: Clean Up

Terminate your instance and delete the volume that you created.


Step 1: Sign Up for Amazon EC2

When you create an Amazon Web Services (AWS) account, AWS automatically signs up the account for all AWS services, including Amazon EC2.

With Amazon EC2, you pay only for what you use. New AWS customers can get started with Amazon EC2 for free. For more information, see Amazon EC2 Pricing.

If you have an AWS account already, skip to the next step. If you don't have an AWS account, use the following procedure to create one.

To create an AWS account

  1. Go to http://aws.amazon.com and click Sign Up Now.

  2. Follow the on-screen instructions.

    Part of the sign-up process involves receiving a phone call and entering a PIN using the phone keypad.

Step 2: Launch an Amazon EC2 Instance

Now that you're signed up for AWS, you're ready to start "computing" in the cloud. The first thing you'll do is to launch a Linux instance using the AWS Management Console. An instance is a virtual server in the cloud. You can use Amazon EC2 to set up and configure the operating system and applications that run on your instance.

You can choose to launch one of the following instances:

  • An instance within the Free Usage Tier. The Free Usage Tier enables you to launch and use an Amazon EC2 micro instance free for 12 months. For more information about the Free Usage Tier, see the AWS Free Usage Tier product page and Getting Started with AWS Free Usage Tier.

  • A regular instance (not within the Free Usage Tier). During this tutorial you'll incur the standard Amazon EC2 usage fees for the instance, until we show you how to terminate it in the last step. The total charges to complete this tutorial are minimal (typically less than a few dollars). For more information about Amazon EC2 usage fees, see Amazon EC2 Pricing.

To launch an instance

  1. Sign in to the AWS Management Console and open the Amazon EC2 console at https://console.aws.amazon.com/ec2/.

    Use the email address and password that you specified when signing up for AWS.

  2. From the navigation bar, select the region for the instance. For this tutorial, you can use the default region. Otherwise, this choice is important because some EC2 resources can be shared between regions, while others can't. For example, if you'd like to connect your instance to an existing EBS volume, you must launch the instance in the same region as the volume.

    Select a region
  3. From the Amazon EC2 console dashboard, click Launch Instance.

    The Create a New Instance page includes these ways to launch an instance:

    • The Classic Wizard offers you precise control and advanced settings for configuring your instance.

    • The Quick Launch Wizard automatically configures many selections for you, so that you can get started quickly. This tutorial guides you through the Quick Launch Wizard.

  4. On the Create a New Instance page, click Quick Launch Wizard.

  5. (Optional) In Name Your Instance, enter a name for the instance that has meaning for you. (If you run multiple instances, naming them helps you identify them in the console.)

  6. In Choose a Key Pair, you can choose from any existing key pairs that you've created, or you can create a new key pair.

    A key pair enables you to connect to a Linux instance through SSH. Therefore, don't select the None option. If you launch your instance without a key pair, then you can't connect to it.

    For this example, we’ll create a key pair:

    1. Click Create New.

    2. Type a name for your key pair and then click Download.

    3. Save your private key in a safe place on your computer. Note the location because you'll need the key to connect to your instance.

  7. In Choose a Launch Configuration, the Quick Launch Wizard displays a list of basic configurations called Amazon Machine Images (AMIs) that you can choose from to launch your instance. An AMI contains everything you need to create a new instance of a server, such as a web server or a database server. In this tutorial, we’ll launch an Amazon Linux instance with a 64-bit operating system. If the configuration is marked with a star, this indicates that it's within the Free Usage Tier.

    Important

    If you launch a regular instance, you're billed from the time that you launch the instance until the instance is stopped or terminated, even if it remains idle.

    Launch instance start
  8. Click Continue to view and customize the settings for your instance.

  9. In Security Details, Security Group, you see the security group that the wizard selects for you.

    A security group defines firewall rules for your instances. These rules specify which incoming network traffic is delivered to your instance. All other traffic is ignored.

    If you're new to Amazon EC2 and haven't set up any security groups yet, AWS defines a default security group for you. The name and description for the group is quicklaunch-x where x is a number associated with your quicklaunch group. The first security group you create using the Quick Launch Wizard is named quicklaunch-1. You can change the name and description using the Edit details button. The group already has basic firewall rules that enable you to connect to the type of instance you choose. For a Linux instance, you connect through SSH on port 22. The quicklaunch-x security group automatically allows SSH traffic on port 22.

    If you have used Amazon EC2 before, the wizard looks for an existing security group for the type of instance you’re creating.

    Caution

    The quicklaunch-x security group authorizes all IP addresses to access your instance over the specified ports (for example, SSH). This is acceptable for the short exercise in this tutorial, but it's unsafe for production environments. In production, you'll authorize only a specific IP address or range of IP addresses to access your instance.

    Launch Windows Instance
  10. Review your settings, and click Launch to launch the instance.

  11. A confirmation page lets you know that your instance is launching. Click Close to close the confirmation page and return to the Amazon EC2 console.

  12. Click Instances in the navigation pane to view the status of your instance. It takes a short time for an instance to launch. The instance's status is pending while it's launching.

    Instance pending

    After the instance is launched, its status changes to running.

    Instance running
  13. (Optional) After your instance is launched, you can view the quicklaunch-x security group rules.

    1. On the Amazon EC2 console, in Network and Security, click Security Groups.

    2. Click the quicklaunch-1 security group to view the security rules created by the Quick Launch Wizard.

    Security group with SSH rule

    The security group contains a rule that authorizes SSH traffic from any IP address source to port 22. If you launch a Linux instance running Apache and MySQL, the Quick Launch Wizard creates a security group that authorizes traffic to port 80 for HTTP (for web traffic) and port 3306 (for MySQL).

Step 3: Connect to Your Instance

There are several ways to connect to a Linux instance. In this step, we show you how to connect to your instance using your browser. Alternatively, there are tools you can use to connect to your instance instead of connecting using your browser. For more information, see the following topics: Connect to Linux/UNIX Instances from Linux/UNIX with SSH and Connecting to Linux/UNIX Instances from Windows Using PuTTY.

To connect to your instance through a web browser

  1. You must have Java installed and enabled in the browser. If you don't have Java already, you can contact your system administrator to get it installed, or follow the steps outlined in these pages:

  2. Sign in to the AWS Management Console and open the Amazon EC2 console at https://console.aws.amazon.com/ec2/.

  3. Click Instances in the navigation pane.

  4. Right-click your instance, and then click Connect.

  5. Click Connect from your browser using the Java SSH client (Java Required). AWS automatically detects the public DNS address of your instance and the key pair name you launched the instance with.

  6. In User name, enter the user name to log in to your instance.

    Note

    For an Amazon Linux instance, the default user name is ec2-user. For Ubuntu, the default user name is ubuntu. Some AMIs allow you to log in as root. So in this example, you may need to change the user name from ec2-user to the appropriate user name.

  7. The Key name field is automatically populated for you.

  8. In Private key path, enter the fully qualified path to your .pem private key file.

  9. Click Save key location, and then click Stored in browser cache to store the key location in your browser cache. This ensures that the key location will be detected in subsequent browser sessions, until your clear your browser’s cache.

  10. Click Launch SSH Client.

  11. When prompted to add the host to your set of known hosts, click No.

  12. If necessary, click Yes to trust the certificate.

  13. Click Run to run the MindTerm client.

  14. If you accept the license agreement, click Accept.

  15. If this is your first time running MindTerm, a series of dialog boxes ask you to confirm setup for your home directory and other settings.

  16. Confirm settings for MindTerm setup. A screen opens and you are connected to your instance.

Congratulations! You've successfully launched and connected to a Linux instance. If you'd like to explore the instance, continue to the next step. Otherwise, skip to Step 5: Clean Up to terminate the instance so that you don't continue to incur charges.

Step 4: Explore Your Instance

Now that you've connected to your instance, you can use it in the way that you'd use a Linux computer sitting in front of you.

Let's take a look at the default storage for the instance. In MindTerm, run the following command to view the mounted volumes.

$ df -h

For a micro instance, your output should look something like this.

Filesystem             Size   Used  Avail Use% Mounted on
/dev/xvda1             8.0G   1.1G   6.9G  14% /
tmpfs                  298M      0   298M   0% /dev/shm

The /dev/xvda1 volume is the root device volume. It contains the image used to boot the instance.

Notice that there's room to install additional software on your instance. For example, you can use yum to download and install packages on your instance.

If you need additional storage for data, a simple solution is to add Amazon Elastic Block Store (Amazon EBS) volumes to your Amazon EC2 instance. An Amazon EBS volume serves as network-attached storage for your instance. Let's add a volume to the instance that you've launched. First we'll use the EC2 console to create an Amazon EBS volume and attach it to the instance, and then we'll connect to the instance and mount the volume.

To create and attach an Amazon EBS volume

  1. Open the Amazon EC2 console at https://console.aws.amazon.com/ec2/.

  2. Select the region in which you created your instance in the navigation bar, and then click Instances in the navigation pane.

    The console displays the list of current instances in that region. Select your Linux instance. In the Description tab in the bottom pane note the Zone for the instance.

  3. In the navigation pane, in Elastic Block Store, click Volumes.

    The console displays a list of current EBS volumes in that region. (You should see the EBS volume that serves as the root device volume for your instance.)

  4. Click Create Volume.

  5. In the Create Volume dialog box, configure the following settings:

    • Leave the volume size blank. (We'll let the snapshot we select determine the size of the volume.)

    • Select the same Availability Zone that you used when you created your instance. Otherwise, you can't attach the volume to your instance.

    • Select a snapshot that contains a public data set hosted by AWS. This enables us to quickly and easily create a volume that is formatted and contains data. The Free Usage Tier provides up to 30 GB of Amazon Elastic Block Storage; therefore, select a public data set that is smaller than 30 GB. We will use snap-2767d046 -- This is a 10,000 song..., which contains the Million Song Sample Dataset. This data set is 5 GB in size. The snapshot list can contain a lot of snapshots. To quickly and easily find the Million Song Sample Dataset snapshot, select the Snapshot dropdown list and start typing the snapshot ID snap-2767d046 until the proper snapshot is found.

    • Select the Standard volume type. This creates a standard EBS volume.

    Now click Yes, Create. This creates a new volume (its state is available, and its snapshot is snap-2767d046).

  6. Right-click the newly created volume and select Attach Volume.

  7. In the Attach Volume dialog box, click the following settings:

    • Select your Linux instance from the list.

    • Specify the device name /dev/sdf.

Now click Yes, Attach.You'll notice in the Details pane for your volume that the volume state is in-use and that it is attached to your instance with the device name /dev/sdf. However, if you return to MindTerm and run the df -h command again, you won't see the volume yet. That's because we need to mount the volume to make it available. To mount a volume based on a snapshot, run the following commands.

$ sudo mkdir /mnt/song-data
$ sudo mount /dev/sdf /mnt/song-data

Note

If you didn't specify a snapshot when you created the volume, the new volume is an empty volume. Before you can mount an empty volume that you create, you must format it using the sudo mkfs command. For more information, see Making an Amazon EBS Volume Available for Use.

Now when you run the df -h command, you'll see output like the following.

Filesystem             Size   Used  Avail Use% Mounted on
/dev/xvda1             8.6G   1.2G   7.4G  14% /
tmpfs                  313M      0   313M   0% /dev/shm
/dev/xvdf              5.0G   4.3G   442M  91% /mnt/song-data

To view the contents of the new volume, run the following command.

$ dir  /mnt/song-data

The output shows the following directory structure.

AdditionalFiles  data  LICENSE  lost+found  README

At this point, you should have a basic understanding of instances and how you work with them.

When you're finished with your instance, don't forget to clean up any resources you've used and terminate the instance, as shown in the next step.

Step 5: Clean Up

Now that you’ve completed this tutorial, you can customize the instance to meet your needs and keep using it.

Important

Remember, if you launched an instance in the Free Usage Tier, there are no charges. However, if you launched a regular instance, as soon as your instance starts to boot, you're billed for each hour or partial hour that you keep the instance running, even if the instance is idle. You'll stop incurring charges for a regular instance as soon as the instance status changes to shutting down or terminated. For more information, see Amazon EC2 Pricing.

Terminating an instance effectively deletes it because you can't reconnect to the instance after you've terminated it. This differs from stopping the instance; when you stop an instance, it is shut down and you are not billed for hourly usage or data transfer (but you are billed for any Amazon EBS volume storage). Also, you can restart a stopped instance at any time with a start request. Each time you transition an instance from stopped to started, we charge a full instance hour, even if these transitions happen multiple times within a single hour. For more information about the differences between stopping and terminating an instance, see Stopping Instances.

To terminate the instance

  1. Sign in to the AWS Management Console and open the Amazon EC2 console at https://console.aws.amazon.com/ec2/.

  2. Locate your instance in the list of instances on the Instances page.

  3. Right-click the instance, and then click Terminate.

  4. Click Yes, Terminate when prompted for confirmation.

    Amazon EC2 begins terminating the instance.

Amazon EBS volumes can persist even after your instance goes away. If you created and attached an EBS volume in the previous step, it was detached when you terminated the instance. However, you must delete the volume, or you'll be charged for volume storage if the storage amount exceeds the limit of the Free Usage Tier. After you delete a volume, its data is gone and the volume can't be attached to any instance.

To delete the volume

  1. Sign in to the AWS Management Console and open the Amazon EC2 console at https://console.aws.amazon.com/ec2/.

  2. Locate the volume that you created in the list of volumes on the Volumes page.

  3. Right-click the volume, and then click Delete.

  4. Click Yes, Delete when prompted for confirmation.

    Amazon EC2 begins deleting the volume.

Finding Additional Tutorials

This tutorial is focused on learning to use Amazon EC2. For tutorials that show you how to use additional AWS products and services with Amazon EC2, see Getting Started with AWS Documentation.