| « PreviousNext » | |
![]() ![]() ![]() | Did this page help you? Yes | No | Tell us about it... |
This topic describes how to launch and run an instance from an AMI.
Important
After launching an instance, you are billed hourly for running time. When you are finished with an instance, be sure to terminate it. For more information, see Terminating Instances.
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.
You can either leverage the Free Usage Tier to launch and use a free Amazon EC2 Micro instance for 12 months, or you can launch a larger instance type, but not within the Free Usage Tier. For more information, see the AWS Free Usage Tier product page and Getting Started with AWS Free Usage Tier.
If you launch an instance that is not within the Free Usage Tier, you incur the standard Amazon EC2 usage fees for the instance. For more information about Amazon EC2 usage rates, see the Amazon EC2 product page.
Important
If you launch an instance that is not within the Free Usage Tier, you are billed after you launch the instance and charged for the time that the instance is running, even if it remains idle.
To launch an instance
Sign in to the AWS Management Console and open the Amazon EC2 console at https://console.aws.amazon.com/ec2/.
From the navigation bar, select the region for the instance. This choice is important because some Amazon EC2 resources can be shared between regions, while others can't. Select the region that meets your needs. For more information, see Resource Locations.

From the Amazon EC2 console dashboard, click Launch Instance.
The Create a New Instance page provides the following ways to launch an instance:
The Classic Wizard provides more granular control and advanced settings for configuring your instance.
The Quick Launch Wizard simplifies the process for you by automatically configuring many selections to get you started quickly with your instance. We recommend this wizard if you are just trying out Amazon EC2. For more information, see Getting Started with Amazon EC2 Linux Instances.
The AWS Marketplace is an online store where you can buy software that runs on AWS. You can launch your instance with just one click.
For this procedure, use the Classic Wizard. Click Classic Wizard, and then click Continue.
On the CHOOSE AN AMI page, the Quick Start tab displays a list of basic configurations called Amazon Machine Images (AMIs). An AMI contains all the information needed to create a new instance. For example, an AMI might contain the software required to act as a web server (for example, Linux, Apache, and your website). To keep things simple, AWS marks the AMIs that are available in the Free Usage Tier with a star.
As you are selecting an AMI, it's important to note whether the AMI is backed by an instance store or by Amazon EBS. Select the type of AMI that meets your needs. For more information, see Storage for the Root Device.
Choose the AMI to use and click Select.
On the INSTANCE DETAILS page, change the following settings as necessary, and then click Continue.
Number of Instances: Select the number of instances based on the selected AMI to launch.
Instance Type: Select the size of the
instance to launch. Larger instance types have more CPU and memory.
To stay within the Free Usage Tier, choose Micro
(t1.micro).
Launch as an EBS-Optimized Instance: If the instance type supports this feature, select this check box to enable it. (Otherwise, this option is grayed out.) Additional charges apply. For more information, see EBS-Optimized Instances.
Availability Zone: Select the Availability
Zone to use. We recommend that you choose No
Preference.
On the second INSTANCE DETAILS page, change the following advanced instance options as necessary, and then click Continue.
Kernel ID: Select Use Default unless you want to use a specific kernel. For more information, see Kernels and RAM Disk FAQ.
RAM Disk ID: Select Use Default unless you want to use a specific RAM disk. For more information, see Kernels and RAM Disk FAQ.
Monitoring: Select this check box to enable detailed monitoring of your instance using Amazon CloudWatch. Additional charges apply. For more information, see Introduction to Amazon CloudWatch in the Amazon CloudWatch Developers Guide.
User Data: You can specify user data to configure an instance during launch or to run a configuration script.
base64 encoded: Select this check box if you want data to be base64 encoded.
Termination Protection: Select this check box to prevent against accidental termination. For more information, see Enabling Termination Protection for an Instance.
Shutdown Behavior: Select whether the instance should stop or terminate when shut down.
IAM Role: Select an AWS Identity and Access Management (IAM) role to associate with the instance. For more information, see IAM Roles for Amazon EC2.
On the third INSTANCE DETAILS page, you can click Edit to specify volumes to attach to the instance besides the volumes specified by the AMI (such as the root device volume), and then click Continue. For this example, it's fine to stick with the default root volume. For more information about changing the block device mapping, see Updating the Block Device Mapping when Launching an Instance.
On the final INSTANCE DETAILS page, specify tags for the instance, and then click Continue. For more information about tags, see Tagging Your Amazon EC2 Resources.
On the CREATE KEY PAIR page, you can choose from any
existing key pairs that you have created in the current region, or create a
new one. For this example, click Choose from your existing Key
Pairs.and select gsg-keypair from the list of
existing key pairs. For more information about creating key pairs, see Getting a Key Pair.
Important
Do not select the Proceed without a Key Pair option. If you launch an instance without a key pair, you can't connect to it. This option is used only when you are creating your own AMI and don't need to connect to the instance.
On the CONFIGURE FIREWALL page, the wizard automatically selects a security group 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. If you use an AMI on the Quick Start tab, the name and description for the group is quick-start-x where x is a number associated with your quick-start group. The first security group you create using the Quick Start tab is named quick-start-1. You can change the name and description. For an Amazon Linux instance, you connect through SSH on port 22. The quick-start-x security group automatically allows SSH traffic on port 22. For a Windows instance, you connect through Remote Desktop Protocol (RDP) and the security group automatically allows RDP traffic on port 3389.
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 quick-start-x security group enables all IP addresses to access your instance over the specified ports (that is, SSH for Linux/UNIX or RDP for Windows). This is acceptable for the short exercise in this tutorial, but it's unsafe for production environments. In production, you authorize only a specific IP address or range of addresses to access your instance.
Note
After an instance is running, you can't change which security groups it belongs to, but you can add and remove rules.
Click Continue to review your settings. When you're satisfied with your selections, click Launch to begin launching your instance.
To launch an instance
Use the ec2-run-instances command.
PROMPT>ec2-run-instances ami-1a2b3c4d -k gsg-keypair
Amazon EC2 returns output similar to the following example.
RESERVATION r-1a2b3c4d 111122223333 default INSTANCE i-1a2b3c4d ami-1a2b3c4d pending gsg-keypair 0 m1.small YYYY-MM-DDTHH:MM:SS+0000 us-east-1a aki-1a2b3c4d monitoring-disabled ebs paravirtual xen sg-1a2b3c4d default false
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.
Use the ec2-describe-instances command to display the launch status of the instance.
PROMPT>ec2-describe-instancesRESERVATION r-1a2b3c4d 111122223333 default INSTANCE i-1a2b3c4d ami-1a2b3c4d ec2-67-202-51-223.compute-1.amazonaws.com ip-10-251-50-35.ec2.internal running gsg-keypair 0 m1.small YYYY-MM-DDTHH:MM:SS+0000 us-east-1a aki-1a2b3c4d monitoring-disabled 184.73.10.99 10.254.170.223 ebs paravirtual xen ABCDE1234567890123 sg-1a2b3c4d default false BLOCKDEVICE /dev/sda1 vol-1a2b3c4d YYYY-MM-DDTHH:MM:SS.SSSZ truei-1a2b3c4d
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; that is, the one that can be used to contact the instance from the Internet. The second DNS name is your instance's local DNS name, and can only be used to contact your instance 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.
To launch an instance
Use the RunInstances action. Construct the following request, where
ami_id represents the
latest version of an AMI.
https://ec2.amazonaws.com/ ?Action=RunInstances &ImageId=ami-1a2b3c4d &MaxCount=1 &MinCount=1 &KeyName=gsg-keypair &Placement.AvailabilityZone=us-east-1a &AUTHPARAMS
The following is an example response.
<RunInstancesResponse xmlns="http://ec2.amazonaws.com/doc/2013-02-01/">
<reservationId>r-1a2b3c4d</reservationId>
<ownerId>111122223333</ownerId>
<groupSet>
<item>
<groupId>default</groupId>
</item>
</groupSet>
<instancesSet>
<item>
<instanceId>i-1a2b3c4d</instanceId>
<imageId>ami-1a2b3c4d</imageId>
<instanceState>
<code>0</code>
<name>pending</name>
</instanceState>
<privateDnsName/>
<dnsName/>
<reason/>
<amiLaunchIndex>0</amiLaunchIndex>
<instanceType>m1.small</instanceType>
<launchTime>YYYY-MM-DDTHH:MM:SS.SSSZ</launchTime>
<placement>
<availabilityZone>us-east-1a</availabilityZone>
<groupName/>
<tenancy>default</tenancy>
</placement>
<monitoring>
<state>disabled</state>
</monitoring>
<rootDeviceType>ebs</rootDeviceType>
</item>
</instancesSet>
</RunInstancesResponse>Look for the instance ID in the instanceId element in the
response 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.
Use the DescribeInstances action to display the launch status of the instance.
Construct the following request.
https://ec2.amazonaws.com/ ?Action=DescribeInstances &InstanceId=i-1a2b3c4d &AUTHPARAMS
The following is an example response. In this response,
ami_id represents the
latest version of an AMI.
<DescribeInstancesResponse xmlns="http://ec2.amazonaws.com/doc/2013-02-01/">
<reservationId>r-1a2b3c4d</reservationId>
<ownerId>111122223333</ownerId>
<groupSet>
<item>
<groupId>default</groupId>
</item>
</groupSet>
<instancesSet>
<item>
<instanceId>i-1a2b3c4d</instanceId>
<imageId>ami-1a2b3c4d</imageId>
<instanceState>
<code>16</code>
<name>running</name>
</instanceState>
<privateDnsName>ip-10-251-50-35.ec2.internal</privateDnsName>
<dnsName>ec2-67-202-51-223.compute-1.amazonaws.com</dnsName>
<keyName>gsg-keypair</keyName>
<amiLaunchIndex>0</amiLaunchIndex>
<instanceType>m1.small</instanceType>
<launchTime>YYYY-MM-DDTHH:MM:SS.SSSZ</launchTime>
<placement>
<availabilityZone>us-east-1a</availabilityZone>
<groupName/>
<tenancy>default</tenancy>
</placement>
<monitoring>
<state>disabled</state>
</monitoring>
</item>
</instancesSet>
</DescribeInstancesResponse>When the instance state is running, as it is in the previous
response, the instance has started booting.