Amazon Elastic Compute Cloud
User Guide (API Version 2011-12-15)
Print this pageEmail this pageGo to the ForumsView the PDFShare this page on TwitterShare this page on FacebookBookmark this page on DeliciousSubmit this page to RedditSubmit this page to DiggDid this page help you?  Yes  No   Tell us about it...

Running an Instance

This section describes how to run an instance.

AWS Management Console

To launch an instance

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

  2. Click Instances in the Navigation pane.

    The console displays a list of running instances.

  3. Click Launch Instance.

    The wizard opens a Create a new instance page.

  4. If you are launching a Linux/UNIX instance, locate the Basic 32-bit Amazon Linux AMI and click its Select button. If you are launching a Windows instance, locate a Windows AMI and click its Select button.

    [Note]Note

    We recommend launching basic AMIs for this tutorial, but you can launch any AMI.

  5. Confirm the following settings and click Continue.

    • The Number of Instances is set to 1.

    • The Availability Zone is set to No Preference.

    • The Instance Type is set to Small (m1.small).

    • The button for Launch Instances is selected.

    The second Instance Details page is displayed with advanced instance options.

  6. Click Continue to accept the default settings for the advanced options.

    The third Instance Details page displays. Here you can specify tags for the instance (for more information, see Using Tags ).

  7. Click Continue to accept the default tag settings.

    The Create Key Pair page is displayed.

  8. Select Choose from your existing Key Pairs, and then select a key pair you've created (see Getting an SSH Key Pair).

    The Configure Firewall page is displayed.

  9. Select Choose one or more of your existing Security Groups, and select default, because you've already configured the default security group (see Adding Rules to the Default Security Group).

    [Note]Note

    After an instance is running, you can't change which security groups it belongs to.

  10. Click Continue, and then Launch to begin launching your instance.

Command Line Tools

To launch an instance

  1. Use the ec2-run-instances command.

    PROMPT>  ec2-run-instances ami-3ac33653 -k gsg-keypair

    Amazon EC2 returns output similar to the following example.

    RESERVATION     r-f25e6f9a      111122223333    default
    INSTANCE        i-85b435ee      ami-3ac33653            pending     gsg-keypair     0 m1.small 2010-03-30T08:01:36+0000        us-east-1a      aki-407d9529          monitoring-disabled           ebs
  2. Look for the instance ID in the second field and write it down.

    You use it to manipulate this instance (including terminating it when you are finished).

    It takes a few minutes for the instance to launch.

  3. The following command displays the launch status of the instance.

    PROMPT>  ec2-describe-instances i-85b435ee 
    RESERVATION	r-f25e6f9a	111122223333  	default
    INSTANCE	i-85b435ee	ami-3ac33653	ec2-67-202-28-13.compute-1.amazonaws.com	domU-12-31-39-00-78-93.compute-1.internal	running	gsg-keypair	0	m1.small	2010-03-30T08:01:36+0000	us-east-1a	aki-407d9529	monitoring-disabled	67.202.28.13	10.254.127.97	ebs
    BLOCKDEVICE	/dev/sda1	vol-02a2a46b	2010-03-30T08:01:44.000Z
[Important]Important

After launching an instance, you are billed hourly for running time. When you are finished, make sure to terminate any instances that you started.

When the instance state in the field just before the key pair name reads "running", the instance has started booting. There might be a short time before it is accessible over the network, however. The first DNS name is your instance's external DNS name, i.e. the one that can be used to contact it from the Internet. The second DNS name is your instance's local DNS name, and is only contactable by other instances within the Amazon EC2 network. The DNS names of your instances are different than those shown in the preceding example and you should use yours instead. The examples in this guide use the public DNS name.

If the instance's state immediately goes to "terminated" instead of "running", you can get information about why the instance didn't launch. For more information, see What to Do If an Instance Immediately Terminates.

API

To launch an instance

  • Construct the following Query request.

    https://ec2.amazonaws.com/
    ?Action=RunInstances
    &ImageId=ami-3ac33653
    &MaxCount=1
    &MinCount=1
    &KeyName=gsg-keypair
    &Placement.AvailabilityZone=us-east-1a
    &...auth parameters...
    

    Following is an example response.

    <RunInstancesResponse xmlns="http://ec2.amazonaws.com/doc/2011-12-15/">
      <reservationId>r-47a5402e</reservationId>
      <ownerId>111122223333</ownerId>
      <groupSet>
        <item>
          <groupId>default</groupId>
        </item>
      </groupSet>
      <instancesSet>
        <item>
          <instanceId>i-2ba64342</instanceId>
          <imageId>ami-3ac33653</imageId>
          <instanceState>
            <code>0</code>
            <name>pending</name>
          </instanceState>
          <privateDnsName></privateDnsName>
          <dnsName></dnsName>
          <keyName>gsg-keypair</keyName>
          <amiLaunchIndex>0</amiLaunchIndex>
          <instanceType>m1.small</instanceType>
          <launchTime>2007-08-07T11:51:50.000Z</launchTime>
          <placement>
            <availabilityZone>us-east-1a</availabilityZone>
          </placement>
          <monitoring>
            <enabled>false</enabled>
          </monitoring>
        </item>
      </instancesSet>
    </RunInstancesResponse>

To view the status of a launched instance

  • Construct the following Query request.

    https://ec2.amazonaws.com/
    ?Action=DescribeInstances
    &InstanceId=i-2ba64342
    &...auth parameters...
    

    Following is an example response

    <DescribeInstancesResponse xmlns="http://ec2.amazonaws.com/doc/2011-12-15/">
      <reservationId>r-47a5402e</reservationId>
      <ownerId>111122223333</ownerId>
      <groupSet>
        <item>
          <groupId>default</groupId>
        </item>
      </groupSet>
      <instancesSet>
        <item>
          <instanceId>i-2ba64342</instanceId>
          <imageId>ami-3ac33653</imageId>
          <instanceState>
            <code>16</code>
            <name>running</name>
          </instanceState>
          <privateDnsName></privateDnsName>
          <dnsName></dnsName>
          <keyName>gsg-keypair</keyName>
          <amiLaunchIndex>0</amiLaunchIndex>
          <instanceType>m1.small</instanceType>
          <launchTime>2007-08-07T11:51:50.000Z</launchTime>
          <placement>
            <availabilityZone>us-east-1a</availabilityZone>
          </placement>
          <monitoring>
            <enabled>false</enabled>
          </monitoring>
        </item>
      </instancesSet>
    </DescribeInstancesResponse>

If the instance's state immediately goes to "terminated" instead of "running", you can get information about why the instance didn't launch. For more information, see What to Do If an Instance Immediately Terminates.