Amazon User Guide
Amazon User Guide
User Guide
API Version 2014-02-01
Amazon Web Services
Amazon Elastic Compute Cloud User Guide
Amazon Elastic Compute Cloud: User Guide
Amazon Web Services
Copyright 2014 Amazon Web Services, Inc. and/or its affiliates. All rights reserved.
The following are trademarks of Amazon Web Services, Inc.: Amazon, Amazon Web Services Design, AWS, Amazon CloudFront,
Cloudfront, Amazon DevPay, DynamoDB, ElastiCache, Amazon EC2, Amazon Elastic Compute Cloud, Amazon Glacier, Kindle, Kindle
Fire, AWS Marketplace Design, Mechanical Turk, Amazon Redshift, Amazon Route 53, Amazon S3, Amazon VPC. In addition,
Amazon.com graphics, logos, page headers, button icons, scripts, and service names are trademarks, or trade dress of Amazon in
the U.S. and/or other countries. Amazon's trademarks and trade dress may not be used in connection with any product or service that
is not Amazon's, in any manner that is likely to cause confusion among customers, or in any manner that disparages or discredits
Amazon.
All other trademarks not owned by Amazon are the property of their respective owners, who may or may not be affiliated with, connected
to, or sponsored by Amazon.
Amazon Elastic Compute Cloud User Guide
What Is Amazon EC2? ........................................................................................................................... 1
Instances and AMIs ................................................................................................................................ 4
Regions and Availability Zones ............................................................................................................... 7
Root Device Volume ............................................................................................................................. 13
Setting Up ............................................................................................................................................. 19
Getting Started ..................................................................................................................................... 24
Step 1: Launch an Instance .................................................................................................................. 25
Step 2: Connect to Your Instance .......................................................................................................... 26
Step 3: Add a Volume ........................................................................................................................... 29
Step 4: Clean Up .................................................................................................................................. 32
Best Practices ....................................................................................................................................... 33
Tutorial: Installing a LAMP Web Server ................................................................................................. 34
Tutorial: Hosting a WordPress Blog ...................................................................................................... 40
Amazon Machine Images ..................................................................................................................... 48
AMI Types ............................................................................................................................................. 50
Finding a Suitable AMI .......................................................................................................................... 53
Shared AMIs ......................................................................................................................................... 54
Finding Shared AMIs ................................................................................................................... 54
Making an AMI Public .................................................................................................................. 57
Sharing an AMI with Specific AWS Accounts .............................................................................. 59
Using Bookmarks ........................................................................................................................ 60
Guidelines for Shared Linux AMIs ............................................................................................... 61
Paid AMIs ............................................................................................................................................. 64
Creating an Amazon EBS-Backed Linux AMI ....................................................................................... 69
Creating an Instance Store-Backed Linux AMI ..................................................................................... 72
Copying an AMI .................................................................................................................................... 80
Deregistering Your AMI ......................................................................................................................... 83
Amazon Linux ....................................................................................................................................... 84
Using Your Own Linux Kernels .............................................................................................................. 91
Instances .............................................................................................................................................. 97
Instance Types ...................................................................................................................................... 97
Micro Instances ........................................................................................................................... 99
I2 Instances ............................................................................................................................... 106
HI1 Instances ............................................................................................................................ 107
HS1 Instances ........................................................................................................................... 109
R3 Instances ............................................................................................................................. 110
GPU Instances .......................................................................................................................... 112
Amazon EBS-Optimized Instances ........................................................................................... 114
Placement Groups ..................................................................................................................... 115
Resizing Instances .................................................................................................................... 118
Spot Instances .................................................................................................................................... 121
Getting Started with Spot Instances .......................................................................................... 122
Viewing Spot Instance Pricing History ............................................................................. 125
Creating a Spot Instance Request ................................................................................... 127
Finding Running Spot Instances ...................................................................................... 130
Canceling Spot Instance Requests .................................................................................. 132
Fundamentals of Spot Instances ............................................................................................... 134
Placing Spot Requests ..................................................................................................... 135
Spot Instance Limits ............................................................................................... 135
Customizing Your Spot Requests ........................................................................... 136
Tracking Spot Requests with Bid Status Codes ...................................................... 138
Tagging Spot Instance Requests ..................................................................................... 144
Understanding Spot Instance Provisioning, Pricing, and Interruption .............................. 145
Protecting Your Spot Instance Data Against Interruptions ............................................... 147
Planning for Interruptions ....................................................................................... 148
Persisting Your Root EBS Partition ......................................................................... 148
Walkthroughs: Using Spot Instances with AWS Services ......................................................... 149
Managing Spot Instances with Auto Scaling .................................................................... 149
API Version 2014-02-01
4
Amazon Elastic Compute Cloud User Guide
Tools for Managing Auto Scaling with Spot Instances ............................................ 150
Launching Spot Instances with Auto Scaling .......................................................... 151
Obtaining Information About the Instances Launched by Auto Scaling .................. 154
Updating the Bid Price for the Spot Instances ........................................................ 158
Scheduling Spot Bid Requests ............................................................................... 161
Using Auto Scaling to Get Notifications for Spot Instances .................................... 161
Using CloudFormation Templates to Launch Spot Instances .......................................... 164
Launching Amazon Elastic MapReduce Job Flows with Spot Instances ......................... 165
Launching Spot Instances in Amazon Virtual Private Cloud ............................................ 165
Advanced Tasks ........................................................................................................................ 168
Subscribe to Your Spot Instance Data Feed .................................................................... 168
Programming Spot Instances the with AWS Java SDK ................................................... 171
Tutorial: Amazon EC2 Spot Instances .................................................................... 172
Tutorial: Advanced Amazon EC2 Spot Request Management ............................... 180
Starting Clusters on Spot Instances ................................................................................ 196
Reserved Instances ............................................................................................................................ 198
Getting Started with Reserved Instances .................................................................................. 199
Tools for Working with Reserved Instances ..................................................................... 202
Reserved Instance Fundamentals ............................................................................................. 204
Choosing Reserved Instances Based on Your Usage Plans ............................................ 204
Understanding Reserved Instance Pricing Tiers .............................................................. 205
Understanding the Pricing Benefit of Reserved Instances .............................................. 210
Reserved Instances and Consolidated Billing ........................................................ 212
Reserved Instance Marketplace ...................................................................................... 212
Buying Reserved Instances ....................................................................................................... 215
Becoming a Buyer ............................................................................................................ 216
Purchasing Reserved Instances ...................................................................................... 217
Reading Your Statement (Invoice) .................................................................................... 223
Obtaining Information About Your Reserved Instances ............................................................. 225
Modifying Your Reserved Instances .......................................................................................... 230
Changing the Instance Type of Your Reservations ........................................................... 233
Submitting Modification Requests .................................................................................... 236
Selling in the Reserved Instance Marketplace .......................................................................... 240
Registering as a Seller ..................................................................................................... 241
Selling Your Reserved Instances ...................................................................................... 245
After Your Reserved Instance Is Sold ............................................................................... 264
Requirements Checklist for Reserved Instances ....................................................................... 266
Instance Metadata and User Data ...................................................................................................... 268
Importing and Exporting Instances ..................................................................................................... 279
Prerequisites ............................................................................................................................. 280
Importing a VM into Amazon EC2 ............................................................................................. 282
Step 1: Install the Amazon EC2 CLI ................................................................................. 283
Step 2: Prepare Your VM .................................................................................................. 283
Step 3: Export Your VM from Its Virtual Environment ....................................................... 284
Step 4: Importing Your VM into Amazon EC2 ................................................................... 284
Checking on the Status of Your Import Task ........................................................... 286
Importing Your Volumes into Amazon EBS ............................................................. 288
Resuming an Upload .............................................................................................. 289
Canceling an Upload .............................................................................................. 290
Cleaning Up After an Upload .................................................................................. 290
Step 5: Launch the instance in Amazon EC2 ................................................................... 291
Exporting Amazon EC2 Instances ............................................................................................ 291
Troubleshooting ......................................................................................................................... 292
Instance Lifecycle ............................................................................................................................... 297
Launch ................................................................................................................................................ 300
Launching an Instance .............................................................................................................. 300
Launching an Instance from a Backup ...................................................................................... 305
Launching an AWS Marketplace Instance ................................................................................. 306
API Version 2014-02-01
5
Amazon Elastic Compute Cloud User Guide
Connect .............................................................................................................................................. 308
Connect Using SSH .................................................................................................................. 308
Connect Using PuTTY ............................................................................................................... 312
Connect Using MindTerm .......................................................................................................... 316
Connect Using RDP .................................................................................................................. 317
Stop and Start ..................................................................................................................................... 319
Reboot ................................................................................................................................................ 322
Retire .................................................................................................................................................. 322
Terminate ............................................................................................................................................ 325
Configure Instances ............................................................................................................................ 331
Managing Software ............................................................................................................................. 332
Updating Instance Software ...................................................................................................... 332
Adding Repositories .................................................................................................................. 336
Finding Software Packages ....................................................................................................... 337
Installing Software Packages .................................................................................................... 338
Preparing to Compile Software ................................................................................................. 339
Managing Users .................................................................................................................................. 340
Set the Time for an Instance ............................................................................................................... 341
Changing the Hostname ..................................................................................................................... 344
Using Dynamic DNS ........................................................................................................................... 347
Launching Instances with User Data .................................................................................................. 349
Monitoring ........................................................................................................................................... 353
Automated and Manual Monitoring ..................................................................................................... 354
Best Practices for Monitoring .............................................................................................................. 356
Monitoring the Status of Your Instances ............................................................................................. 356
Monitoring Instances with Status Checks .................................................................................. 356
Monitoring Events for Your Instances ........................................................................................ 361
Monitoring Your Instances with CloudWatch ....................................................................................... 364
Enabling or Disabling Detailed Monitoring on an Amazon EC2 Instance .................................. 365
View Amazon EC2 Metrics ........................................................................................................ 368
Get Statistics for Metrics ........................................................................................................... 373
Get Statistics for a Specific EC2 Instance ....................................................................... 374
Aggregating Statistics Across Instances .......................................................................... 378
Get Statistics Aggregated by Auto Scaling Group ........................................................... 383
Get Statistics Aggregated by Image (AMI) ID .................................................................. 385
Graphing Metrics ....................................................................................................................... 390
Graph a Metric ................................................................................................................. 390
Graph a Metric Across Resources ................................................................................... 391
Create a CloudWatch Alarm ...................................................................................................... 394
Send Email Based on CPU Usage Alarm ........................................................................ 394
Send Email Based on Load Balancer Alarm .................................................................... 396
Send Email Based on Storage Throughput Alarm ........................................................... 399
Create Alarms That Stop or Terminate an Instance .................................................................. 401
Monitoring Scripts for Amazon EC2 Instances ................................................................................... 416
Amazon CloudWatch Monitoring Scripts for Linux .................................................................... 416
Amazon CloudWatch Monitoring Scripts for Windows .............................................................. 422
Network and Security ......................................................................................................................... 432
Key Pairs ............................................................................................................................................. 433
Security Groups .................................................................................................................................. 440
Controlling Access .............................................................................................................................. 448
IAM Policies ............................................................................................................................... 450
Supported Resources and Conditions ............................................................................. 456
Example Policies .............................................................................................................. 463
IAM Roles .................................................................................................................................. 477
Network Access ......................................................................................................................... 482
Amazon VPC ...................................................................................................................................... 485
Supported Platforms ................................................................................................................. 487
Instance IP Addressing ....................................................................................................................... 489
API Version 2014-02-01
6
Amazon Elastic Compute Cloud User Guide
Multiple Private IP Addresses ................................................................................................... 494
Elastic IP Addresses ........................................................................................................................... 498
Elastic Network Interfaces .................................................................................................................. 503
Enhanced Networking ........................................................................................................................ 516
Storage ............................................................................................................................................... 521
Amazon EBS ...................................................................................................................................... 523
EBS Volumes ............................................................................................................................. 524
EBS Volume Types ........................................................................................................... 525
Creating a Volume ............................................................................................................ 526
Restoring from a Snapshot .............................................................................................. 528
Attaching a Volume to an Instance ................................................................................... 529
Making a Volume Available for Use .................................................................................. 532
Volume Information .......................................................................................................... 536
Monitoring the Status of Your Volumes ............................................................................. 536
Detaching a Volume from an Instance ............................................................................. 546
Deleting a Volume ............................................................................................................ 547
Expanding a Volume ........................................................................................................ 548
Expanding a Linux Partition ............................................................................................. 554
EBS Snapshots ......................................................................................................................... 559
Creating a Snapshot ........................................................................................................ 559
Deleting a Snapshot ......................................................................................................... 560
Copying a Snapshot ......................................................................................................... 561
Snapshot Information ....................................................................................................... 562
Sharing Snapshots .......................................................................................................... 563
EBS Performance ...................................................................................................................... 564
EC2 Configuration ............................................................................................................ 565
I/O Characteristics ........................................................................................................... 566
Workload Demand ........................................................................................................... 567
Pre-Warm Volumes .......................................................................................................... 568
RAID Configuration .......................................................................................................... 572
Benchmark Volumes ........................................................................................................ 577
API and Command Overview .................................................................................................... 580
Instance Store ..................................................................................................................................... 582
Amazon S3 ......................................................................................................................................... 590
Block Device Mapping ........................................................................................................................ 592
Using Public Data Sets ....................................................................................................................... 603
Resources and Tags ........................................................................................................................... 606
Resource Locations ............................................................................................................................ 606
Listing and Filtering Your Resources .................................................................................................. 607
Tagging Your Resources ..................................................................................................................... 610
Usage Reports .................................................................................................................................... 618
Instance Usage ......................................................................................................................... 620
Reserved Instance Utilization .................................................................................................... 624
Troubleshooting .................................................................................................................................. 630
Launching Your Instance ..................................................................................................................... 630
Connecting to Your Instance ............................................................................................................... 631
Stopping Your Instance ....................................................................................................................... 636
Terminating Your Instance ................................................................................................................... 637
Failed Status Checks .......................................................................................................................... 638
Instance Capacity ............................................................................................................................... 661
General ............................................................................................................................................... 662
Making API Requests ......................................................................................................................... 664
Query Requests .................................................................................................................................. 665
Troubleshooting API Request Errors .................................................................................................. 668
Ensuring Idempotency ........................................................................................................................ 670
SOAP Requests .................................................................................................................................. 672
Document History ............................................................................................................................... 673
API Version 2014-02-01
7
Amazon Elastic Compute Cloud User Guide
What Is Amazon EC2?
Amazon Elastic Compute Cloud (Amazon EC2) provides resizable computing capacity in the Amazon
Web Services (AWS) cloud. Using Amazon EC2 eliminates your need to invest in hardware up front, so
you can develop 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, and 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.
Features of Amazon EC2
Amazon EC2 provides the following features:
Virtual computing environments, known as instances
Pre-configured templates for your instances, known as Amazon Machine Images (AMIs), that package
the bits you need for your server (including the operating system and additional software)
Various configurations of CPU, memory, storage, and networking capacity for your instances, known
as instance types
Secure login information for your instances using key pairs (AWS stores the public key, and you store
the private key in a secure place)
Storage volumes for temporary data that's deleted when you stop or terminate your instance, known
as instance store volumes
Persistent storage volumes for your data using Amazon Elastic Block Store (Amazon EBS), known as
Amazon EBS volumes
Multiple physical locations for your resources, such as instances and Amazon EBS volumes, known
as regions and Availability Zones
A firewall that enables you to specify the protocols, ports, and source IP ranges that can reach your
instances using security groups
Static IP addresses for dynamic cloud computing, known as Elastic IP addresses
Metadata, known as tags, that you can create and assign to your Amazon EC2 resources
Virtual networks you can create that are logically isolated from the rest of the AWS cloud, and that you
can optionally connect to your own network, known as virtual private clouds (VPCs)
For more information about the features of Amazon EC2, see the Amazon EC2 product page.
API Version 2014-02-01
1
Amazon Elastic Compute Cloud User Guide
Features of Amazon EC2
How to Get Started with Amazon EC2
The first thing you need to do is get set up to use Amazon EC2. After you are set up, you are ready to
complete the Getting Started tutorial for Amazon EC2. Whenever you need more information about a
feature of Amazon EC2, you can read the technical documentation.
Getting Started
Setting Up with Amazon EC2 (p. 19)
Getting Started with Amazon EC2 Linux Instances (p. 24)
Getting Started with Amazon EC2 Windows Instances
Basics
Instances and AMIs (p. 4)
Instance Types (p. 97)
Regions and Availability Zones (p. 7)
Tags (p. 610)
Networking and Security
Amazon EC2 Key Pairs (p. 433)
Security Groups (p. 440)
Elastic IP Addresses (EIP) (p. 498)
Amazon EC2 and Amazon VPC (p. 485)
Storage
Amazon EBS (p. 523)
Instance Store (p. 582)
If you have questions about whether AWS is right for you, Contact AWS Sales. If you have technical
questions about Amazon EC2, use the Amazon EC2 forum.
Related Services
You can provision Amazon EC2 resources, such as instances and volumes, directly using Amazon EC2.
You can also provision Amazon EC2 resources using other services in AWS. For more information, see
the following documentation:
Auto Scaling Developer Guide
AWS CloudFormation User Guide
AWS Elastic Beanstalk Developer Guide
AWS OpsWorks User Guide
API Version 2014-02-01
2
Amazon Elastic Compute Cloud User Guide
How to Get Started with Amazon EC2
To automatically distribute incoming application traffic across multiple instances, use Elastic Load
Balancing. For more information, see Elastic Load Balancing Developer Guide.
To monitor basic statistics for your instances and Amazon EBS volumes, use Amazon CloudWatch. For
more information, see Monitoring Your Instances with CloudWatch (p. 364).
To monitor the calls made to the Amazon EC2 API for your account, including calls made by the AWS
Management Console, command line tools, and other services, use AWS CloudTrail. For more information,
see the AWS CloudTrail User Guide.
To get a managed relational database in the cloud, use Amazon Relational Database Service (Amazon
RDS) to launch a database instance. Although you can set up a database on an EC2 instance, Amazon
RDS offers the advantage of handling your database management tasks, such as patching the software,
backing up, and storing the backups. For more information, see Amazon Relational Database Service
Developer Guide.
Accessing Amazon EC2
Amazon EC2 provides a web-based user interface, the Amazon EC2 console. If you've signed up for an
AWS account, you can access the Amazon EC2 console by signing into the AWS Management Console
and selecting EC2 from the console home page.
If you prefer to use a command line interface, you have several options:
AWS Command Line Interface (CLI)
Provides commands for a broad set of AWS products, and is supported on Windows, Mac, and
Linux/Unix. To get started, see AWS Command Line Interface User Guide. For more information
about the commands for Amazon EC2, see ec2.
Amazon EC2 Command Line Interface (CLI) Tools
Provides commands for Amazon EC2, Amazon EBS, and Amazon VPC, and is supported on Windows,
Mac, and Linux/Unix. To get started, see Setting Up the Amazon EC2 Command Line Interface Tools
on Linux and Commands (CLI Tools) in the Amazon Elastic Compute Cloud Command Line Reference.
AWS Tools for Windows PowerShell
Provides commands for a broad set of AWS products for those who script in the PowerShell
environment. To get started, see AWS Tools for Windows PowerShell User Guide.
Amazon EC2 provides a Query API. These requests are HTTP or HTTPS requests that use the HTTP
verbs GET or POST and a Query parameter named Action. For more information about the API actions
for Amazon EC2, see Actions in the Amazon Elastic Compute Cloud API Reference.
If you prefer to build applications using language-specific APIs instead of submitting a request over HTTP
or HTTPS, AWS provides libraries, sample code, tutorials, and other resources for software developers.
These libraries provide basic functions that automatically take care of tasks such as cryptographically
signing your requests, retrying requests, and handling error responses, so that it is easier for you to get
started. For more information about downloading the AWS SDKs, see AWS SDKs and Tools. For a list
of available APIs for Amazon EC2, see Available APIs for Amazon EC2 (p. 664).
Pricing for Amazon EC2
When you sign up for AWS, you can get started with Amazon EC2 for free using the AWS Free Usage
Tier.
Amazon EC2 provides the following purchasing options for instances:
API Version 2014-02-01
3
Amazon Elastic Compute Cloud User Guide
Accessing Amazon EC2
On-Demand Instances
Pay for the instances that you use by the hour, with no long-term commitments or upfront payments.
Reserved Instances
Make a low, one-time, upfront payment for an instance, reserve it for a one- or three-year term, and
pay a significantly lower hourly rate for these instances.
Spot Instances
Specify the maximum hourly price that you are willing to pay to run a particular instance type. The
Spot Price fluctuates based on supply and demand, but you never pay more than the maximum price
you specified. If the Spot Price moves higher than your maximum price, Amazon EC2 shuts down
your Spot Instances.
For a complete list of charges and specific prices for Amazon EC2, see Amazon EC2 Pricing.
To calculate the cost of a sample provisioned environment, see AWS Economics Center.
To see your bill, go to your AWS Account Activity page. Your bill contains links to usage reports that
provide details about your bill. To learn more about AWS account billing, see AWS Account Billing.
If you have questions concerning AWS billing, accounts, and events, Contact AWS Support.
For an overview of Trusted Advisor, a service that helps you optimize the costs, security, and performance
of your AWS environment, see AWS Trusted Advisor.
Instances and AMIs
An Amazon Machine Image (AMI) is a template that contains a software configuration (for example, an
operating system, an application server, and applications). From an AMI, you launch an instance, which
is a copy of the AMI running as a virtual server in the cloud. You can launch multiple instances of an AMI,
as shown in the following figure.
Your instances keep running until you stop or terminate them, or until they fail. If an instance fails, you
can launch a new one from the AMI.
Instances
You can launch different types of instances from a single AMI. An instance type essentially determines
the hardware of the host computer used for your instance. Each instance type offers different compute
and memory capabilities. Select an instance type based on the amount of memory and computing power
API Version 2014-02-01
4
Amazon Elastic Compute Cloud User Guide
Instances and AMIs
that you need for the application or software that you plan to run on the instance. For more information
about the hardware specifications for each Amazon EC2 instance type, see Instance Type Details.
After you launch an instance, it looks like a traditional host, and you can interact with it as you would any
computer. You have complete control of your instances; you can use sudo to run commands that require
root privileges.
Your AWS account has a limit on the number of instances that you can have running. For more information
about this limit, and how to request an increase, see How many instances can I run in Amazon EC2 in
the Amazon EC2 General FAQ.
In addition to the limit on running instances, there is a limit on the overall number of instances that you
can have (whether running, stopped, or in any other state except for terminated). This overall instance
limit is two times your running instance limit.
Storage for Your Instance
The root device for your instance contains the image used to boot the instance. For more information,
see Amazon EC2 Root Device Volume (p. 13).
Your instance may include local storage volumes, known as instance store volumes, which you can
configure at launch time with block device mapping. For more information, see Block Device
Mapping (p. 592). After these volumes have been added to and mapped on your instance, they are available
for you to mount and use. If your instance fails, or if your instance is stopped or terminated, the data on
these volumes is lost; therefore, these volumes are best used for temporary data. For important data,
you should use a replication strategy across multiple instances in order to keep your data safe, or store
your persistent data in Amazon S3 or Amazon EBS volumes. For more information, see Storage (p. 521).
Security Best Practices
Use AWS Identity and Access Management (IAM) to control access to your AWS resources, including
your instances. You can create IAM users and groups under your AWS account, assign security
credentials to each, and control the access that each has to resources and services in AWS. For more
information, see Controlling Access to Amazon EC2 Resources (p. 448).
Restrict access by only allowing trusted hosts or networks to access ports on your instance. For example,
you can restrict SSH access by restricting incoming traffic on port 22. For more information, see Amazon
EC2 Security Groups (p. 440).
Review the rules in your security groups regularly, and ensure that you apply the principle of least
privilegeonly open up permissions that you require. You can also create different security groups to
deal with instances that have different security requirements. Consider creating a bastion security group
that allows external logins, and keep the remainder of your instances in a group that does not allow
external logins.
Disable password-based logins for instances launched from your AMI. Passwords can be found or
cracked, and are a security risk. For more information, see Disable Password-Based Logins for
Root (p. 61). For more information about sharing AMIs safely, see Shared AMIs (p. 54).
Stopping, Starting, and Terminating Instances
Stopping an instance
When an instance is stopped, the instance performs a normal shutdown, and then transitions to a stopped
state. All of its Amazon EBS volumes remain attached, and you can start the instance again at a later
time.
You are not charged for additional instance hours while the instance is in a stopped state. A full instance
hour will be charged for every transition from a stopped state to a running state, even if this happens
API Version 2014-02-01
5
Amazon Elastic Compute Cloud User Guide
Instances
multiple times within a single hour. If the instance type was changed while the instance was stopped, you
will be charged the rate for the new instance type after the instance is started. All of the associated Amazon
EBS usage of your instance, including root device usage, is billed using typical Amazon EBS prices.
When an instance is in a stopped state, you can attach or detach Amazon EBS volumes. You can also
create an AMI from the instance, and you can change the kernel, RAM disk, and instance type.
Terminating an instance
When an instance is terminated, the instance performs a normal shutdown, then the attached Amazon
EBS volumes are deleted unless the volume's deleteOnTermination attribute is set to false. The
instance itself is also deleted, and you can't start the instance again at a later time.
To prevent accidental termination, you can disable instance termination. If you do so, ensure that the
disableApiTermination attribute is set to true for the instance. To control the behavior of an instance
shutdown, such as shutdown -h in Linux or shutdown in Windows, set the
instanceInitiatedShutdownBehavior instance attribute to stop or terminate as desired. Instances
with Amazon EBS volumes for the root device default to stop, and instances with instance-store root
devices are always terminated as the result of an instance shutdown.
For more information, see Instance Lifecycle (p. 297).
AMIs
Amazon Web Services (AWS) publishes many Amazon Machine Images (AMIs) that contain common
software configurations for public use. In addition, members of the AWS developer community have
published their own custom AMIs. You can also create your own custom AMI or AMIs; doing so enables
you to quickly and easily start new instances that have everything you need. For example, if your application
is a website or a web service, your AMI could include a web server, the associated static content, and
the code for the dynamic pages. As a result, after you launch an instance from this AMI, your web server
starts, and your application is ready to accept requests.
All AMIs are categorized as either backed by Amazon EBS, which means that the root device for an
instance launched from the AMI is an Amazon EBS volume, or backed by instance store, which means
that the root device for an instance launched from the AMI is an instance store volume created from a
template stored in Amazon S3.
The description of an AMI indicates the type of root device (either ebs or instance store). This is
important because there are significant differences in what you can do with each type of AMI. For more
information about these differences, see Storage for the Root Device (p. 50).
API Version 2014-02-01
6
Amazon Elastic Compute Cloud User Guide
AMIs
Regions and Availability Zones
Amazon EC2 is hosted in multiple locations world-wide. These locations are composed of regions and
Availability Zones. Each region is a separate geographic area. Each region has multiple, isolated locations
known as Availability Zones. Amazon EC2 provides you the ability to place resources, such as instances,
and data in multiple locations. Resources aren't replicated across regions unless you do so specifically.
Amazon operates state-of-the-art, highly-available data centers. Although rare, failures can occur that
affect the availability of instances that are in the same location. If you host all your instances in a single
location that is affected by such a failure, none of your instances would be available.
Note
Some AWS resources might not be available in all regions and Availability Zones. Ensure that
you can create the resources you need in the desired regions or Availability Zone before deploying
your applications.
Topics
Region and Availability Zone Concepts (p. 7)
Describing Your Regions and Availability Zones (p. 9)
Specifying the Region for a Resource (p. 11)
Launching Instances in an Availability Zone (p. 12)
Migrating an Instance to Another Availability Zone (p. 13)
Region and Availability Zone Concepts
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.
Amazon EC2 resources are either global, tied to a region, or tied to an Availability Zone. For more
information, see Resource Locations (p. 606).
Regions
Each Amazon EC2 region is designed to be completely isolated from the other Amazon EC2 regions.
This achieves the greatest possible fault tolerance and stability.
Amazon EC2 provides multiple regions so that you can launch Amazon EC2 instances in locations that
meet your requirements. For example, you might want to launch instances in Europe to be closer to your
European customers or to meet legal requirements. The following table lists the regions that provide
support for Amazon EC2.
API Version 2014-02-01
7
Amazon Elastic Compute Cloud User Guide
Regions and Availability Zones
Name Code
Asia Pacific (Tokyo) Region ap-northeast-1
Asia Pacific (Singapore) Region ap-southeast-1
Asia Pacific (Sydney) Region ap-southeast-2
EU (Ireland) Region eu-west-1
South America (Sao Paulo) Region sa-east-1
US East (Northern Virginia) Region us-east-1
US West (Northern California) Region us-west-1
US West (Oregon) Region us-west-2
When you view your resources, you'll only see the resources tied to the region you've specified. This is
because regions are isolated from each other, and we don't replicate resources across regions
automatically.
When you work with an instance using the command line interface or API actions, you must specify its
regional endpoint. For more information about the regions and endpoints for Amazon EC2, see Regions
and Endpoints in the Amazon Web Services General Reference. For more information about endpoints
and protocols in AWS GovCloud (US), see AWS GovCloud (US) Endpoints in the AWS GovCloud (US)
User Guide.
When you launch an instance, you must select an AMI that's in the same region. If the AMI is in another
region, you can copy the AMI to the region you're using. For more information, see Copying an AMI (p. 80).
All communications between regions is across the public Internet. Therefore, you should use the appropriate
encryption methods to protect your data. Data transfer between regions is charged at the Internet data
transfer rate for both the sending and the receiving instance. For more information, see Amazon EC2
Pricing - Data Transfer.
Availability Zones
You can list the Availability Zones that are available to your account. For more information, see Describing
Your Regions and Availability Zones (p. 9).
When you launch an instance, you can select an Availability Zone or let us choose one for you. If you
distribute your instances across multiple Availability Zones and one instance fails, you can design your
application so that an instance in another Availability Zone can handle requests.
You can also use Elastic IP addresses to mask the failure of an instance in one Availability Zone by rapidly
remapping the address to an instance in another Availability Zone. For more information, see Elastic IP
Addresses (EIP) (p. 498).
To ensure that resources are distributed across the Availability Zones for a region, we independently map
Availability Zones to identifiers for each account. For example, your Availability Zone us-east-1a might
not be the same location as us-east-1a for another account. Note that there's no way for you to
coordinate Availability Zones between accounts.
As Availability Zones grow over time, our ability to expand them can become constrained. If this happens,
we might restrict you from launching an instance in a constrained Availability Zone unless you already
have an instance in that Availability Zone. Eventually, we might also remove the constrained Availability
Zone from the list of Availability Zones for new customers. Therefore, your account might have a different
number of available Availability Zones in a region than another account.
API Version 2014-02-01
8
Amazon Elastic Compute Cloud User Guide
Region and Availability Zone Concepts
Describing Your Regions and Availability Zones
You can use the AWS Management Console or the command line interface to determine which regions
and Availability Zones are available for your use. For more information about these command line
interfaces, see Accessing Amazon EC2 (p. 3).
To find your regions and Availability Zones using the AWS Management Console
1. Open the AWS Management Console.
2. From the navigation bar, view the options in the region selector.
3. Open the Amazon EC2 console. Your Availability Zones are listed on the dashboard under Service
Health, under Availability Zone Status.
API Version 2014-02-01
9
Amazon Elastic Compute Cloud User Guide
Describing Your Regions and Availability Zones
To find your regions and Availability Zones using the AWS CLI
1. Use the describe-regions command as follows to describe your regions.
PROMPT> aws ec2 describe-regions
{
"Regions": [
{
"Endpoint": "ec2.us-east-1.amazonaws.com",
"RegionName": "us-east-1"
},
{
"Endpoint": "ec2.ap-southeast-1.amazonaws.com",
"RegionName": "ap-southeast-1"
},
{
"Endpoint": "ec2.ap-southeast-2.amazonaws.com",
"RegionName": "ap-southeast-2"
},
...
]
}
2. Use the describe-availability-zones command as follows to describe your Availability Zones within
the us-east-1 region.
PROMPT> aws ec2 describe-availability-zones --region us-east-1
{
"AvailabilityZones": [
{
"State": "available",
"RegionName": "us-east-1",
"Messages": [],
"ZoneName": "us-east-1b"
},
{
"State": "available",
"RegionName": "us-east-1",
"Messages": [],
"ZoneName": "us-east-1c"
},
{
"State": "available",
"RegionName": "us-east-1",
"Messages": [],
"ZoneName": "us-east-1d"
}
]
}
To find your regions and Availability Zones using the Amazon EC2 CLI
1. Use the ec2-describe-regions command as follows to describe your regions.
API Version 2014-02-01
10
Amazon Elastic Compute Cloud User Guide
Describing Your Regions and Availability Zones
PROMPT> ec2-describe-regions
REGION us-east-1 ec2.us-east-1.amazonaws.com
REGION ap-northeast-1 ec2.ap-northeast-1.amazonaws.com
REGION ap-southeast-1 ec2.ap-southeast-1.amazonaws.com
..
2. Use the ec2-describe-availability-zones command as follows to describe your Availability Zones
within the us-east-1 region.
PROMPT> ec2-describe-availability-zones --region us-east-1
AVAILABILITYZONE us-east-1a available us-east-1
AVAILABILITYZONE us-east-1b available us-east-1
AVAILABILITYZONE us-east-1c available us-east-1
AVAILABILITYZONE us-east-1d available us-east-1
Specifying the Region for a Resource
Every time you create an Amazon EC2 resource, you can specify the region for the resource. You can
specify the region for a resource using the AWS Management Console or the command line.
To specify the region for a resource using the console
1. Open the Amazon EC2 console.
2. Use the region selector in the navigation bar.
To specify the default region using the command line
You can set the value of an environment variable to the desired regional endpoint (for example,
https://ec2.us-west-1.amazonaws.com):
API Version 2014-02-01
11
Amazon Elastic Compute Cloud User Guide
Specifying the Region for a Resource
AWS_DEFAULT_REGION (AWS CLI)
EC2_URL (Amazon EC2 CLI)
Alternatively, you can use the --region command line option with each individual command. For example,
--region us-west-1.
For more information about the endpoints for Amazon EC2, see Amazon Elastic Compute Cloud Endpoints.
Launching Instances in an Availability Zone
When you launch an instance, select a region that puts your instances closer to specific customers, or
meets the legal or other requirements you have. By launching your instances in separate Availability
Zones, you can protect your applications from the failure of a single location.
When you launch an instance, you can optionally specify an Availability Zone in the region that you are
using. If you do not specify an Availability Zone, we select one for you. When you launch your initial
instances, we recommend that you accept the default Availability Zone, because this enables us to select
the best Availability Zone for you based on system health and available capacity. If you launch additional
instances, only specify an Availability Zone if your new instances must be close to, or separated from,
your running instances.
To specify an Availability Zone for your instance using the console
1. Open the Amazon EC2 console.
2. On the dashboard, click Launch Instance.
3. Follow the directions for the wizard. On the Configure Instance Details page, do the following:
[EC2-Classic] Select one of the Availability Zone options from the list, or select No Preference to
enable us to select the best one for you.
[EC2-VPC] Select one of the subnet options from the list, or select No preference (default subnet
in any Availability Zone) to enable us to select the best one for you.
To specify an Availability Zone for your instance using the AWS CLI
You can use the run-instances command with one of the following options:
[EC2-Classic] --placement
[EC2-VPC] --subnet-id
To specify an Availability Zone for your instance using the Amazon EC2 CLI
You can use the ec2-run-instances command with one of the following options:
[EC2-Classic] --availability-zone
[EC2-VPC] --subnet
API Version 2014-02-01
12
Amazon Elastic Compute Cloud User Guide
Launching Instances in an Availability Zone
Migrating an Instance to Another Availability Zone
If you need to, you can migrate an instance from one Availability Zone to another. For example, if you
are trying to modify the instance type of your instance and we can't launch an instance of the new instance
type in the current Availability Zone, you could migrate the instance to an Availability Zone where we can
launch an instance of that instance type.
The migration process involves creating an AMI from the original instance, launching an instance in the
new Availability Zone, and updating the configuration of the new instance, as shown in the following
procedure.
To migrate an instance to another Availability Zone
1. Create an AMI from the instance. The procedure depends on the operating system and the type of
root device volume for the instance. For more information, see the documentation that corresponds
to your operating system and root device volume:
Creating an Amazon EBS-Backed Linux AMI (p. 69)
Creating an Instance Store-Backed Linux AMI (p. 72)
Creating an Amazon EBS-Backed Windows AMI
Creating an Instance Store-Backed Windows AMI
2. [EC2-VPC] If you need to preserve the private IP address of the instance, you must delete the subnet
in the current Availability Zone and then create a subnet in the new Availability Zone with the same
IP address range as the original subnet. Note that you must terminate all instances in a subnet before
you can delete it. Therefore, you should move all instances in the current subnet to the new subnet.
3. Launch an instance from the AMI that you just created, specifying the new Availability Zone or subnet.
You can use the same instance type as the original instance, or select a new instance type. For more
information, see Launching Instances in an Availability Zone (p. 12).
4. If the original instance has an associated Elastic IP address, associate it with the new instance. For
more information, see Associating an Elastic IP Address with a Different Running Instance (p. 502).
5. If the original instance is a Reserved Instance, change the Availability Zone for your reservation. (If
you also changed the instance type, you can also change the instance type for your reservation.)
For more information, see Submitting Modification Requests (p. 236).
6. (Optional) Terminate the original instance. For more information, see Terminating an Instance (p. 325).
Amazon EC2 Root Device Volume
When you launch an instance, the root device volume contains the image used to boot the instance.
When we introduced Amazon EC2, all AMIs were backed by Amazon EC2 instance store, which means
the root device for an instance launched from the AMI is an instance store volume created from a template
stored in Amazon S3. After we introduced Amazon EBS, we introduced AMIs that are backed by Amazon
EBS. This means that the root device for an instance launched from the AMI is an Amazon EBS volume
created from an Amazon EBS snapshot. You can choose between AMIs based by Amazon EC2 instance
store and AMIs backed by Amazon EBS. We recommend that you use AMIs backed by Amazon EBS,
because they launch faster and use persistent storage.
Topics
Root Device Storage Concepts (p. 14)
Choosing an AMI by Root Device Type (p. 15)
Determining the Root Device Type of Your Instance (p. 16)
Changing the Root Device Volume to Persist (p. 16)
API Version 2014-02-01
13
Amazon Elastic Compute Cloud User Guide
Migrating an Instance to Another Availability Zone
Root Device Storage Concepts
You can launch an instance from one of two types of AMIs: an instance store-backed AMI or an Amazon
EBS-backed AMI. The description of an AMI includes which type of AMI it is; you'll see the root device
referred to in some places as either ebs (for Amazon EBS-backed) or instance store (for instance
store-backed). This is important because there are significant differences between what you can do with
each type of AMI. For more information about these differences, see Storage for the Root Device (p. 50).
Instance Store-backed Instances
Instances that use instance stores 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 (typically sda1). Any data on the instance store volumes persists
as long as the instance is running, but this data is deleted when the instance is terminated (instance
store-backed instances do not support the Stop action) or if it fails (such as if an underlying drive has
issues).
After an instance store-backed instance fails or terminates, it cannot be restored. If you plan to use
Amazon EC2 instance store-backed instances, we highly recommend that you distribute the data on your
instance stores across multiple Availability Zones. You should also back up the data on your instance
store volumes to persistent storage on a regular basis.
For more information, see Amazon EC2 Instance Store (p. 582).
Amazon EBS-backed Instances
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 Amazon
EBS snapshot referenced by the AMI you use. You can optionally use other Amazon EBS volumes or
instance store volumes.
API Version 2014-02-01
14
Amazon Elastic Compute Cloud User Guide
Root Device Storage Concepts
An Amazon EBS-backed instance can be stopped and later restarted without affecting data stored in the
attached volumes. There are various instance and volume-related tasks you can do when an Amazon
EBS-backed instance is in a stopped state. For example, you can modify the properties of the instance,
you can change the size of your instance or update the kernel it is using, or you can attach your root
volume to a different running instance for debugging or any other purpose.
By default, the root device volume and the other Amazon EBS volumes attached when you launch an
Amazon EBS-backed instance are automatically deleted when the instance terminates. For information
about how to change this behavior when you launch an instance, see Changing the Root Device Volume
to Persist (p. 16).
By default, any Amazon EBS volumes that you attach to a running instance are detached with their data
intact when the instance terminates. You can attach a detached volume to any running instance.
If an Amazon EBS-backed instance fails, you can restore your session by following one of these methods:
Stop and then start again.
Automatically snapshot all relevant volumes and create a new AMI. For more information, see Creating
an Amazon EBS-Backed Linux AMI (p. 69).
Attach the volume to the new instance by following these steps:
1. Create a snapshot of the root volume.
2. Register a new AMI using the snapshot.
3. Launch a new instance from the new AMI.
4. Detach the remaining Amazon EBS volumes from the old instance.
5. Reattach the Amazon EBS volumes to the new instance.
We recommend using either the first or the second method for failed instances with normal volume size,
and the third method for failed instances with large volumes.
Choosing an AMI by Root Device Type
The AMI that you specify when you launch your instance determines the type of root device volume that
your instance has.
To choose an Amazon EBS-backed AMI using the console
1. Open the Amazon EC2 console.
2. In the navigation pane, click AMIs.
3. From the filter lists, select the image type (such as Public images), the operating system (such as
Amazon Linux), and EBS images.
4. (Optional) To get additional information to help you make your choice, click the Show/Hide Columns
icon, update the columns to display, and click Close.
5. Choose an AMI and write down its AMI ID.
To choose an instance store-backed AMI using the console
1. Open the Amazon EC2 console.
2. In the navigation pane, click AMIs.
3. From the filter lists, select the image type (such as Public images), the operating system (such as
Amazon Linux), and Instance store images.
4. (Optional) To get additional information to help you make your choice, click the Show/Hide Columns
icon, update the columns to display, and click Close.
API Version 2014-02-01
15
Amazon Elastic Compute Cloud User Guide
Choosing an AMI by Root Device Type
5. Choose an AMI and write down its AMI ID.
To verify the type of the root device volume of an AMI using the command line
You can use one of the following commands. For more information about these command line interfaces,
see Accessing Amazon EC2 (p. 3).
describe-images (AWS CLI)
ec2-describe-images (Amazon EC2 CLI)
Get-EC2Image (AWS Tools for Windows PowerShell)
Determining the Root Device Type of Your Instance
To determine the root device type of an instance using the console
1. Open the Amazon EC2 console.
2. In the navigation pane, click Instances, and select the instance.
3. Check the value of Root device type in the Description tab as follows:
If the value is ebs, this is an Amazon EBS-backed instance.
If the value is instance store, this is an instance store-backed instance.
To determine the root device type of an instance using the command line
You can use one of the following commands. For more information about these command line interfaces,
see Accessing Amazon EC2 (p. 3).
describe-instances (AWS CLI)
ec2-describe-instances (Amazon EC2 CLI)
Get-EC2Instance (AWS Tools for Windows PowerShell)
Changing the Root Device Volume to Persist
By default, the root device volume for an AMI backed by Amazon EBS is deleted when the instance
terminates. To change the default behavior, set the DeleteOnTermination attribute to false using a
block device mapping.
Changing the Root Volume to Persist Using the Console
Using the console, you can change the DeleteOnTermination attribute when you launch an instance.
To change this attribute for a running instance, you must use the command line.
To change the root device volume of an instance to persist at launch using the console
1. Open the Amazon EC2 console.
2. From the Amazon EC2 console dashboard, click Launch Instance.
3. On the Choose an Amazon Machine Image (AMI) page, choose the AMI to use and click Select.
4. Follow the wizard to complete the Choose an Instance Type and Configure Instance Details
pages.
API Version 2014-02-01
16
Amazon Elastic Compute Cloud User Guide
Determining the Root Device Type of Your Instance
5. On the Add Storage page, deselect the Delete On Termination check box for the root volume.
6. Complete the remaining wizard pages, and then click Launch.
You can verify the setting by viewing details for the root device volume on the instance's details pane.
Next to Block devices, click the entry for the root device volume. By default, Delete on termination is
True. If you change the default behavior, Delete on termination is False.
Changing the Root Volume of an Instance to Persist Using
the AWS CLI
Using the AWS CLI, you can change the DeleteOnTermination attribute when you launch an instance
or while the instance is running. The root device is typically /dev/sda1 (Linux) or xvda (Windows).
Example at Launch
Use the run-instances command to preserve the root volume by including a block device mapping that
sets its DeleteOnTermination attribute for to false.
aws ec2 run-instances --image-id ami-1a2b3c4d --block-device-mappings
"[{\"DeviceName\":\"/dev/sda1\",\"Ebs\":{\"DeleteOnTermination\":false}}]"
other parameters...
You can confirm that DeleteOnTermination is false by using the describe-instances command and
looking for the BlockDeviceMappings entry for /dev/sda1 in the command output, as shown here.
...
"BlockDeviceMappings": [
{
"DeviceName": "/dev/sda1",
"Ebs": {
"Status": "attached",
"DeleteOnTermination": false,
"VolumeId": "vol-877166c8",
"AttachTime": "2013-07-19T02:42:39.000Z"
}
}
...
Example While the Instance is Running
Use the modify-instance-attribute command to preserve the root volume by including a block device
mapping that sets its DeleteOnTermination attribute to false.
aws ec2 modify-instance-attribute --instance-id i-5203422c --block-device-map
pings "[{\"DeviceName\": \"/dev/sda1\",\"Ebs\":{\"DeleteOnTermina
tion\":false}}]"
Changing the Root Volume of an Instance to Persist Using
the Amazon EC2 CLI
Using the Amazon EC2 CLI, you can change the DeleteOnTermination attribute when you launch an
instance or while the instance is running. The root device is typically /dev/sda1 (Linux) or xvda
(Windows).
API Version 2014-02-01
17
Amazon Elastic Compute Cloud User Guide
Changing the Root Device Volume to Persist
Example at Launch
Use the ec2-run-instances command to include a block device mapping that sets the
DeleteOnTermination flag for the root device to false. Include the -v option to run the command in
verbose mode.
ec2-run-instances ami-1a2b3c4d -b /dev/sda1=::false other parameters... -v
If you're using the command line tools on a Windows system, you must put quotation marks around the
block device mapping value.
ec2-run-instances ami-1a2b3c4d -b "xvda=::false" other parameters... -v
By running the command in verbose mode, you can see the underlying request and response, and confirm
that DeleteOnTermination is false, as shown here.
...
<blockDeviceMapping>
<item>
<deviceName>/dev/sda1</deviceName>
<ebs>
<deleteOnTermination>false</deleteOnTermination>
</ebs>
</item>
</blockDeviceMapping>
...
Example While the Instance is Running
Use the ec2-modify-instance-attribute command to preserve the root volume by setting its
DeleteOnTermination attribute to false.
ec2-modify-instance-attribute i-5203422c -b /dev/sda1=::false
If you're using the command line tools on a Windows system, you must put quotation marks around the
block device mapping value.
ec2-modify-instance-attribute i-5203422c -b "xvda=::false"
API Version 2014-02-01
18
Amazon Elastic Compute Cloud User Guide
Changing the Root Device Volume to Persist
Setting Up with Amazon EC2
Before you use Amazon EC2 for the first time, complete the following tasks:
1. Sign Up for AWS (p. 19)
2. Create an IAM User (p. 19)
3. Create a Key Pair (p. 21)
4. Create a Security Group (p. 22)
Sign Up for AWS
When you sign up for Amazon Web Services (AWS), your AWS account is automatically signed up for
all services in AWS, including Amazon EC2. You are charged only for the services that you use.
With Amazon EC2, you pay only for what you use. If you are a new AWS customer, you can get started
with Amazon EC2 for free. For more information, see AWS Free Usage Tier.
If you have an AWS account already, skip to the next task. 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 then click Sign Up.
2. Follow the on-screen instructions.
Part of the sign-up procedure involves receiving a phone call and entering a PIN using the phone
keypad.
Note your AWS account number, because you'll need it for the next task.
Create an IAM User
Services in AWS, such as Amazon EC2, require that you provide credentials when you access them, so
that the service can determine whether you have permission to access its resources. The console requires
your password. You can create access keys for your AWS account to access the command line interface
API Version 2014-02-01
19
Amazon Elastic Compute Cloud User Guide
Sign Up for AWS
or API. However, we don't recommend that you access AWS using the credentials for your AWS account;
we recommend that you use AWS Identity and Access Management (IAM) instead. Create an IAM user,
and then add the user to an IAM group with administrative permissions or and grant this user administrative
permissions. You can then access AWS using a special URL and the credentials for the IAM user.
If you signed up for AWS but have not created an IAM user for yourself, you can create one using the
IAM console.
To create an administrator group with an IAM user
1. Open the IAM console at https://console.aws.amazon.com/iam/.
Enter the email address and password that you used when you signed up for AWS.
2. From the dashboard, click Create a New Group of Users.
3. Enter Administrators in the Group Name box.
4. Select the Administrator Access policy template, which grants users in the group permission to
perform any action on any AWS resource, and then click Continue.
5. On the Create New Users tab, enter an IAM user name for yourself in box 1, and then click Continue.
6. When prompted, click Continue.
7. If you plan to use the CLI or the API for Amazon EC2, click Download Credentials or Show User
Security Credentials, and then save the access keys in a secure place. When you have finished,
click Close Window. Note that you can't get the secret access key after you close this window.
8. If you plan to use the AWS Management Console, click Users in the navigation pane, and then follow
these steps:
a. Select the user you just created.
b. Click the Security Credentials tab in the details pane.
c. Under Sign-In Credentials, click Manage Password.
d. In the Manage Password dialog box, select an option and click Apply.
e. If you assigned an auto-generated password, click Download Credentials or Show User
Security Credentials and save the password in a secure place.
To sign in as this new IAM user, sign out of the AWS console, then use the following URL, where
your_aws_account_id is your AWS account number without the hyphens (for example, if your AWS
account number is 1234-5678-9012, your AWS account ID is 123456789012):
https://your_aws_account_id.signin.aws.amazon.com/console/
Enter the IAM user name and password that you just created. When you're signed in, the navigation bar
displays "your_user_name @ your_aws_account_id".
If you don't want the URL for your sign-in page to contain your AWS account ID, you can create an account
alias. From the IAM dashboard, click Create Account Alias and enter an alias, such as your company
name. To sign in after you create an account alias, use the following URL:
https://your_account_alias.signin.aws.amazon.com/console/
To verify the sign-in link for IAM users for your account, open the IAM console and check under AWS
Account Alias on the dashboard.
For more information about IAM, see IAM and Amazon EC2 (p. 448).
API Version 2014-02-01
20
Amazon Elastic Compute Cloud User Guide
Create an IAM User
Create a Key Pair
AWS uses public-key cryptography to secure the login information for your instance. A Linux instance
has no password; you use a key pair to log in to your instance securely. You specify the name of the key
pair when you launch your instance, then provide the private key when you log in.
If you haven't created a key pair already, you can create one using the Amazon EC2 console. Note that
if you plan to launch instances in multiple regions, you'll need to create a key pair in each region. For
more information about regions, see Regions and Availability Zones (p. 7).
To create a key pair
1. Open the Amazon EC2 console.
2. From the navigation bar, select a region for the key pair. You can select any region that's available
to you, regardless of your location. However, key pairs are specific to a region; for example, if you
plan to launch an instance in the US West (Oregon) Region, you must create a key pair for the
instance in the US West (Oregon) Region.
3. Click Key Pairs in the navigation pane.
4. Click Create Key Pair.
5. Enter a name for the new key pair in the Key pair name field of the Create Key Pair dialog box, and
then click Create. Choose a name that is easy for you to remember, such as your IAM user name,
followed by -key-pair, plus the region name. For example, me-key-pair-uswest2.
6. The private key file is automatically downloaded by your browser. The base file name is the name
you specified as the name of your key pair, and the file name extension is .pem. Save the private
key file in a safe place.
Important
This is the only chance for you to save the private key file. You'll need to provide the name
of your key pair when you launch an instance and the corresponding private key each time
you connect to the instance.
7. If you will use an SSH client on a Mac or Linux computer to connect to your Linux instance, use the
following command to set the permissions of your private key file so that only you can read it.
API Version 2014-02-01
21
Amazon Elastic Compute Cloud User Guide
Create a Key Pair
$ chmod 400 your_user_name-key-pair-region_name.pem
For more information, see Amazon EC2 Key Pairs (p. 433).
If you'll connect to your Linux instance from a computer running Mac or Linux, you'll specify the .pem file
to your SSH client with the -i option and the path to your private key. If you'll connect to your Linux
instance from a computer running Windows, you can use either MindTerm or PuTTY. If you plan to use
PuTTY, you'll need to install it and use the following procedure to convert the .pem file to a .ppk file.
(Optional) To prepare to connect to a Linux instance from Windows using PuTTY
1. Download and install PuTTY from http://www.chiark.greenend.org.uk/~sgtatham/putty/. Be sure to
install the entire suite.
2. Start PuTTYgen (for example, from the Start menu, click All Programs > PuTTY > PuTTYgen).
3. Under Type of key to generate, select SSH-2 RSA.
4. Click Load. By default, PuTTYgen displays only files with the extension .ppk. To locate your .pem
file, select the option to display files of all types.
5. Select the private key file that you created in the previous procedure and click Open. Click OK to
dismiss the confirmation dialog box.
6. Click Save private key. PuTTYgen displays a warning about saving the key without a passphrase.
Click Yes.
7. Specify the same name for the key that you used for the key pair. PuTTY automatically adds the
.ppk file extension.
Create a Security Group
Security groups act as a firewall for associated instances, controlling both inbound and outbound traffic
at the instance level. You must add rules to a security group that enable you to connect to your instance
from your IP address using SSH. You can also add rules that allow inbound and outbound HTTP and
HTTPS access from anywhere.
Note that if you plan to launch instances in multiple regions, you'll need to create a security group in each
region. For more information about regions, see Regions and Availability Zones (p. 7).
Tip
You'll need the public IP address of your local computer, which you can get using a service. For
example, we provide the following service: http://checkip.amazonaws.com/. To locate another
service that provides your IP address, use the search phrase "what is my IP address." If you are
connecting through an Internet service provider (ISP) or from behind a firewall without a static
IP address, you need to find out the range of IP addresses used by client computers.
API Version 2014-02-01
22
Amazon Elastic Compute Cloud User Guide
Create a Security Group
To create a security group with least privilege
1. Open the Amazon EC2 console.
2. From the navigation bar, select a region for the security group. Security groups are specific to a
region; for example, if you plan to launch an instance in the US West (Oregon) Region, you must
create a security group for the instance in the US West (Oregon) Region.
3. Click Security Groups in the navigation pane.
4. Click Create Security Group.
5. Enter a name for the new security group and a description. Choose a name that is easy for you to
remember, such as your IAM user name, followed by _SG_, plus the region name. For example,
me_SG_uswest2.
6. On the Inbound tab, create the following rules (click Add Rule for each new rule), and click Create
when you're done:
Select HTTP from the Type list, and make sure that Source is set to Anywhere (0.0.0.0/0).
Select HTTPS from the Type list, and make sure that Source is set to Anywhere (0.0.0.0/0).
Select SSH from the Type list. In the Source box, ensure Custom IP is selected, and specify the
public IP address of your computer or network in CIDR notation. To specify an individual IP address
in CIDR notation, add the routing prefix /32. For example, if your IP address is 203.0.113.25,
specify 203.0.113.25/32. If your company allocates addresses from a range, specify the entire
range, such as 203.0.113.0/24.
Caution
For security reasons, we don't recommend that you allow SSH access from all IP addresses
(0.0.0.0/0) to your instance, except for testing purposes and only for a short time.
For more information, see Amazon EC2 Security Groups (p. 440).
API Version 2014-02-01
23
Amazon Elastic Compute Cloud User Guide
Create a Security Group
Getting Started with Amazon EC2
Linux Instances
Let's get started with Amazon Elastic Compute Cloud (Amazon EC2) by launching, connecting to, and
using a Linux instance. We'll use the AWS Management Console, a point-and-click web-based interface,
to complete the example architecture shown in the following diagram:
The instance is an Amazon EBS-backed instance (meaning that the root volume is an Amazon EBS
volume). We'll also create and attach an additional Amazon EBS volume. You can either specify the
Availability Zone in which your instance runs, or let us select an Availability Zone for you. When you
launch your instance, you secure it by specifying a key pair and security group. (This exercise assumes
that you created a key pair and a security group when getting set up; see Get Set Up for Amazon EC2.)
When you connect to your instance, you must specify the private key of the key pair that you specified
when launching your instance.
To complete this exercise, perform the following tasks:
1. Launch an Amazon EC2 Instance (p. 25)
2. Connect to Your Instance (p. 26)
3. Add a Volume to Your Instance (p. 29)
4. Clean Up Your Instance and Volume (p. 32)
API Version 2014-02-01
24
Amazon Elastic Compute Cloud User Guide
Related Topics
If you'd prefer to launch a Windows instance, see this tutorial: Getting Started with Amazon EC2 Windows
Instances.
If you'd prefer to use the AWS CLI, see this tutorial in the AWS Command Line Interface User Guide:
Using Amazon EC2 through the AWS CLI.
If you'd prefer to use the Amazon EC2 CLI, see this tutorial in the Amazon Elastic Compute Cloud
Command Line Reference: Launching an Instance Using the Amazon EC2 CLI.
For tutorials that show you how to use additional AWS products and services with Amazon EC2, see
Getting Started with AWS.
Launch an Amazon EC2 Instance
You can launch a Linux instance using the AWS Management Console as described in this topic. Before
you begin, be sure that you've completed the steps in Get Set Up for Amazon EC2. After you've launched
your instance, you can connect to it and use it. For more information, see Connect to Your Instance (p. 26).
If you'd prefer to launch and connect to a Windows instance, see Getting Started with Amazon EC2
Windows Instances.
Important
When you sign up for AWS, you can get started with Amazon EC2 for free using the AWS Free
Usage Tier. If you created your AWS account less than 12 months ago, and have not already
exceeded the Free Usage Tier benefits for Amazon EC2 and Amazon EBS, it will not cost you
anything to complete this tutorial, because we help you select options that are within the Free
Usage Tier benefits. Otherwise, you'll incur the standard Amazon EC2 usage fees from the time
that you launch the instance until you terminate the instance (which is the final task of this tutorial),
even if it remains idle. The total charges to complete this tutorial outside the Free Usage Tier
are minimal (typically only a few dollars).
The following procedure is intended to help you launch your first instance quickly and doesn't go through
all possible options. For more information about the advanced options, see Launching an Instance.
To launch an instance
1. Open the Amazon EC2 console at https://console.aws.amazon.com/ec2/.
2. From the console dashboard, click Launch Instance.
3. The Select an Amazon Machine Image (AMI) page displays a list of basic configurations called
Amazon Machine Images (AMIs) that serve as templates for your instance. Select the 64-bit Amazon
Linux AMI. Notice that this configuration is marked "Free tier eligible."
4. On the Select an Instance Type page, you can select the hardware configuration of your instance.
The t1.micro instance is selected by default. Click Review and Launch to let the wizard complete
other configuration settings for you, so you can get started quickly.
5. On the Review Instance Launch page, you can review the settings for your instance.
Under Security Groups, you'll see that the wizard created and selected a security group for you.
Instead, select the security group that you created when getting set up using the following steps:
a. Click Edit security groups.
b. On the Configure Security Group page, ensure the Select an existing security group option
is selected.
c. Select your security group from the list of existing security groups, and click Review and Launch.
API Version 2014-02-01
25
Amazon Elastic Compute Cloud User Guide
Step 1: Launch an Instance
6. On the Review Instance Launch page, click Launch.
7. In the Select an existing key pair or create a new key pair dialog box, select Choose an existing
key pair, then select the key pair you created when getting set up.
Alternatively, you can create a new key pair. Select Create a new key pair, enter a name for the
key pair, and then click Download Key Pair. This is the only chance for you to save the private key
file, so be sure to download it. Save the private key file in a safe place. You'll need to provide the
name of your key pair when you launch an instance and the corresponding private key each time
you connect to the instance.
A key pair enables you to connect to a Linux instance through SSH. Therefore, don't select the
Proceed without a key pair option. If you launch your instance without a key pair, then you can't
connect to it.
When you are ready, select the acknowledgment check box, and then click Launch Instances.
8. A confirmation page lets you know that your instance is launching. Click View Instances to close
the confirmation page and return to the console.
9. On the Instances screen, you can view the status of your instance. It takes a short time for an
instance to launch. When you launch an instance, its initial state is pending. After the instance
starts, its state changes to running, and it receives a public DNS name. (If the Public DNS column
is hidden, click the Show/Hide icon and select Public DNS.)
Connect to Your Instance
After you launch your instance, you can connect to it and use it the way that you'd use a computer sitting
in front of you.
If you receive an error while attempting to connect to your instance, see Troubleshooting Connecting to
Your Instance.
Before you try to connect to your instance, be sure that you've completed the following tasks:
Get the public DNS name of the instance
You can get the public DNS for your instance using the Amazon EC2 console (check the Public DNS
column; if this column is hidden, click the Show/Hide icon and select Public DNS). If you prefer, you
can use the ec2-describe-instances command.
Locate the private key
You'll need the fully-qualified path of the .pem file for the key pair that you specified when you launched
the instance.
Enable inbound SSH traffic from your IP address to your instance
Ensure that the security group associated with your instance allows incoming SSH traffic from your IP
address. For more information, see Authorizing Network Access to Your Instances.
There are several ways to connect to a Linux instance. Choose the method that meets your needs:
Option 1: Connect Using Your Browser (p. 27)
Option 2: Connect from Windows Using PuTTY (p. 27)
Option 3: Connect from Mac or Linux Using an SSH Client (p. 29)
Next Step
After you've successfully launched and connected to your instance, you can do any of the following:
API Version 2014-02-01
26
Amazon Elastic Compute Cloud User Guide
Step 2: Connect to Your Instance
Continue to the next step in this tutorial, Add a Volume to Your Instance (p. 29).
Continue using this instance with a different tutorial, such as Installing a LAMP Web Server or Hosting
a WordPress Blog.
Skip to the last step in this tutorial, Clean Up Your Instance and Volume (p. 32), to terminate the instance
so that you don't continue to incur charges.
Option 1: Connect Using Your Browser
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 the following pages: Install
Java and Enable Java in your web browser.
To connect to your Linux instance using a web browser
1. From the Amazon EC2 console, click Instances in the navigation pane.
2. Select the instance, and then click Connect.
3. Click A Java SSH client directly from my browser (Java required) .
4. Amazon EC2 automatically detects the public DNS name of your instance and populates Public
DNS for you. It also detects the key pair that you specified when you launched the instance. Complete
the following, and then click Launch SSH Client.
a. In User name, enter ec2-user.
Tip
For Amazon Linux, the default user name is ec2-user. For RHEL5, the user name is
often root but might be ec2-user. For Ubuntu, the user name is ubuntu. For SUSE
Linux, the user name is root. Otherwise, check with your AMI provider.
b. In Private key path, enter the fully qualified path to your private key (.pem) file.
c. Click Store in browser cache to store the location of the private key in your browser cache.
This enables Amazon EC2 to detect the location of the private key in subsequent browser
sessions, until you clear your browser's cache.
5. When prompted to add the host to your set of known hosts, click No.
6. If necessary, click Yes to trust the certificate.
7. Click Run to run the MindTerm client.
8. If you accept the license agreement, click Accept.
9. If this is your first time running MindTerm, a series of dialog boxes asks you to confirm setup for your
home directory and other settings. Confirm these settings. A window opens and you are connected
to your instance.
Option 2: Connect from Windows Using PuTTY
PuTTY doesn't use .pem files, it uses .ppk files. If you haven't already generated a .ppk file, do so now.
For more information, see To prepare to connect to a Linux instance from Windows using PuTTY.
To connect to your Linux instance using PuTTY
1. Start PuTTY (from the Start menu, click All Programs > PuTTY > PuTTY).
2. In the Category pane, select Session and complete the following fields:
a. In the Host Name box, enter ec2-user@public_dns_name.
API Version 2014-02-01
27
Amazon Elastic Compute Cloud User Guide
Option 1: Connect Using Your Browser
b. Under Connection type, select SSH.
c. Ensure that Port is 22.
3. In the Category pane, expand Connection, expand SSH, and then select Auth. Complete the
following:
a. Click Browse.
b. Select the .ppk file that you generated for your key pair, and then click Open.
c. Click Open to start the PuTTY session.
4. If this is the first time you have connected to this instance, PuTTY displays a security alert dialog
box that asks whether you trust the host you are connecting to. Click Yes. A window opens and you
are connected to your instance.
API Version 2014-02-01
28
Amazon Elastic Compute Cloud User Guide
Option 2: Connect from Windows Using PuTTY
Option 3: Connect from Mac or Linux Using an
SSH Client
Your Mac or Linux computer most likely includes an SSH client by default. You can check for an SSH
client by typing ssh at the command line. If your computer doesn't recognize the command, the OpenSSH
project provides a free implementation of the full suite of SSH tools. For more information, see
http://www.openssh.org.
Open your command shell and run the following command:
$ ssh -i /path/key_pair.pem ec2-user@public_dns_name
Tip
For Amazon Linux, the default user name is ec2-user. For RHEL5, the user name is often
root but might be ec2-user. For Ubuntu, the user name is ubuntu. For SUSE Linux, the user
name is root. Otherwise, check with your AMI provider.
Add a Volume to Your Instance
Now that you've launched and connected to your Linux instance, you can run the following command on
your instance to view its mounted volumes.
[ec2-user ~]$ 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 some room to install additional software on your instance. For example, you can use
the yum command to download and install packages.
If you need additional storage for your data, a simple solution is to add Amazon EBS volumes to your
instance. An Amazon EBS volume serves as network-attached storage for your instance. Let's add a
volume to the Linux instance that you've launched. First we'll use the EC2 console to create the volume
and attach it to the instance, and then we'll mount the volume to make it available.
To create and attach an Amazon EBS volume
1. Open the Amazon EC2 console at https://console.aws.amazon.com/ec2/.
2. In the navigation bar, select the region in which you created your instance, 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 Availability Zone for the instance.
3. In the navigation pane, under Elastic Block Store, click Snapshots. Select Public Snapshots from
the filter list. Select a snapshot from the list and note its snapshot ID. The Free Usage Tier provides
up to 30 GB of Amazon Elastic Block Storage; therefore, to avoid being charged for this tutorial,
choose a snapshot that is smaller than 30 GB.
API Version 2014-02-01
29
Amazon Elastic Compute Cloud User Guide
Option 3: Connect from Mac or Linux Using an SSH
Client
Note that this tutorial assumes that you create the volume using a snapshot as described in this step.
If you create an empty volume instead, we'll ask you to perform an additional step in the next
procedure.
4. Click Create Volume.
5. The Create Volume dialog box is preconfigured with the snapshot ID and volume size of the snapshot
you selected. Configure the following, and then click Create:
Select the Standard volume type to create a standard EBS volume.
Select the same Availability Zone that you used when you created your instance. Otherwise, you
can't attach the volume to your instance.
6. In the navigation pane, under Elastic Block Store, click Volumes. Notice that your newly created
volume appears there and the state of the volume is available, so it's ready to be attached to an
instance.
7. Right-click the newly created volume and select Attach Volume.
8. In the Attach Volume dialog box, configure the following, and then click Attach:
Start typing in the name or ID of your instance, then select it from the list of suggested options.
Specify an unused device name for that instance. We'll use /dev/sdf in this tutorial. If you select
a different device name, be sure to note it as you'll need this information in the next procedure.
You'll notice that in the Details pane for your volume, the state of the volume is in-use, and the volume
is attached to your instance with the device name /dev/sdf. However, if you return to your instance and
run the df -h command again, you won't see the volume yet. That's because we need to mount the volume
for df -h to see it. The lsblk command, however, can see all block devices attached to the instance.
Note
Some Linux distributions do not provide the lsblk command by default. If the lsblk command
does not work, you can use sudo fdisk -l | grep Disk instead.
[ec2-user ~]$ lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
xvdf 202:80 0 100G 0 disk
xvdf1 202:81 0 10G 0 part
xvda1 202:1 0 8G 0 disk /
In the above example, lsblk reports that there are two block devices attached to the instance; xvda1 is
mounted as the root file system (note the MOUNTPOINT value of /) and xvdf (which contains the disk
partition, xvdf1) is not mounted at all.
To make a volume available
1. Identify the device to mount. In the previous procedure, the new volume was attached to /dev/sdf.
Depending on the block device drivers on your instance's operating system, the device may appear
at a different location (such as /dev/xvdf in the previous example) than what you specified in the
console (/dev/sdf); in some cases, even the trailing letter may change (for example, /dev/xvdj).
Amazon Linux instances always create links from the device path that you specified in the console
to the new device path, but other distributions (such as Ubuntu or Red Hat) are not as predictable.
Use the lsblk command to list the available devices.
API Version 2014-02-01
30
Amazon Elastic Compute Cloud User Guide
Step 3: Add a Volume
Note
Some Linux distributions do not provide the lsblk command by default. If the lsblk command
does not work, you can use sudo fdisk -l | grep Disk instead.
[ec2-user ~]$ lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
xvdf 202:80 0 100G 0 disk
xvdf1 202:81 0 10G 0 part
xvda1 202:1 0 8G 0 disk /
The xvdf device is not mounted, and there is a 10 GB partition at xvdf1. Sometimes when you
create a volume from a snapshot, the data on the volume is contained in a partition such as this
instead of the root of the volume. In this case, you mount the /dev/xvdf1 partition (the lsblk
command output omits the /dev/ portion of the file path). If there was not a partition on xvdf, then
you would mount /dev/xvdf.
2. (Optional) If you created an empty volume instead of creating a volume from a snapshot in the
previous procedure, you need to format the volume using mkfs before you can mount it. Use the
following command to create an ext4 file system on the volume. Substitute the device name (such
as /dev/xvdf) for device_name.
Caution
This step assumes that you're mounting an empty volume. If you're mounting a volume that
already has data on it (for example, a volume that was restored from a snapshot), don't use
mkfs before mounting the volume (skip to the next step instead). Otherwise, you'll format
the volume and delete the existing data. For more information, see Making the Volume
Available on Linux.
Note
SUSE Linux Enterprise Server 11 does not fully support ext4 file systems. If you chose a
SLES 11 AMI for your instance, use ext3 in the following command instead.
[ec2-user ~]$ sudo mkfs -t ext4 device_name
3. To mount the device as /mnt/my-data, run the following commands.
[ec2-user ~]$ sudo mkdir /mnt/my-data
[ec2-user ~]$ sudo mount /dev/xvdf1 /mnt/my-data
Be sure to specify the device name you identified in Step 1 (p. 30); otherwise, you might receive the
following error when you run this mount command: "mount: you must specify the filesystem
type". If you see this error, repeat Step 1 (p. 30) and use the correct device path (remember to add
the /dev/ to the device name you get from the lsblk command).
4. Now when you run the df -h command, you'll see output like the following.
[ec2-user ~]$ df -h
Filesystem Size Used Avail Use% Mounted on
/dev/xvda1 7.9G 1.1G 6.8G 14% /
tmpfs 298M 0 298M 0% /dev/shm
/dev/xvdf1 10G 76M 10G 1% /mnt/my-data
5. To view the contents of the new volume, run the following command.
[ec2-user ~]$ ls /mnt/my-data
API Version 2014-02-01
31
Amazon Elastic Compute Cloud User Guide
Step 3: Add a Volume
At this point, you have completed the example architecture for this tutorial. You can continue to customize
and use your instance for as long as you wish.
Important
Remember, if you launched an instance in the Free Usage Tier, there are no charges. Otherwise,
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.
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, Clean Up Your Instance and Volume (p. 32).
Clean Up Your Instance and Volume
After you've finished with the instance and the Amazon EBS volume that you created for this tutorial, you
should clean up. First, terminate the instance, which detaches the volume from the instance, and then
delete the volume.
Terminating an instance effectively deletes it because you can't reconnect to an 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. For more information about the differences between
stopping and terminating an instance, see Stopping Instances.
To terminate the instance
1. Locate your instance in the list of instances on the Instances page. If you can't find your instance,
verify that you have selected the correct region.
2. Right-click the instance, and then click Terminate.
3. Click Yes, Terminate when prompted for confirmation.
EBS volumes can persist even after your instance is terminated. 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. Locate the volume that you created in the list of volumes on the Volumes page. If you can't find your
volume, verify that you have selected the correct region.
2. Right-click the volume, and then click Delete Volume.
3. Click Yes, Delete when prompted for confirmation.
Amazon EC2 begins deleting the volume.
API Version 2014-02-01
32
Amazon Elastic Compute Cloud User Guide
Step 4: Clean Up
Best Practices for Amazon EC2
This checklist is intended to help you get the maximum benefit from and satisfaction with Amazon EC2.
Manage access to AWS resources and APIs using identity federation, IAM users, and IAM roles.
Establish credential management policies and procedures for creating, distributing, rotating, and revoking
AWS access credentials. For more information, see IAM Best Practices in the Using IAM guide.
Launch your instances into a VPC instead of EC2-Classic. For more information about the benefits,
see Amazon EC2 and Amazon Virtual Private Cloud (VPC) (p. 485).
Implement the least permissive rules for your security group. For more information, see Security Group
Rules (p. 441).
Understand the implications of the root device type for data persistence, backup, and recovery. For
more information, see Storage for the Root Device (p. 50).
Use separate Amazon EBS volumes for the operating system versus data.
Design your applications to handle dynamic IP addressing when your instance restarts. For more
information, see Amazon EC2 Instance IP Addressing (p. 489).
Regularly patch, update, and secure the operating system and applications on your instance. For more
information about updating Amazon Linux, see Managing Software (p. 332). For more information about
updating Windows Server, go to Windows Server Update Services on the Microsoft website.
Regularly back up your instance using Amazon EBS snapshots (p. 559) or a backup tool.
Deploy critical components of your application across multiple Availability Zones, and replicate your
data appropriately.
Monitor and respond to events. For more information, see Monitoring Amazon EC2 (p. 353).
Ensure that you are prepared to handle failover. For a basic solution, you can manually attach a network
interface or Elastic IP address to a replacement instance. For more information, see Elastic Network
Interfaces (ENI) (p. 503). For an automated solution, you can use Auto Scaling. For more information,
see the Auto Scaling Developer Guide.
Regularly test the process of recovering your instances and Amazon EBS volumes if they fail.
Use instance metadata and custom resource tags to track and identify your AWS resources. For more
information, see Instance Metadata and User Data (p. 268) and Tagging Your Amazon EC2
Resources (p. 610).
API Version 2014-02-01
33
Amazon Elastic Compute Cloud User Guide
Tutorial: Installing a LAMP Web
Server
The following procedures help you install the Apache web server with PHP and MySQL support on your
Amazon EC2 instance (sometimes called a LAMP web server or LAMP stack). You can use this server
to host a static website or deploy a dynamic PHP application that reads and writes information to a
database.
Prerequisites
This tutorial assumes that you have already launched an instance with a public DNS name that is reachable
from the Internet. For more information, see Launch an Amazon EC2 Instance (p. 25). You must also
have configured your security group to allow SSH (port 22), HTTP (port 80), and HTTPS (port 443)
connections. For more information about these prerequisites, see Setting Up with Amazon EC2 (p. 19).
Important
These procedures are intended for use with Amazon Linux, but the commands and file locations
are similar for Red Hat and CentOS. For more information about other distributions, see their
specific documentation. If you are trying to set up a LAMP web server on an Ubuntu instance,
this tutorial will not work for you. For information about LAMP web servers on Ubuntu, go to
the Ubuntu community documentation ApacheMySQLPHP topic.
To install and start the LAMP web server
1. Connect to your instance (p. 26).
2. To ensure that all of your software packages are up to date, perform a quick software update on your
instance. This process may take a few minutes, but it is important to make sure you have the latest
security updates and bug fixes.
Note
The -y option installs the updates without asking for confirmation. If you would like to
examine the updates before installing, you can omit this option.
[ec2-user ~]$ sudo yum update -y
3. Now that your instance is current, you can install the Apache web server, MySQL, and PHP software
packages. Use the yum groupinstall command to install multiple software packages and all related
dependencies at the same time.
API Version 2014-02-01
34
Amazon Elastic Compute Cloud User Guide
[ec2-user ~]$ sudo yum groupinstall -y "Web Server" "MySQL Database" "PHP
Support"
Note
Non-Amazon Linux instances may have subtle differences in their group names. If the above
command fails because of an invalid group name, use the yum grouplist command and
scan the output for similar groups, such as "MySQL Database server" instead of "MySQL
Database", and use the appropriate group name for your distribution.
4. Install the php-mysql package.
[ec2-user ~]$ sudo yum install -y php-mysql
5. Start the Apache web server.
[ec2-user ~]$ sudo service httpd start
Starting httpd: [ OK ]
6. Use the chkconfig command to configure the Apache web server to start at each system boot.
[ec2-user ~]$ sudo chkconfig httpd on
Tip
The chkconfig command does not provide any confirmation message when you successfully
enable a service. You can verify that httpd is on by running the following command.
[ec2-user ~]$ chkconfig --list httpd
httpd 0:off 1:off 2:on 3:on 4:on 5:on 6:off
Here, httpd is on in runlevels 2, 3, 4, and 5 (which is what you want to see).
7. Test your web server. In a web browser, enter the public DNS address (or the public IP address) of
your instance; you should see the Apache test page. You can get the public DNS for your instance
using the Amazon EC2 console (check the Public DNS column; if this column is hidden, click the
Show/Hide icon and select Public DNS).
Tip
If you are unable to see the Apache test page, check that the security group you are using
contains a rule to allow HTTP (port 80) traffic. For information about adding an HTTP rule to
your security group, see Adding Rules to a Security Group (p. 445).
Important
If you are not using Amazon Linux, you may also need to configure the firewall on your
instance to allow these connections. For more information about how to configure the firewall,
see the documentation for your specific distribution.
API Version 2014-02-01
35
Amazon Elastic Compute Cloud User Guide
Note
This test page appears only when there is no content in /var/www/html. When you add
content to the document root, your content appears at the public DNS address of your
instance instead of this test page.
Apache httpd serves files that are kept in a directory called the Apache document root. The Amazon
Linux Apache document root is /var/www/html, which is owned by root by default.
[ec2-user ~]$ ls -l /var/www
total 16
drwxr-xr-x 2 root root 4096 Jul 12 01:00 cgi-bin
drwxr-xr-x 3 root root 4096 Aug 7 00:02 error
drwxr-xr-x 2 root root 4096 Jan 6 2012 html
drwxr-xr-x 3 root root 4096 Aug 7 00:02 icons
To allow ec2-user to manipulate files in this directory, you need to modify the ownership and permissions
of the directory. There are many ways to accomplish this task; in this tutorial, you add a www group to
your instance, and you give that group ownership of the /var/www directory and add write permissions
for the group. Any members of that group will then be able to add, delete, and modify files for the web
server.
To set file permissions
1. Add the www group to your instance.
[ec2-user ~]$ sudo groupadd www
2. Add your user (in this case, ec2-user) to the www group.
[ec2-user ~]$ sudo usermod -a -G www ec2-user
API Version 2014-02-01
36
Amazon Elastic Compute Cloud User Guide
Important
You need to log out and log back in to pick up the new group.You can use the exit command,
or close the terminal window.
3. Log out and then log back in again, and verify your membership in the www group.
a. Log out.
[ec2-user ~]$ exit
b. Reconnect to your instance, and then run the following command to verify your membership in
the www group.
[ec2-user ~]$ groups
ec2-user wheel www
4. Change the group ownership of /var/www and its contents to the www group.
[ec2-user ~]$ sudo chown -R root:www /var/www
5. Change the directory permissions of /var/www and its subdirectories to add group write permissions
and to set the group ID on future subdirectories.
[ec2-user ~]$ sudo chmod 2775 /var/www
[ec2-user ~]$ find /var/www -type d -exec sudo chmod 2775 {} +
6. Recursively change the file permissions of /var/www and its subdirectories to add group write
permissions.
[ec2-user ~]$ find /var/www -type f -exec sudo chmod 0664 {} +
Now ec2_user (and any future members of the www group) can add, delete, and edit files in the Apache
document root. Now you are ready to add content, such as a static website or a PHP application.
To test your LAMP web server
If your server is installed and running, and your file permissions are set correctly, your ec2-user account
should be able to create a simple PHP file in the /var/www/html directory that will be available from
the Internet.
1. Create a simple PHP file in the Apache document root.
[ec2-user ~]$ echo "<?php phpinfo(); ?>" > /var/www/html/phpinfo.php
Tip
If you get a "Permission denied" error when trying to run this command, try logging out
and logging back in again to pick up the proper group permissions that you configured in
To set file permissions (p. 36).
API Version 2014-02-01
37
Amazon Elastic Compute Cloud User Guide
2. In a web browser, enter the URL of the file you just created. This URL is the public DNS address of
your instance followed by a forward slash and the file name. For example:
http://my.public.dns.amazonaws.com/phpinfo.php
You should see the PHP information page.
3. Delete the phpinfo.php file. Although this can be useful information to you, it should not be broadcast
to the Internet for security reasons.
[ec2-user ~]$ rm /var/www/html/phpinfo.php
To secure the MySQL server
The default installation of the MySQL server has several features that are great for testing and development,
but they should be disabled or removed for production servers. The mysql_secure_installation command
walks you through the process of setting a root password and removing the insecure features from your
installation. Even if you are not planning on using the MySQL server, performing this procedure is a good
idea.
1. Start the MySQL server so that you can run mysql_secure_installation.
[ec2-user ~]$ sudo service mysqld start
Initializing MySQL database: Installing MySQL system tables...
OK
Filling help tables...
OK
To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system
PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
...
Starting mysqld: [ OK ]
API Version 2014-02-01
38
Amazon Elastic Compute Cloud User Guide
2. Run mysql_secure_installation.
[ec2-user ~]$ sudo mysql_secure_installation
a. When prompted, enter a password for the root account.
i. Enter the current root password. By default, the root account does not have a password
set, so press Enter.
ii. Type Y to set a password, and enter a secure password twice. For more information about
creating a secure password, go to http://www.pctools.com/guides/password/. Make sure to
store this password in a safe place.
b. Type Y to remove the anonymous user accounts.
c. Type Y to disable remote root login.
d. Type Y to remove the test database.
e. Type Y to reload the privilege tables and save your changes.
3. (Optional) Stop the MySQL server if you do not plan to use it right away. You can restart the server
when you need it again.
[ec2-user ~]$ sudo service mysqld stop
Stopping mysqld: [ OK ]
4. (Optional) If you want the MySQL server to start at every boot, enter the following command.
[ec2-user ~]$ sudo chkconfig mysqld on
You should now have a fully functional LAMP web server. If you add content to the Apache document
root at /var/www/html, you should be able to view that content at the public DNS address for your
instance.
Related Topics
For more information on transferring files to your instance or installing a WordPress blog on your web
server, see the following topics:
Transferring Files to Your Instance with WinSCP (p. 315)
Transferring Files to Linux/Unix Instances from Linux/Unix with SCP (p. 310)
Tutorial: Hosting a WordPress Blog with Amazon EC2 (p. 40)
For more information about the Apache web server, go to http://httpd.apache.org/. For more information
about the MySQL database server, go to http://www.mysql.com/. For more information about the PHP
programming language, go to http://php.net/.
API Version 2014-02-01
39
Amazon Elastic Compute Cloud User Guide
Tutorial: Hosting a WordPress Blog
with Amazon EC2
The following procedures will help you install, configure, and secure a WordPress blog on your Amazon
EC2 instance.
Important
These procedures are intended for use with Amazon Linux, but the commands and file locations
are similar for Red Hat and CentOS. For more information about other distributions, see their
specific documentation.
This tutorial is a good introduction to using Amazon EC2 in that you have full control over a web server
that hosts your WordPress blog, which is not typical with a traditional hosting service. Of course, that
means that you are responsible for updating the software packages and maintaining security patches for
your server as well. For a more automated WordPress installation that does not require direct interaction
with the web server configuration, the AWS CloudFormation service provides a WordPress template that
can also get you started quickly. For more information, see Get Started in the AWS CloudFormation User
Guide. If you'd prefer to host your WordPress blog on a Windows instance, see Deploying a WordPress
Blog on Your Amazon EC2 Windows Instance in the Amazon Elastic Compute Cloud Microsoft Windows
Guide.
Prerequisites
This tutorial assumes that you have launched an instance with a functional web server with PHP and
MySQL support. Your Amazon EC2 security group should also allow HTTP and HTTPS traffic. If you do
not already have a functional web server, see Tutorial: Installing a LAMP Web Server (p. 34) to create
one and then return to this tutorial to install WordPress. For information about adding rules to your security
group, see Adding Rules to a Security Group (p. 445).
To download and unzip the WordPress installation package
1. Download the latest WordPress installation package with the wget command. The following command
should always download the latest release.
[ec2-user ~]$ wget https://wordpress.org/latest.tar.gz
--2013-08-09 17:19:01-- https://wordpress.org/latest.tar.gz
Resolving wordpress.org (wordpress.org)... 66.155.40.249, 66.155.40.250
Connecting to wordpress.org (wordpress.org)|66.155.40.249|:443... connected.
HTTP request sent, awaiting response... 200 OK
API Version 2014-02-01
40
Amazon Elastic Compute Cloud User Guide
Length: 4028740 (3.8M) [application/x-gzip]
Saving to: latest.tar.gz
100%[======================================>] 4,028,740 20.1MB/s in 0.2s
2013-08-09 17:19:02 (20.1 MB/s) - latest.tar.gz saved [4028740/4028740]
2. Unzip and unarchive the installation package. The installation folder is unzipped to a folder called
wordpress.
[ec2-user ~]$ tar -xzf latest.tar.gz
[ec2-user ~]$ ls
latest.tar.gz wordpress
To create a MySQL user and database for your WordPress installation
Your WordPress installation needs to store information, such as blog post entries and user comments,
in a database. This procedure will help you create a database for your blog and a user that is authorized
to read and save information to that database.
1. Start the MySQL server.
[ec2-user ~]$ sudo service mysqld start
2. Log in to the MySQL server as the root user. Enter your MySQL root password when prompted;
this may be different than your root system password, or it may even be empty if you have not
secured your MySQL server.
Important
If you have not secured your MySQL server yet, it is very important that you do so. For more
information, see To secure the MySQL server (p. 38).
[ec2-user ~]$ mysql -u root -p
Enter password:
3. Create a user and password for your MySQL database. Your WordPress installation uses these
values to communicate with your MySQL database. Enter the following command, substituting a
unique user name and password.
mysql> CREATE USER 'wordpress-user'@'localhost' IDENTIFIED BY
'your_strong_password';
Query OK, 0 rows affected (0.00 sec)
Make sure that you create a strong password for your user. Do not use the single quote character (
' ) in your password, because this will break the preceding command. For more information about
creating a secure password, go to http://www.pctools.com/guides/password/. Do not reuse an existing
password, and make sure to store this password in a safe place.
4. Create your database. Give your database a descriptive, meaningful name, such as wordpress-db.
Note
The punctuation marks surrounding the database name in the command below are called
backticks. The backtick (`) key is usually located above the Tab key on a standard keyboard.
API Version 2014-02-01
41
Amazon Elastic Compute Cloud User Guide
Backticks are not always required, but they allow you to use otherwise illegal characters,
such as hyphens, in database names.
mysql> CREATE DATABASE `wordpress-db`;
Query OK, 1 row affected (0.01 sec)
5. Grant full privileges for your database to the WordPress user you created earlier.
mysql> GRANT ALL PRIVILEGES ON `wordpress-db`.* TO "wordpress-user"@"local
host";
Query OK, 0 rows affected (0.00 sec)
6. Flush the MySQL privileges to pick up all of your changes.
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.01 sec)
7. Exit the mysql client.
mysql> exit
Bye
To create and edit the wp-config.php file
The WordPress installation folder contains a sample configuration file called wp-config-sample.php.
In this procedure, you copy this file and edit it to fit your specific configuration.
1. Copy the wp-config-sample.php file to a file called wp-config.php. This creates a new
configuration file and keeps the original sample file intact as a backup.
[ec2-user ~]$ cd wordpress/
[ec2-user wordpress]$ cp wp-config-sample.php wp-config.php
2. Edit the wp-config.php file with your favorite text editor (such as nano or vim) and enter values
for your installation. If you do not have a favorite text editor, nano is much easier for beginners to
use.
[ec2-user wordpress]$ nano wp-config.php
a. Find the line that defines DB_NAME and change database_name_here to the database name
you created in Step 4 (p. 41) of To create a MySQL user and database for your WordPress
installation (p. 41).
define('DB_NAME', 'wordpress-db');
b. Find the line that defines DB_USER and change username_here to the database user you
created in Step 3 (p. 41) of To create a MySQL user and database for your WordPress
installation (p. 41).
API Version 2014-02-01
42
Amazon Elastic Compute Cloud User Guide
define('DB_USER', 'wordpress-user');
c. Find the line that defines DB_PASSWORD and change password_here to the strong password
you created in Step 3 (p. 41) of To create a MySQL user and database for your WordPress
installation (p. 41).
define('DB_PASSWORD', 'your_strong_password');
d. Find the section called Authentication Unique Keys and Salts. These KEY and SALT
values provide a layer of encryption to the browser cookies that WordPress users store on their
local machines. Basically, adding long, random values here makes your site more secure. Visit
https://api.wordpress.org/secret-key/1.1/salt/ to randomly generate a set of key values that you
can copy and paste into your wp-config.php file. To paste text into a PuTTY terminal, place
the cursor where you want to paste the text and right-click your mouse inside the PuTTY terminal.
For more information about security keys, go to
http://codex.wordpress.org/Editing_wp-config.php#Security_Keys.
Note
The values below are for example purposes only; do not use these values for your
installation.
define('AUTH_KEY', ' #U$$+[RXN8:b^-L 0(WU_+ c+WFkI~c]o]-
bHw+)/Aj[wTwSiZ<Qb[mghEXcRh-');
define('SECURE_AUTH_KEY', 'Zsz._P=l/|y.Lq)XjlkwS1y5NJ76E6EJ.AV0pCK
ZZB,*~*r ?6OP$eJT@;+(ndLg');
define('LOGGED_IN_KEY', 'ju}qwre3V*+8f_zOWf?{LlGsQ]Ye@2Jh^,8x>)Y
|;(^[Iw]Pi+LG#A4R?7N`YB3');
define('NONCE_KEY',
'P(g62HeZxEes|LnI^i=H,[XwK9I&[2s|:?0N}VJM%?;v2v]v+;+^9eXUahg@::Cj');
define('AUTH_SALT',
'C$DpB4Hj[JK:?{ql`sRVa:{:7yShy(9A@5wg+`JJVb1fk%_-Bx*M4(qc[Qg%JT!h');
define('SECURE_AUTH_SALT',
'd!uRu#}+q#{f$Z?Z9uFPG.${+S{n~1M&%@~gL>U>NV<zpD-@2-Es7Q1O-bp28EKv');
define('LOGGED_IN_SALT', ';j{00P*owZf)kVD+FVLn-~
>.|Y%Ug4#I^*LVd9QeZ^&XmK|e(76miC+&W&+^0P/');
define('NONCE_SALT',
'-97r*V/cgxLmp?Zy4zUU4r99QQ_rGs2LTd%P;|_e1tS)8_B/,.6[=UK<J_y9?JWG');
e. Save the file and exit your text editor.
To move your WordPress installation to the Apache document root
Now that you've unzipped the installation folder, created a MySQL database and user, and customized
the WordPress configuration file, you are ready to move your installation files to your web server document
root so you can run the installation script that completes your installation. The location of these files
depends on whether you want your WordPress blog to be available at the root of your web server (for
example, my.public.dns.amazonaws.com) or in a subdirectory or folder (for example,
my.public.dns.amazonaws.com/blog).
API Version 2014-02-01
43
Amazon Elastic Compute Cloud User Guide
Important
Choose the location where you want your blog to be available and only run the mv associated
with that location. If you run both sets of commands below, you will get an error message on the
second mv command because the files you are trying to move are no longer there.
1. To make your blog available at my.public.dns.amazonaws.com, move the files in the wordpress
folder (but not the folder itself) to the Apache document root (/var/www/html on Amazon Linux
instances).
[ec2-user wordpress]$ mv * /var/www/html/
2. OR, to make your blog available at my.public.dns.amazonaws.com/blog instead, create a new
folder called blog inside the Apache document root and move the files in the wordpress folder (but
not the folder itself) to the new blog folder.
[ec2-user wordpress]$ mkdir /var/www/html/blog
[ec2-user wordpress]$ mv * /var/www/html/blog
Important
If you are not moving on to the next procedure immediately, stop the Apache web server (httpd)
now for security purposes. After you move your installation to the Apache document root, the
WordPress installation script is unprotected and an attacker could gain access to your blog if
the Apache web server were running. To stop the Apache web server, enter the command sudo
service httpd stop. If you are moving on to the next procedure, you do not need to stop the
Apache web server.
To fix file permissions for the Apache web server
Some of the available features in WordPress require write access to the Apache document root (such as
uploading media though the Administration screens). The web server runs as the apache user, so you
need to add that user to the www group that was created in the LAMP web server tutorial (p. 34).
1. Add the apache user to the www group.
[ec2-user wordpress]$ sudo usermod -a -G www apache
2. Change the group ownership of /var/www and its contents to the www group.
[ec2-user wordpress]$ sudo chgrp -R www /var/www
3. Change the directory permissions of /var/www and its subdirectories to add group write permissions
and to set the group ID on future subdirectories.
[ec2-user wordpress]$ sudo chmod 2775 /var/www
[ec2-user wordpress]$ find /var/www -type d -exec sudo chmod 2775 {} +
4. Recursively change the file permissions of /var/www and its subdirectories to add group write
permissions.
[ec2-user wordpress]$ find /var/www -type f -exec sudo chmod 0664 {} +
API Version 2014-02-01
44
Amazon Elastic Compute Cloud User Guide
5. Restart the Apache web server to pick up the new group and permissions.
[ec2-user wordpress]$ sudo service httpd restart
Stopping httpd: [ OK ]
Starting httpd: [ OK ]
To run the WordPress installation script
1. Use the chkconfig command to ensure that the httpd and mysqld services start at every system
boot.
[ec2-user wordpress]$ sudo chkconfig httpd on
[ec2-user wordpress]$ sudo chkconfig mysqld on
2. Verify that the MySQL server (mysqld) is running.
[ec2-user wordpress]$ sudo service mysqld status
mysqld (pid 4746) is running...
If the mysqld service is not running, start it.
[ec2-user wordpress]$ sudo service mysqld start
Starting mysqld: [ OK ]
3. Verify that your Apache web server (httpd) is running.
[ec2-user wordpress]$ sudo service httpd status
httpd (pid 502) is running...
If the httpd service is not running, start it.
[ec2-user wordpress]$ sudo service httpd start
Starting httpd: [ OK ]
4. Verify that the php and php-mysql packages are installed. Your output may look slightly different,
but look for the Installed Packages section.
[ec2-user wordpress]$ yum list installed php php-mysql
Loaded plugins: priorities, security, update-motd, upgrade-helper
amzn-main | 2.1 kB 00:00
amzn-updates | 2.3 kB 00:00
Installed Packages
php.x86_64 5.3.27-1.0.amzn1 @amzn-
updates
php-mysql.x86_64 5.3.27-1.0.amzn1 @amzn-
updates
Note
If either of these packages are not listed as installed, install them with the following command
and then restart the httpd service.
API Version 2014-02-01
45
Amazon Elastic Compute Cloud User Guide
[ec2-user wordpress]$ sudo yum install -y php php-mysql
[ec2-user wordpress]$ sudo service httpd restart
5. In a web browser, enter the URL of your WordPress blog (either the public DNS address for your
instance, or that address followed by the blog folder). You should see the WordPress installation
screen.
http://my.public.dns.amazonaws.com
6. Enter the remaining installation information into the WordPress installation wizard.
Value Field
Enter a name for your WordPress site. Site Title
Enter a name for your WordPress administrator.
For security purposes you should choose a
unique name for this user, since this will be more
difficult to exploit than the default user name,
admin.
Username
Enter a strong password, and then enter it again
to confirm. Do not reuse an existing password,
and make sure to store this password in a safe
place.
Password
Enter the email address you want to use for
notifications.
Your E-mail
7. Click Install WordPress to complete the installation.
API Version 2014-02-01
46
Amazon Elastic Compute Cloud User Guide
Congratulations, you should now be able to log into your WordPress blog and start posting entries.
If your WordPress blog becomes popular and you need more compute power, you might consider migrating
to a larger instance type; for more information, see Resizing Your Instance (p. 118). If your blog requires
more storage space than you originally accounted for, you could expand the storage space on your
instance; for more information, see Expanding the Storage Space of a Volume (p. 548). If your MySQL
database needs to grow, you could consider moving it to Amazon RDS to take advantage of the service's
autoscaling abilities.
For information about WordPress, see the WordPress Codex help documentation at
http://codex.wordpress.org/. For more information about troubleshooting your installation, go to
http://codex.wordpress.org/Installing_WordPress#Common_Installation_Problems. For information about
making your WordPress blog more secure, go to http://codex.wordpress.org/Hardening_WordPress. For
information about keeping your WordPress blog up-to-date, go to
http://codex.wordpress.org/Updating_WordPress.
API Version 2014-02-01
47
Amazon Elastic Compute Cloud User Guide
Amazon Machine Images (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.
An AMI includes the following:
A template for the root volume for the instance (for example, an operating system, an application server,
and applications)
Launch permissions that control which AWS accounts can use the AMI to launch instances
A block device mapping that specifies the volumes to attach to the instance when it's launched
Using an AMI
The following diagram summarizes the AMI lifecycle. After you create and register an AMI, you can use
it to launch new instances. (You can also launch instances from an AMI if the AMI owner grants you
launch permissions.) You can copy an AMI to the same region or to different regions. When you are
finished launching instance from an AMI, you can deregister the AMI.
You can search for an AMI that meets the criteria for your instance. You can search for AMIs provided
by AWS or AMIs provided by the community. For more information, see AMI Types (p. 50) and Finding
a Suitable AMI (p. 53).
When you are connected to an instance, you can use it just like you use any other server. For information
about launching, connecting, and using your instance, see Amazon EC2 Instances (p. 97).
API Version 2014-02-01
48
Amazon Elastic Compute Cloud User Guide
Using an AMI
Creating Your Own AMI
You can customize the instance that you launch from a public AMI and then save that configuration as a
custom AMI for your own use. Instances that you launch from your AMI use all the customizations that
you've made.
The root storage device of the instance determines the process you follow to create an AMI. The root
volume of an instance is either an Amazon EBS volume or an instance store volume. For information,
see Amazon EC2 Root Device Volume (p. 13).
To create an Amazon EBS-backed AMI, see Creating an Amazon EBS-Backed Linux AMI (p. 69). To
create an instance store-backed AMI, see Creating an Instance Store-Backed Linux AMI (p. 72).
To help categorize and manage your AMIs, you can assign custom tags to them. For more information,
see Tagging Your Amazon EC2 Resources (p. 610).
Buying, Sharing, and Selling AMIs
After you create an AMI, you can keep it private so that only you can use it, or you can share it with a
specified list of AWS accounts. You can also make your custom AMI public so that the community can
use it. Building a safe, secure, usable AMI for public consumption is a fairly straightforward process, if
you follow a few simple guidelines. For information about how to create and use shared AMIs, see Shared
AMIs (p. 54).
You can purchase an AMIs from a third party, including AMIs that come with service contracts from
organizations such as Red Hat. You can also create an AMI and sell it to other Amazon EC2 users. For
more information about buying or selling AMIs, see Paid AMIs (p. 64).
Deregistering Your AMI
You can deregister an AMI when you have finished with it. After you deregister an AMI, you can't use it
to launch new instances. For more information, see Deregistering Your AMI (p. 83).
Amazon Linux
The Amazon Linux AMI is a supported and maintained Linux image provided by AWS. The following are
some of the features of Amazon Linux:
A stable, secure, and high-performance execution environment for applications running on Amazon
EC2.
Provided at no additional charge to Amazon EC2 users.
An Amazon EBS-backed, PV-GRUB AMI that includes Linux 3.4, AWS tools, and repository access to
multiple versions of MySQL, PostgreSQL, Python, Ruby, and Tomcat.
Updated on a regular basis to include the latest components, and these updates are also made available
in the yum repositories for installation on running instances.
Includes packages that enable easy integration with AWS services, such as the Amazon EC2 API and
AMI tools, the Boto library for Python, and the Elastic Load Balancing tools.
For more information, see Amazon Linux (p. 84).
API Version 2014-02-01
49
Amazon Elastic Compute Cloud User Guide
Creating Your Own AMI
AMI Types
You can select an AMI to use based on the following characteristics:
Region (see Regions and Availability Zones (p. 7))
Operating system
Architecture (32-bit or 64-bit)
Launch Permissions (p. 50)
Storage for the Root Device (p. 50)
Launch Permissions
The owner of an AMI determines its availability by specifying launch permissions. Launch permissions
fall into the following categories.
Description Launch
Permission
The owner grants launch permissions to all AWS accounts. public
The owner grants launch permissions to specific AWS accounts. explicit
The owner has implicit launch permissions for an AMI. implicit
Amazon and the Amazon EC2 community provide a large selection of public AMIs. For more information,
see Shared AMIs (p. 54). Developers can charge for their AMIs. For more information, see Paid
AMIs (p. 64).
Storage for the Root Device
All AMIs are categorized as either backed by Amazon EBS or backed by instance store. The former
means that the root device for an instance launched from the AMI is an Amazon EBS volume created
from an Amazon EBS snapshot. The latter means that the root device for an instance launched from the
AMI is an instance store volume created from a template stored in Amazon S3. For more information,
see Amazon EC2 Root Device Volume (p. 13).
This section summarizes the important differences between the two types of AMIs. The following table
provides a quick summary of these differences.
Amazon Instance Store-Backed Amazon EBS-Backed Characteristic
Usually less than 5 minutes Usually less than 1 minute Boot time
10 GiB 1 TiB Size limit
Instance store volume Amazon EBS volume Root device volume
Data on instance store volumes
persists only during the life of the
instance; you can also attach Amazon
EBS volumes that persist after
instance termination.
Data on Amazon EBS volumes
persists after instance termination*;
you can also attach instance store
volumes that don't persist after
instance termination.
Data persistence
API Version 2014-02-01
50
Amazon Elastic Compute Cloud User Guide
AMI Types
Amazon Instance Store-Backed Amazon EBS-Backed Characteristic
Instance attributes are fixed for the life
of an instance.
The instance type, kernel, RAM disk,
and user data can be changed while
the instance is stopped.
Upgrading
You're charged for instance usage and
storing your AMI in Amazon S3.
You're charged for instance usage,
Amazon EBS volume usage, and
storing your AMI as an Amazon EBS
snapshot.
Charges
Requires installation and use of AMI
tools
Uses a single command/call AMI creation/bundling
Cannot be in stopped state; instances
are running or terminated
Can be placed in stopped state where
instance is not running, but the root
volume is persisted in Amazon EBS
Stopped state
* By default, Amazon EBS-backed instance root volumes have the DeleteOnTermination flag set to
true, which causes the volume to be deleted upon instance termination. For information about how to
change this so that the volume persists following termination, see Changing the Root Device Volume to
Persist (p. 16).
Determining the Root Device Type of Your AMI
To determine the root device type of an AMI using the console
1. Open the Amazon EC2 console.
2. In the navigation pane, click AMIs, and select the AMI.
3. Check the value of Root Device Type in the Details tab as follows:
If the value is ebs, this is an Amazon EBS-backed AMI.
If the value is instance store, this is an instance store-backed AMI.
To determine the root device type of an AMI using the command line
You can use one of the following commands. For more information about these command line interfaces,
see Accessing Amazon EC2 (p. 3).
describe-images (AWS CLI)
ec2-describe-images (Amazon EC2 CLI)
Get-EC2Image (AWS Tools for Windows PowerShell)
Size Limit
Amazon EC2 instance store-backed AMIs are limited to 10 GiB storage for the root device, whereas
Amazon EBS-backed AMIs are limited to 1 TiB. Many Windows AMIs come close to the 10 GiB limit, so
you'll find that Windows AMIs are often backed by an Amazon EBS volume.
Note
All Windows Server 2008, Windows Server 2008 R2, and Windows Server 2012 AMIs are backed
by an Amazon EBS volume by default because of their larger size.
API Version 2014-02-01
51
Amazon Elastic Compute Cloud User Guide
Storage for the Root Device
Stopped State
You can stop an Amazon EBS-backed instance, but not an Amazon EC2 instance store-backed instance.
Stopping causes the instance to stop running (its status goes from running to stopping to stopped).
A stopped instance persists in Amazon EBS, which allows it to be restarted. Stopping is different from
terminating; you can't restart a terminated instance. Because Amazon EC2 instance store-backed AMIs
can't be stopped, they're either running or terminated. For more information about what happens and
what you can do while an instance is stopped, see Stop and Start Your Instance (p. 319).
Default Data Storage and Persistence
Instances that use an instance store volume for the root device automatically have instance store available
(the root volume contains the root partition and you can store additional data). Any data on an instance
store volume is deleted when the instance fails or terminates (except for data on the root device). You
can add persistent storage to your instance by attaching one or more Amazon EBS volumes.
Instances that use Amazon EBS for the root device automatically have an Amazon EBS volume attached.
The volume appears in your list of volumes like any other. The instances don't use any available instance
store volumes by default. You can add instance storage or additional Amazon EBS volumes using a block
device mapping. For more information, see Block Device Mapping (p. 592). For information about what
happens to the instance store volumes when you stop an instance, see Stop and Start Your
Instance (p. 319).
Boot Times
Amazon EBS-backed AMIs launch faster than Amazon EC2 instance store-backed AMIs. When you
launch an Amazon EC2 instance store-backed AMI, all the parts have to be retrieved from Amazon S3
before the instance is available. With an Amazon EBS-backed AMI, only the parts required to boot the
instance need to be retrieved from the snapshot before the instance is available. However, the performance
of an instance that uses an Amazon EBS volume for its root device is slower for a short time while the
remaining parts are retrieved from the snapshot and loaded into the volume. When you stop and restart
the instance, it launches quickly, because the state is stored in an Amazon EBS volume.
AMI Creation
To create Linux/Unix AMIs backed by instance store, you must create an AMI from your instance on the
instance itself, but there aren't any API actions to help you. To create a Windows AMI backed by instance
store, there's an API action that creates an AMI and another API action that registers the AMI.
AMI creation is much easier for AMIs backed by Amazon EBS. The CreateImage API action creates
the AMI on both Linux/Unix and Windows. This API action creates your Amazon EBS-backed AMI and
registers it. There's also a button in the AWS Management Console that lets you create an AMI from a
running instance. For more information, see Creating an Amazon EBS-Backed Linux AMI (p. 69).
How You're Charged
With AMIs backed by instance store, you're charged for AMI storage and instance usage. With AMIs
backed by Amazon EBS, you're charged for volume storage and usage in addition to the AMI and instance
usage charges.
With Amazon EC2 instance store-backed AMIs, each time you customize an AMI and create a new one,
all of the parts are stored in Amazon S3 for each AMI. So, the storage footprint for each customized AMI
is the full size of the AMI. For Amazon EBS-backed AMIs, each time you customize an AMI and create
a new one, only the changes are stored. So the storage footprint for subsequent AMIs you customize
after the first is much smaller, resulting in lower AMI storage charges.
API Version 2014-02-01
52
Amazon Elastic Compute Cloud User Guide
Storage for the Root Device
When an Amazon EBS-backed instance is stopped, you're not charged for instance usage; however,
you're still charged for volume storage. We charge a full instance hour for every transition from a stopped
state to a running state, even if you transition the instance multiple times within a single hour. For example,
let's say the hourly instance charge for your instance is $0.10. If you were to run that instance for one
hour without stopping it, you would be charged $0.10. If you stopped and restarted that instance twice
during that hour, you would be charged $0.30 for that hour of usage (the initial $0.10, plus 2 x $0.10 for
each restart).
Finding a Suitable AMI
Before you select an AMI, consider the following requirements you might have for the instances that you'll
launch:
The region
The operating system
The architecture: 32-bit (i386) or 64-bit (x86_64)
The root device type: Amazon EBS or instance store
The provider: Amazon Web Services, Oracle, IBM, Microsoft, or the community
Finding an AMI Using the Amazon EC2 Console
To find a suitable AMI using the console
1. Open the Amazon EC2 console.
2. From the navigation bar, select a region. You can select any region that's available to you, regardless
of your location. This is the region in which you'll launch your instance.
3. In the navigation pane, click AMIs.
4. (Optional) Use the Filter options to scope the list of displayed AMIs to the AMIs that interest you.
For example, to list all AMIs provided by AWS, select Public images and then Amazon images.
5. (Optional) Click the Show/Hide Columns icon to select which image attributes to display, such as
the root device type. Alternatively, you can select an AMI from the list and view its properties in the
Details tab.
6. Before you select an AMI, it's important that you check whether it's backed by instance store or by
Amazon EBS and that you are aware of the effects of this difference. For more information, see
Storage for the Root Device (p. 50).
7. To launch an instance from this AMI, select it and then click Launch. For more information, see
Launch Your Instance (p. 300). If you're not ready to launch the instance now, write down the AMI ID
(ami-xxxxxxxx) for later.
Finding an AMI Using the Command Line
You can use one of the following commands to find your AMIs and Amazon's public AMIs.
describe-images (AWS CLI)
aws ec2 describe-images --owners self amazon
ec2-describe-images (Amazon EC2 CLI)
API Version 2014-02-01
53
Amazon Elastic Compute Cloud User Guide
Finding a Suitable AMI
ec2-describe-images -o self -o amazon
To reduce the number of displayed AMIs, use a filter to list only the types of AMIs that interest you. For
example, add the following filters to display only Windows AMIs backed by Amazon EBS:
describe-images (AWS CLI)
--filters "Name=platform,Values=Windows,Name=root-device-type,Values=ebs"
ec2-describe-images (Amazon EC2 CLI)
--filter "platform=windows" --filter "root-device-type=ebs"
After locating an AMI that meets your needs, write down its ID (ami-xxxxxxxx). You can use this AMI to
launch an instances. For more information, see Launching an Instance Using the AWS CLI in the AWS
Command Line Interface User Guide or Launching an Instance Using the Amazon EC2 CLI in the Amazon
Elastic Compute Cloud Command Line Reference.
Shared AMIs
A shared AMI is an AMI that a developer created and made available for other developers to use. One
of the easiest ways to get started with Amazon EC2 is to use a shared AMI that has the components you
need and then add custom content.
You use a shared AMI at your own risk. Amazon can't vouch for the integrity or security of AMIs shared
by other Amazon EC2 users. Therefore, you should treat shared AMIs as you would any foreign code
that you might consider deploying in your own data center and perform the appropriate due diligence.
We recommend that you get an AMI from a trusted source. If you have questions or observations about
a shared AMI, use the AWS forums.
Amazon's public images have an aliased owner, which appears as amazon in the account field. This
enables you to find AMIs from Amazon easily. Other users can't alias their AMIs.
Topics
Finding Shared AMIs (p. 54)
Making an AMI Public (p. 57)
Sharing an AMI with Specific AWS Accounts (p. 59)
Using Bookmarks (p. 60)
Guidelines for Shared Linux AMIs (p. 61)
Finding Shared AMIs
You can use the Amazon EC2 console or the Amazon EC2 CLI to find shared AMIs.
API Version 2014-02-01
54
Amazon Elastic Compute Cloud User Guide
Shared AMIs
Finding a Shared AMI Using the Console
To find a shared private AMI using the console
1. Open the Amazon EC2 console.
2. In the navigation pane, click AMIs.
3. In the first filter, select Private images. All AMIs that have been shared with you are listed.
To find a shared public AMI using the console
1. Open the Amazon EC2 console.
2. In the navigation pane, click AMIs.
3. To find shared AMIs, select Public images from the Filter list.
4. Use filters to list only the types of AMIs that interest you. For example, select Amazon images to
display only Amazon's public images.
Finding a Shared AMI Using the AWS CLI
To find a shared public AMI using the command line tools
Use the describe-images command to list AMIs. You can scope the list to the types of AMIs that interest
you, as shown in the following examples.
The following command lists all public AMIs using the --executable-users option. This list includes
any public AMIs that you own.
aws ec2 describe-images --executable-users all
The following command lists the AMIs for which you have explicit launch permissions. This list excludes
any such AMIs that you own.
aws ec2 describe-images -executable-users self
The following command lists the AMIs owned by Amazon. Amazon's public AMIs have an aliased owner,
which appears as amazon in the account field. This enables you to find AMIs from Amazon easily. Other
users can't alias their AMIs.
aws ec2 describe-images --owners amazon
The following command lists the AMIs owned by the specified AWS account.
aws ec2 describe-images --owners 123456789012
To reduce the number of displayed AMIs, use a filter to list only the types of AMIs that interest you. For
example, use the following filter to display only Windows-based AMIs.
--filters "Name=platform,Values=windows"
API Version 2014-02-01
55
Amazon Elastic Compute Cloud User Guide
Finding Shared AMIs
Finding a Shared AMI Using the Amazon EC2 CLI
To find a shared public AMI using the command line tools
Use the ec2-describe-images command to list AMIs. You can scope the list to the types of AMIs that
interest you, as shown in the following examples.
The following command lists all public AMIs using the -x all option. This list includes any public AMIs
that you own.
ec2-describe-images -x all
The following command lists the AMIs for which you have explicit launch permissions. This list excludes
any such AMIs that you own.
ec2-describe-images -x self
The following command lists the AMIs owned by Amazon. Amazon's public AMIs have an aliased owner,
which appears as amazon in the account field. This enables you to find AMIs from Amazon easily. Other
users can't alias their AMIs.
ec2-describe-images -o amazon
The following command lists the AMIs owned by the specified AWS account.
ec2-describe-images -o <target_uid>
The <target_uid> is the account ID that owns the AMIs for which you are looking.
To reduce the number of displayed AMIs, use a filter to list only the types of AMIs that interest you. For
example, use the following filter to display only Windows-based AMIs.
--filter "platform=windows"
Using Shared AMIs
Before you use a shared AMI, take the following steps to confirm that there are no pre-installed credentials
that would allow unwanted access to your instance by a third party and no pre-configured remote logging
that could transmit sensitive data to a third party. Check the documentation for the Linux distribution used
by the AMI for information about improving the security of the system.
To ensure that you don't accidentally lose access to your instance, we recommend that you initiate two
SSH sessions and keep the second session open until you've removed credentials that you don't recognize
and confirmed that you can still log into your instance using SSH.
1. Identify and disable any unauthorized public SSH keys. The only key in the file should be the key you
used to launch the AMI. The following command locates authorized_keys files:
sudo find / -name "authorized_keys" -print -exec cat {} \;
2. Disable password-based authentication for the root user. Open the ssh_config file and edit the
PermitRootLogin line as follows:
API Version 2014-02-01
56
Amazon Elastic Compute Cloud User Guide
Finding Shared AMIs
PermitRootLogin without-password
Alternatively, you can disable the ability to log into the instance as root:
PermitRootLogin No
Then restart the sshd service.
3. Check whether there are any other user accounts that are able to log in to your instance. Accounts
with superuser privileges are particularly dangerous. Remove or lock the password of any unknown
accounts.
4. Check for open ports that you aren't using and running network services listening for incoming
connections.
5. To prevent preconfigured remote logging, you should delete the existing configuration file and restart
the rsyslog service. For example:
sudo rm /etc/rsyslog.config
sudo service rsyslog restart
6. Verify that all cron jobs are legitimate.
If you discover a public AMI that you feel presents a security risk, contact the AWS security team. For
more information, see the AWS Security Center.
Making an AMI Public
Amazon EC2 enables you to share your AMIs with other AWS accounts. You can allow all AWS accounts
to launch the AMI (make the AMI public), or only allow a few specific accounts to launch the AMI. You
are not billed when your AMI is launched by other AWS accounts; only the accounts launching the AMI
are billed.
Before you share an AMI, make sure to read the security considerations in Guidelines for Shared Linux
AMIs (p. 61).
Note
If an AMI has a product code, you can't make it public. You must share the AMI with only specific
AWS accounts.
Sharing a Public AMI Using the Console
To share a public AMI using the console
1. Open the Amazon EC2 console.
2. In the navigation pane, click AMIs.
3. Select your AMI in the list, and then select Modify Image Permissions from the Actions list.
4. Select the Public radio button, and then click Save.
Sharing a Public AMI Using the AWS CLI
Each AMI has a launchPermission property that controls which AWS accounts, besides the owner's,
are allowed to use that AMI to launch instances. By modifying the launchPermission property of an
API Version 2014-02-01
57
Amazon Elastic Compute Cloud User Guide
Making an AMI Public
AMI, you can make the AMI public (which grants launch permissions to all AWS accounts or share it with
only the AWS accounts that you specify.
You can add or remove account IDs from the list of accounts that have launch permissions for an AMI
To make the AMI public, specify the all group.You can specify both public and explicit launch permissions.
To make an AMI public
Use the modify-image-attribute command as follows to add the all group to the launchPermission
list for the specified AMI.
aws ec2 modify-image-attribute --image-id ami-2bb65342 --launch-permission
"{\"Add\":[{\"Group\":\"all\"}]}"
To verify the launch permissions of the AMI, use the following describe-image-attribute command.
aws ec2 describe-image-attribute --image-id ami-2bb65342 --attribute launchPer
mission
(Optional) To make the AMI private again, remove the all group from its launch permissions. Note that
the owner of the AMI always has launch permissions and is therefore unaffected by this command.
aws ec2 modify-image-attribute --image-id ami-2bb65342 "{\"Re
move\":[{\"Group\":\"all\"}]}"
Sharing a Public AMI Using the Amazon EC2 CLI
Each AMI has a launchPermission property that controls which AWS accounts, besides the owner's,
are allowed to use that AMI to launch instances. By modifying the launchPermission property of an
AMI, you can make the AMI public (which grants launch permissions to all AWS accounts or share it with
only the AWS accounts that you specify.
You can add or remove account IDs from the list of accounts that have launch permissions for an AMI
To make the AMI public, specify the all group.You can specify both public and explicit launch permissions.
To make an AMI public
Use the ec2-modify-image-attribute command as follows to add the all group to the launchPermission
list for the specified AMI.
ec2-modify-image-attribute ami-2bb65342 --launch-permission -a all
To verify the launch permissions of the AMI, use the following command.
ec2-describe-image-attribute ami-2bb65342 -l
To make the AMI private again, remove the all group from its launch permissions. Note that the owner
of the AMI always has launch permissions and is therefore unaffected by this command.
ec2-modify-image-attribute ami-2bb65342 -l -r all
API Version 2014-02-01
58
Amazon Elastic Compute Cloud User Guide
Making an AMI Public
Sharing an AMI with Specific AWS Accounts
You can share an AMI with specific AWS accounts without making the AMI public. All you need are the
AWS account IDs.
Sharing an AMI Using the Console
To grant explicit launch permissions using the console
1. Open the Amazon EC2 console.
2. In the navigation pane, click AMIs.
3. Select your AMI in the list, and then select Modify Image Permissions from the Actions list.
4. Specify the AWS account number of the user with whom you want to share the AMI in the AWS
Account Number field, then click Add Permission.
To share this AMI with multiple users, repeat the above step until you have added all the required
users.
5. To allow create volume permissions for snapshots, check Add "create volume" permissions to
the following associated snapshots when creating permissions.
Note
You do not need to share the Amazon EBS snapshots than an AMI references in order to
share the AMI. Only the AMI itself needs to be shared; the system automatically provides
the instance access to the referenced Amazon EBS snapshots for the launch.
6. Click Save when you are done.
Sharing an AMI Using the AWS CLI
Use the modify-image-attribute command to share an AMI as shown in the following examples.
To grant explicit launch permissions
The following command grants launch permissions for the specified AMI to the specified AWS account.
aws ec2 modify-image-attribute --image-id ami-2bb65342
"{\"Add\":[{\"UserId\":\"123456789012\"}]}"
To remove launch permissions for an account
The following command removes launch permissions for the specified AMI from the specified AWS
account:
aws ec2 modify-image-attribute --image-id ami-2bb65342 "{\"Re
move\":[{\"UserId\":\"123456789012\"}]}"
To remove all launch permissions
The following command removes all public and explicit launch permissions from the specified AMI. Note
that the owner of the AMI always has launch permissions and is therefore unaffected by this command.
aws ec2 reset-image-attribute --image-id ami-2bb65342 --attribute launchPermis
sion
API Version 2014-02-01
59
Amazon Elastic Compute Cloud User Guide
Sharing an AMI with Specific AWS Accounts
Sharing an AMI Using the Amazon EC2 CLI
Use the ec2-modify-image-attribute command to share an AMI as shown in the following examples.
To grant explicit launch permissions
The following command grants launch permissions for the specified AMI to the specified AWS account.
ec2-modify-image-attribute ami-2bb65342 -l -a 111122223333
To remove launch permissions for an account
The following command removes launch permissions for the specified AMI from the specified AWS
account:
ec2-modify-image-attribute ami-2bb65342 -l -r 111122223333
To remove all launch permissions
The following command removes all public and explicit launch permissions from the specified AMI. Note
that the owner of the AMI always has launch permissions and is therefore unaffected by this command.
ec2-reset-image-attribute ami-2bb65342 -l
Using Bookmarks
If you have created a public AMI, or shared an AMI with another AWS user, you can create a bookmark
that allows a user to access your AMI and launch an instance in their own account immediately. This is
an easy way to share AMI references, so users don't have to spend time finding your AMI in order to use
it.
Note that your AMI must be public, or you must have shared it with the user to whom you want to send
the bookmark.
To create a bookmark for your AMI
1. Type a URL with the following information, where <region> is the region in which your AMI resides,
and <ami_id> is the ID of the AMI:
https://console.aws.amazon.com/ec2/v2/home?region=<region>#LaunchInstanceWiz
ard:ami=<ami_id>
For example, this URL launches an instance from the ami-2bb65342 AMI in the us-east-1 region:
https://console.aws.amazon.com/ec2/v2/home?region=us-east-1#LaunchInstanceWiz
ard:ami=ami-2bb65342
2. Distribute the link to users who want to use your AMI.
3. To use a bookmark, click the link or copy and paste it into your browser. The launch wizard opens,
with the AMI already selected.
API Version 2014-02-01
60
Amazon Elastic Compute Cloud User Guide
Using Bookmarks
Guidelines for Shared Linux AMIs
If you follow these guidelines, you'll provide a better user experience and make your users' instances
less vulnerable to security issues.
Topics
Update the AMI Tools at Boot Time (p. 61)
Disable Password-Based Logins for Root (p. 61)
Disable Root Access (p. 62)
Remove SSH Host Key Pairs (p. 62)
Install Public Key Credentials (p. 63)
Disabling sshd DNS Checks (Optional) (p. 63)
Identify Yourself (p. 64)
Protect Yourself (p. 64)
If you are building AMIs for AWS Marketplace, see Building AMIs for AWS Marketplace for guidelines,
policies and best practices.
For additional information about sharing AMIs safely, see the following articles:
How To Share and Use Public AMIs in A Secure Manner
Public AMI Publishing: Hardening and Clean-up Requirements
Update the AMI Tools at Boot Time
For AMIs backed by instance store, we recommend that your AMIs download and upgrade the Amazon
EC2 AMI creation tools during startup. This ensures that new AMIs based on your shared AMIs have the
latest AMI tools.
For Amazon Linux, add the following to /etc/rc.local:
# Update the Amazon EC2 AMI tools
echo " + Updating EC2 AMI tools"
yum update -y aws-amitools-ec2
echo " + Updated EC2 AMI tools"
Use this method to automatically update other software on your image.
Note
When deciding which software to automatically update, consider the amount of WAN traffic that
the update will generate (your users will be charged for it) and the risk of the update breaking
other software on the AMI.
For other distributions, make sure you have the latest AMI tools.
Disable Password-Based Logins for Root
Using a fixed root password for a public AMI is a security risk that can quickly become known. Even
relying on users to change the password after the first login opens a small window of opportunity for
potential abuse.
API Version 2014-02-01
61
Amazon Elastic Compute Cloud User Guide
Guidelines for Shared Linux AMIs
To solve this problem, disable password-based logins for the root user. Additionally, we recommend you
disable root access.
To disable password-based logins for root
1. Open the /etc/ssh/sshd_config file with a text editor and locate the following line:
#PermitRootLogin yes
2. Change the line to:
PermitRootLogin without-password
The location of this configuration file might differ for your distribution, or if you are not running
OpenSSH. If this is the case, consult the relevant documentation.
Disable Root Access
When you work with shared AMIs, it is a known best practice to have a secure environment; one of the
elements associated with a secure environment is ensuring that the root password is not empty. To do
this, log into your running instance and issue the following command to disable root access:
[ec2-user ~]$ sudo passwd -l root
Note
This does not impact the use of sudo.
Remove SSH Host Key Pairs
If you plan to share an AMI derived from a public AMI, remove the existing SSH host key pairs located
in /etc/ssh. This forces SSH to generate new unique SSH key pairs when someone launches an
instance using your AMI, improving security and reducing the likelihood of "man-in-the-middle" attacks.
The following list shows the SSH files to remove.
ssh_host_dsa_key
ssh_host_dsa_key.pub
ssh_host_key
ssh_host_key.pub
ssh_host_rsa_key
ssh_host_rsa_key.pub
You can securely remove all of these files with the following command.
[ec2-user ~]$ sudo shred -u /etc/ssh/*_key /etc/ssh/*_key.pub
Important
If you forget to remove the existing SSH host key pairs from your public AMI, our routine auditing
process notifies you and all customers running instances of your AMI of the potential security
risk. After a short grace period, we mark the AMI private.
API Version 2014-02-01
62
Amazon Elastic Compute Cloud User Guide
Guidelines for Shared Linux AMIs
Install Public Key Credentials
After configuring the AMI to prevent logging in using a password, you must make sure users can log in
using another mechanism.
Amazon EC2 allows users to specify a public-private key pair name when launching an instance. When
a valid key pair name is provided to the RunInstances API call (or through the command line API tools),
the public key (the portion of the key pair that Amazon EC2 retains on the server after a call to
CreateKeyPair or ImportKeyPair) is made available to the instance through an HTTP query against
the instance metadata.
To log in through SSH, your AMI must retrieve the key value at boot and append it to
/root/.ssh/authorized_keys (or the equivalent for any other user account on the AMI). Users can
launch instances of your AMI with a key pair and log in without requiring a root password.
Many distributions, including Amazon Linux and Ubuntu, use the cloud-init package to inject public
key credentials for a configured user. If your distribution does not support cloud-init, you can add the
following code to a system start-up script (such as /etc/rc.local) to pull in the public key you specified
at launch for the root user.
if [ ! -d /root/.ssh ] ; then
mkdir -p /root/.ssh
chmod 700 /root/.ssh
fi
# Fetch public key using HTTP
curl http://169.254.169.254/latest/meta-data/public-keys/0/openssh-key > /tmp/my-
key
if [ $? -eq 0 ] ; then
cat /tmp/my-key >> /root/.ssh/authorized_keys
chmod 700 /root/.ssh/authorized_keys
rm /tmp/my-key
fi
This can be applied to any user account; you do not need to restrict it to root.
Note
Rebundling an instance based on this AMI includes the key with which it was launched. To
prevent the key's inclusion, you must clear out (or delete) the authorized_keys file or exclude
this file from rebundling.
Disabling sshd DNS Checks (Optional)
Disabling sshd DNS checks slightly weakens your sshd security. However, if DNS resolution fails, SSH
logins still work. If you do not disable sshd checks, DNS resolution failures prevent all logins.
To disable sshd DNS checks
1. Open the /etc/ssh/sshd_config file with a text editor and locate the following line:
#UseDNS yes
2. Change the line to:
UseDNS no
API Version 2014-02-01
63
Amazon Elastic Compute Cloud User Guide
Guidelines for Shared Linux AMIs
Note
The location of this configuration file can differ for your distribution or if you are not running
OpenSSH. If this is the case, consult the relevant documentation.
Identify Yourself
Currently, there is no easy way to know who provided a shared AMI, because each AMI is represented
by an account ID.
We recommend that you post a description of your AMI, and the AMI ID, in the Amazon EC2 forum. This
provides a convenient central location for users who are interested in trying new shared AMIs. You can
also post the AMI to the Amazon Machine Images (AMIs) page.
Protect Yourself
The previous sections described how to make your shared AMIs safe, secure, and usable for the users
who launch them. This section describes guidelines to protect yourself from the users of your AMI.
We recommend against storing sensitive data or software on any AMI that you share. Users who launch
a shared AMI might be able to rebundle it and register it as their own. Follow these guidelines to help you
to avoid some easily overlooked security risks:
Always delete the shell history before bundling. If you attempt more than one bundle upload in the
same AMI, the shell history contains your secret access key. The following example should be the last
command executed before bundling from within the instance.
[ec2-user ~]$ shred -u ~/.*history
AWS recommends using the --exclude directory option on ec2-bundle-vol to skip any directories
and subdirectories that contain secret information that you would not like to include in your bundle. For
more information, see ec2-bundle-vol in the Amazon Elastic Compute Cloud Command Line Reference.
Bundling a running instance requires your private key and X.509 certificate. Put these and other
credentials in a location that is not bundled (such as the instance store).
Exclude the SSH authorized keys when bundling the image. The Amazon public AMIs store the public
key used to launch an instance with its SSH authorized keys file.
Note
Unfortunately, it is not possible for this list of guidelines to be exhaustive. Build your shared AMIs
carefully and take time to consider where you might expose sensitive data.
Paid AMIs
A paid AMI is an AMI that you can purchase from a developer.
Amazon EC2 integrates with Amazon DevPay and AWS Marketplace, enabling developers to charge
other Amazon EC2 users for the use of their AMIs or to provide support for instances. For more information
about Amazon DevPay, see the Amazon DevPay site.
The AWS Marketplace is an online store where you can buy software that runs on AWS; including AMIs
that you can use to launch your EC2 instance. The AWS Marketplace AMIs are organized into categories,
API Version 2014-02-01
64
Amazon Elastic Compute Cloud User Guide
Paid AMIs
such as Developer Tools, to enable you to find products to suit your requirements. For more information
about AWS Marketplace, see the AWS Marketplace site.
Launching an instance from a paid AMI is the same as launching an instance from any other AMI. No
additional parameters are required. The instance is charged according to the rates set by the owner of
the AMI, as well as the standard usage fees for the related web services; for example, the hourly rate for
running a m1.small instance type in Amazon EC2. The owner of the paid AMI can confirm whether a
specific instance was launched using that paid AMI.
Important
All paid AMIs from Amazon DevPay are backed by instance store. AWS Marketplace supports
AMIs backed by Amazon EBS.
Topics
Selling Your AMI (p. 65)
Finding a Paid AMI (p. 65)
Purchase a Paid AMI (p. 66)
Getting the Product Code for Your Instance (p. 67)
Using Paid Support (p. 67)
Bills for Paid and Supported AMIs (p. 68)
Managing Your AWS Marketplace Subscriptions (p. 68)
Selling Your AMI
You can sell your AMI using either AWS Marketplace or Amazon DevPay. Both help customers buy
software that runs on AWS, but AWS Marketplace offers a better shopping experience, making it easier
for customers to find your AMI. AWS Marketplace also supports AWS features that Amazon DevPay
doesn't support, such as Amazon EBS-backed AMIs, Reserved Instances, and Spot Instances.
For information about how to sell your AMI on AWS Marketplace, see Selling on AWS Marketplace.
For information about how to sell your AMI on Amazon DevPay, see Using DevPay with Your Amazon
EC2 AMI.
Finding a Paid AMI
There are several ways that you can find AMIs that are available for you to purchase. For example, you
can use AWS Marketplace, the Amazon EC2 console, or the Amazon EC2 CLI. Alternatively, a developer
might let you know about a paid AMI themselves.
Finding a Paid AMI Using the Console
To find a paid AMI using the console
1. Open the Amazon EC2 console.
2. In the navigation pane, click AMIs.
3. Select Public images from the first Filter list, Marketplace images from the second Filter list, and
the operating system from the third Filter list.
API Version 2014-02-01
65
Amazon Elastic Compute Cloud User Guide
Selling Your AMI
Finding a Paid AMI Using AWS Marketplace
To find a paid AMI using AWS Marketplace
1. Open AWS Marketplace.
2. Enter the name of the operating system in the search box, and click Go.
3. To scope the results further, use one of the categories or filters.
4. Each product is labeled with its product type: either AMI or Software as a Service.
Finding a Paid Windows AMI Using the AWS CLI
To find a paid Windows AMI using the AWS CLI
You can also find a paid Windows AMI using the describe-images command as follows.
ec2-describe-images --owners aws-marketplace
This command returns numerous details that describe each AMI, including the product code for a paid
AMI. The output from describe-images includes an entry for the product code like the following:
"ProductCodes": [
{
"ProductCodeId": "product_code",
"ProductCodeType": "marketplace"
}
],
Finding a Paid Windows AMI Using the Amazon EC2 CLI
To find a paid Windows AMI using the Amazon EC2 CLI
You can also find a paid Windows AMI using the ec2-describe-images command as follows.
ec2-describe-images -o aws-marketplace
This command returns numerous details that describe each AMI, including the product code for a paid
AMI. The following example output from ec2-describe-images includes a product code.
IMAGE ami-a5bf59cc image_source 123456789012 available public
product_code x86_64 machine instance-store
Purchase a Paid AMI
You must sign up for (purchase) a paid AMI before you can launch an instance using the AMI.
Typically a seller of a paid AMI presents you with information about the AMI, including its price and a link
where you can buy it. When you click the link, you're first asked to log into AWS, and then you can
purchase the AMI.
Important
You don't get the discount from Reserved Instances if you use a paid AMI from Amazon DevPay.
That is, if you purchase Reserved Instances, you don't get the lower price associated with them
API Version 2014-02-01
66
Amazon Elastic Compute Cloud User Guide
Purchase a Paid AMI
when you launch a paid AMI. You always pay the price that's specified by the seller of the paid
AMI.
Purchasing a Paid AMI Using the Console
You can purchase a paid AMI by using the Amazon EC2 launch wizard. For more information, see
Launching an AWS Marketplace Instance (p. 306).
Subscribing to a Product Using AWS Marketplace
To use the AWS Marketplace, you must have an AWS account. To launch instances from AWS Marketplace
products, you must be signed up to use the Amazon EC2 service, and you must be subscribed to the
product from which to launch the instance. There are two ways to subscribe to products in the AWS
Marketplace:
AWS Marketplace website:You can launch preconfigured software quickly with the 1-Click deployment
feature.
Amazon EC2 launch wizard: You can search for an AMI and launch an instance directly from the
wizard. For more information, see Launching an AWS Marketplace Instance (p. 306).
Purchasing a Paid AMI From a Developer
The developer of a paid AMI can enable you to purchase a paid AMI that isn't listed in AWS Marketplace.
The developer provides you with a link that enables you to purchase the product through Amazon. You
can sign in with your Amazon.com credentials and select a credit card that's stored in your Amazon.com
account to use when purchasing the AMI.
Getting the Product Code for Your Instance
You can determine whether your instance has an Amazon DevPay or AWS Marketplace product code
using its instance metadata. For more information about retrieving metadata, see Instance Metadata and
User Data (p. 268).
To retrieve a product code, use the following query:
GET http://169.254.169.254/2007-03-01/meta-data/product-codes
If the instance has a product code, Amazon EC2 returns it. For example:
774F4FF8
Using Paid Support
Amazon EC2 also enables developers to offer support for software (or derived AMIs). Developers can
create support products that you can sign up to use. During sign-up for the support product, the developer
gives you a product code, which you must then associate with your own AMI. This enables the developer
to confirm that your instance is eligible for support. It also ensures that when you run instances of the
product, you are charged according to the terms for the product specified by the developer.
Important
You can't use a support product with Reserved Instances. You always pay the price that's
specified by the seller of the support product.
API Version 2014-02-01
67
Amazon Elastic Compute Cloud User Guide
Getting the Product Code for Your Instance
To associate a product code with your AMI, use one of the following commands, where ami_id is the ID
of the AMI and product_code is the product code:
modify-image-attribute (AWS CLI)
aws ec2 modify-image-attribute --image-id ami_id --product-codes "product_code"
ec2-modify-image-attribute (Amazon EC2 CLI)
ec2-modify-image-attribute ami_id --product-code product_code
After you set the product code attribute, it cannot be changed or removed.
Bills for Paid and Supported AMIs
At the end of each month, you receive an email with the amount your credit card has been charged for
using any paid or supported AMIs during the month. This bill is separate from your regular Amazon EC2
bill. For more information, see Paying For AWS Marketplace Products.
Managing Your AWS Marketplace Subscriptions
On the AWS Marketplace website, you can check your subscription details, view the vendor's usage
instructions, manage your subscriptions, and more.
To check your subscription details
1. Log in to the AWS Marketplace.
2. Click Your Account.
3. Click Manage Your Software Subscriptions.
4. All your current subscriptions are listed. Click Usage Instructions to view specific instructions for
using the product, for example, a user name for connecting to your running instance.
To cancel an AWS Marketplace subscription
1. Ensure that you have terminated any instances running from the subscription.
a. Open the Amazon EC2 console.
b. In the navigation pane, click Instances.
c. Select the instance, and select Terminate from the Actions menu. When prompted, click Yes,
Terminate.
2. Log in to the AWS Marketplace, and click Your Account, then Manage Your Software
Subscriptions.
3. Click Cancel subscription. You are prompted to confirm your cancellation.
Note
After you've canceled your subscription, you are no longer able to launch any instances
from that AMI. To use that AMI again, you need to resubscribe to it, either on the AWS
Marketplace website, or through the launch wizard in the Amazon EC2 console.
API Version 2014-02-01
68
Amazon Elastic Compute Cloud User Guide
Bills for Paid and Supported AMIs
Creating an Amazon EBS-Backed Linux AMI
To create an Amazon EBS-backed Linux AMI, start from an instance that you've launched from an existing
Amazon EBS-backed Linux AMI. After you've customized the instance to suit your needs, create and
register a new AMI, which you can use to launch new instances with these customizations.
If you need to create an Amazon EBS-backed Windows AMI, see Creating an Amazon EBS-Backed
Windows AMI in the Amazon Elastic Compute Cloud Microsoft Windows Guide.
The AMI creation process is different for instance store-backed AMIs. For more information about the
differences between Amazon EBS-backed and instance store-backed instances, and how to determine
the root device type for your instance, see Storage for the Root Device (p. 50). If you need to create an
instance store-backed Linux AMI, see Creating an Instance Store-Backed Linux AMI (p. 72).
Topics
Overview of the Creation Process for Amazon EBS-Backed AMIs (p. 69)
Creating the AMI from an Instance (p. 70)
Creating an AMI from a Snapshot (p. 71)
Overview of the Creation Process for Amazon
EBS-Backed AMIs
The following diagram summarizes the creation process for Amazon EBS-backed AMIs.
First, launch an instance from an AMI that's similar to the AMI that you'd like to create. You can connect
to your instance and customize it. When the instance is set up the way you want it, it's best to stop the
instance before you create an AMI to ensure data integrity. Then, you can create the image. When you
create an Amazon EBS-backed AMI, we automatically register it for you.
Amazon EC2 powers down the instance before creating the AMI to ensure that everything on the instance
is stopped and in a consistent state during the creation process. If you're confident that your instance is
in a consistent state appropriate for AMI creation, you can tell Amazon EC2 not to power down and reboot
the instance. Some file systems, such as xfs, can freeze and unfreeze activity, making it safe to create
the image without rebooting the instance.
During the AMI creation process, Amazon EC2 creates snapshots of your instance's root volume and
any other Amazon EBS volumes attached to your instance. Depending on the size of the volumes, it may
take several minutes for the entire AMI creation process to complete (sometimes up to 24 hours). To help
speed up this process, we recommend that you create snapshots of your volumes immediately before
creating an AMI. For more information, see Creating an Amazon EBS Snapshot (p. 559).
After the process completes, you have a new AMI and snapshot created from the root volume of the
instance. When you launch an instance using the new AMI, we create a new Amazon EBS volume for
its root volume using the snapshot. Both the AMI and the snapshot incur charges to your account until
you delete them. For more information, see Deregistering Your AMI (p. 83).
API Version 2014-02-01
69
Amazon Elastic Compute Cloud User Guide
Creating an Amazon EBS-Backed Linux AMI
If you add instance-store volumes or Amazon EBS volumes to your instance in addition to the root device
volume, the block device mapping for the new AMI contains information for these volumes, and the block
device mappings for instances that you launch from the new AMI automatically contain information for
these volumes. The instance-store volumes specified in the block device mapping for the new instance
are new and don't contain any data from the instance store volumes of the instance you used to create
the AMI. The data on Amazon EBS volumes persists. For more information, see Block Device
Mapping (p. 592).
Creating the AMI from an Instance
You can create an AMI using the AWS Management Console or the command line.
To create an AMI from an instance using the console
1. Open the Amazon EC2 console.
2. If you don't have a running instance that uses an Amazon EBS volume for the root device, you must
launch one. For instructions, see Launching an Instance (p. 300).
3. (Optional) Connect to the instance and customize it. For example, you can install software and
applications, copy data, or attach additional Amazon EBS volumes. For more information about
connecting to an instance, see Connect to Your Instance (p. 308).
4. (Optional) Create snapshots of all the volumes attached your instance. This may help reduce the
time it takes to create the AMI. For more information about creating snapshots, see Creating an
Amazon EBS Snapshot (p. 559).
5. In the navigation pane, click Instances and select your instance. Click Actions and then click Create
Image.
Tip
If this option is disabled, your instance isn't an Amazon EBS-backed instance.
6. In the Create Image dialog box, specify the following, and then click Create Image.
a. A unique name for the image.
b. (Optional) A description of the image, up to 255 characters.
c. By default, Amazon EC2 shuts down the instance, takes snapshots of any attached volumes,
creates and registers the AMI, and then reboots the instance. Select No reboot if you don't want
your instance to be shut down.
Warning
If you select No reboot, we can't guarantee the file system integrity of the created
image.
d. (Optional) You can modify the root volume, Amazon EBS volumes, and instance store volumes
as follows:
To change the size of the root volume, locate the Root volume in the Type column, and fill in
the Size field.
To suppress an Amazon EBS volume specified by the block device mapping of the AMI used
to launch the instance, locate the EBS volume in the list and click Delete.
To add an Amazon EBS volume, click Add New Volume, select EBS from the Type list, and
fill in the fields. When you then launch an instance from your new AMI, these additional volumes
are automatically attached to the instance. Empty volumes must be formatted and mounted.
Volumes based on a snapshot must be mounted.
To suppress an instance store volume specified by the block device mapping of the AMI used
to launch the instance, locate the volume in the list and click Delete.
To add an instance store volume, click Add New Volume, select Instance Store from the
Type list, and select a device name from the Device list. When you launch an instance from
your new AMI, these additional volumes are automatically initialized and mounted. These
API Version 2014-02-01
70
Amazon Elastic Compute Cloud User Guide
Creating the AMI from an Instance
volumes don't contain data from the instance store volumes of the running instance from which
you based your AMI.
7. Click AMIs in the navigation pane to view the status of your AMI. While the new AMI is being created,
its status is pending. This process typically takes a few minutes to finish, and then the status of
your AMI is available.
8. (Optional) Click Snapshots in the navigation pane to view the snapshot that was created for the new
AMI. When you launch an instance from this AMI, we use this snapshot to create its root device
volume.
To create an AMI from an instance using the command line
You can use one of the following commands. For more information about these command line interfaces,
see Accessing Amazon EC2 (p. 3).
create-image (AWS CLI)
ec2-create-image (Amazon EC2 CLI)
New-EC2Image (AWS Tools for Windows PowerShell)
Creating an AMI from a Snapshot
If you have a snapshot of the root device volume of an instance, you can create an AMI from this snapshot
using the AWS Management Console or the command line.
To create an AMI from a snapshot using the console
1. Open the Amazon EC2 console.
2. In the navigation pane, under Elastic Block Store, click Snapshots.
3. Select the snapshot, and then select Create Image from the Actions list.
4. In the Create Image from EBS Snapshot dialog box, do the following:
a. Select the architecture from the Architecture list (i386 for 32-bit or x86_64 for 64-bit).
b. Select the AKI from the Kernel ID list. If you select the default AKI or don't select an AKI, you'll
be required to specify an AKI every time you launch an instance using this AMI. In addition, your
instance may fail the health checks if the default AKI is incompatible with the instance.
c. Click Create.
To create an AMI from a snapshot using the command line
You can use one of the following commands. For more information about these command line interfaces,
see Accessing Amazon EC2 (p. 3).
register-image (AWS CLI)
ec2-register (Amazon EC2 CLI)
Register-EC2Image (AWS Tools for Windows PowerShell)
API Version 2014-02-01
71
Amazon Elastic Compute Cloud User Guide
Creating an AMI from a Snapshot
Creating an Instance Store-Backed Linux AMI
To create an instance store-backed Linux AMI, start from an instance that you've launched from an existing
instance store-backed Linux AMI. After you've customized the instance to suit your needs, bundle the
volume and register a new AMI, which you can use to launch new instances with these customizations.
If you need to create an instance store-backed Windows AMI, see Creating an Instance Store-Backed
Windows AMI in the Amazon Elastic Compute Cloud Microsoft Windows Guide.
The AMI creation process is different for instance store-backed AMIs. For more information about the
differences between Amazon EBS-backed and instance store-backed instances, and how to determine
the root device type for your instance, see Storage for the Root Device (p. 50). If you need to create an
Amazon EBS-backed Linux AMI, see Creating an Amazon EBS-Backed Linux AMI (p. 69).
Topics
Overview of the Creation Process for Instance Store-Backed AMIs (p. 72)
Prerequisites (p. 73)
Creating an AMI from an Instance Store-Backed Linux Instance (p. 73)
Converting your Instance Store-Backed AMI to an Amazon EBS-Backed AMI (p. 77)
Overview of the Creation Process for Instance
Store-Backed AMIs
The following diagram summarizes the process of creating an AMI from an instance store-backed instance.
First, launch an instance from an AMI that's similar to the AMI that you'd like to create. You can connect
to your instance and customize it. When the instance is set up the way you want it, you can bundle it. It
takes several minutes for the bundling process to complete. After the process completes, you have a
bundle, which consists of an image manifest (image.manifest.xml) and files (image.part.xx) that
contain a template for the root volume. Next you upload the bundle to your Amazon S3 bucket and then
register your AMI.
When you launch an instance using the new AMI, we create the root volume for the instance using the
bundle that you uploaded to Amazon S3. The storage space used by the bundle in Amazon S3 incurs
charges to your account until you delete it. For more information, see Deregistering Your AMI (p. 83).
If you add instance store volumes to your instance in addition to the root device volume, the block device
mapping for the new AMI contains information for these volumes, and the block device mappings for
instances that you launch from the new AMI automatically contain information for these volumes. For
more information, see Block Device Mapping (p. 592).
API Version 2014-02-01
72
Amazon Elastic Compute Cloud User Guide
Creating an Instance Store-Backed Linux AMI
Prerequisites
Before you can create the AMI, you must complete the following tasks:
Install the AMI tools. For more information, see Set Up the AMI Tools.
Install the API tools. For more information, see Setting Up the Amazon EC2 Command Line Interface
Tools on Linux.
Ensure that you have an Amazon S3 bucket for the bundle. To create an Amazon S3 bucket, open the
Amazon S3 console and click Create Bucket.
Note
You can also use the AWS CLI mb command to create a bucket. To get started with the AWS
CLI, see AWS Command Line Interface User Guide.
Ensure that you have the following credentials:
Your AWS account ID. To retrieve your account ID, go to Your Security Credentials and expand
Account Identifiers.
An X.509 certificate and private key. If you need to create an X.509 certificate, go to Your Security
Credentials, expand X.509 Certificates, and click Create New Certificate. The X.509 certificate
and private key are used to encrypt and decrypt your AMI.
Your access key ID. If you need to retrieve or create an access key ID, go to Your Security Credentials,
and expand Access Keys.
Your secret access key. You can't retrieve your secret access key. Therefore, if you can't find your
secret access key, you'll need to create a new one. To create a secret access key, go to Your Security
Credentials, expand Access Keys, and click Create New Access Key.
Connect to your instance and customize it. For example, you can install software and applications,
copy data, delete temporary files, and modify the Linux configuration.
Creating an AMI from an Instance Store-Backed
Linux Instance
To prepare to use the Amazon EC2 AMI Tools (HVM instances only)
The Amazon EC2 AMI tools require GRUB Legacy to boot properly. Some AMIs (most notably, Ubuntu)
are configured to use GRUB 2. You must check to see that your instance uses GRUB Legacy, and if not,
you need to install and configure it.
HVM instances also require partitioning tools to be installed for the AMI tools to work properly.
1. Check to see if your instance uses GRUB Legacy.
a. List the block devices to find the root block device.
[ec2-user ~]$ lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
xvda 202:0 0 8G 0 disk
xvda1 202:1 0 8G 0 part /
xvdb 202:16 0 30G 0 disk /media/ephemeral0
In this example, the root device (indicated by a MOUNTPOINT of /) is /dev/xvda1. The root block
device is its parent, /dev/xvda.
b. Determine the GRUB version on the root block device.
API Version 2014-02-01
73
Amazon Elastic Compute Cloud User Guide
Prerequisites
[ec2-user ~]$ sudo file -s /dev/xvda
/dev/xvda: x86 boot sector; GRand Unified Bootloader, stage1 version
0x3, stage2 address 0x2000, 1st sector stage2 0x800, stage2 segment
0x200, GRUB version 0.94; partition 1: ID=0xee, starthead 254,
startsector 1, 16777215 sectors, extended partition table (last)\011,
code offset 0x48
In the above example, the GRUB version is 0.94, which is GRUB Legacy. If your GRUB version
is 0.9x or less, you may move on to Step 3 (p. 74). If you do not see a GRUB version in this
output, try the grub-install -v command.
ubuntu:~$ grub-install -v
grub-install (GRUB) 1.99-21ubuntu3.10
In this example, the GRUB version is greater than 0.9x, so GRUB Legacy must be installed.
Proceed to Step 2 (p. 74).
2. Install the grub package using the package manager for your distribution to install GRUB Legacy.
For Ubuntu instances, use the following command.
ubuntu:~$ sudo apt-get install -y grub
You can verify that your instance is using GRUB Legacy with the grub --version command.
ubuntu:~$ grub --version
grub (GNU GRUB 0.97)
3. Install the following partition management packages using the package manager for your distribution.
gdisk (some distributions may call this package gptfdisk instead)
kpartx
For Ubuntu instances, use the following command.
ubuntu:~$ sudo apt-get install -y gdisk kpartx
4. Check the kernel parameters for your instance.
ubuntu:~$ cat /proc/cmdline
BOOT_IMAGE=/boot/vmlinuz-3.2.0-54-virtual root=UUID=4f392932-ed93-4f8f-aee7-
72bc5bb6ca9d ro console=ttyS0 xen_emul_unplug=unnecessary
Note the options following the kernel and root device parameters, console=ttyS0 and
xen_emul_unplug=unnecessary.
5. Check the kernel entries in /boot/grub/menu.lst.
ubuntu:~$ grep ^kernel /boot/grub/menu.lst
kernel /boot/vmlinuz-3.2.0-54-virtual root=LABEL=cloudimg-rootfs ro con
sole=hvc0
API Version 2014-02-01
74
Amazon Elastic Compute Cloud User Guide
Creating an AMI from an Instance Store-Backed Linux
Instance
kernel /boot/vmlinuz-3.2.0-54-virtual root=LABEL=cloudimg-rootfs ro single
kernel /boot/memtest86+.bin
Note that the console parameter is pointing to hvc0 instead of ttyS0 and that the
xen_emul_unplug=unnecessary parameter is missing.
6. Edit the /boot/grub/menu.lst file with your favorite text editor (such as vim or nano) to change
the console and add the parameters you identified earlier to the boot entries.
title Ubuntu 12.04.3 LTS, kernel 3.2.0-54-virtual
root (hd0)
kernel /boot/vmlinuz-3.2.0-54-virtual root=LABEL=cloudimg-rootfs
ro console=ttyS0 xen_emul_unplug=unnecessary
initrd /boot/initrd.img-3.2.0-54-virtual
title Ubuntu 12.04.3 LTS, kernel 3.2.0-54-virtual (recovery mode)
root (hd0)
kernel /boot/vmlinuz-3.2.0-54-virtual root=LABEL=cloudimg-rootfs
ro single console=ttyS0 xen_emul_unplug=unnecessary
initrd /boot/initrd.img-3.2.0-54-virtual
title Ubuntu 12.04.3 LTS, memtest86+
root (hd0)
kernel /boot/memtest86+.bin
7. Verify that your kernel entries now contain the correct parameters.
ubuntu:~$ grep ^kernel /boot/grub/menu.lst
kernel /boot/vmlinuz-3.2.0-54-virtual root=LABEL=cloudimg-rootfs ro con
sole=ttyS0 xen_emul_unplug=unnecessary
kernel /boot/vmlinuz-3.2.0-54-virtual root=LABEL=cloudimg-rootfs ro single
console=ttyS0 xen_emul_unplug=unnecessary
kernel /boot/memtest86+.bin
To create an AMI from an instance store-backed Linux instance
This procedure assumes that you have satisfied the prerequisites in Prerequisites (p. 73).
1. Upload your credentials to your instance. We use these credentials to ensure that only you and
Amazon EC2 can access your AMI.
a. Create a temporary directory on your instance for your credentials as follows:
[ec2-user ~]$ mkdir /tmp/cert
This enables you to exclude your credentials from the created image.
b. Copy your X.509 certificate and private key from your computer to the /tmp/cert directory on
your instance, using a secure copy tool such as scp (p. 310). The -i my-private-key.pem
option in the following scp command is the private key you use to connect to your instance with
SSH, not the X.509 private key. For example:
you@your_computer:~ $ scp -i my-private-key.pem /path/to/pk-HKZYK
TAIG2ECMXYIBH3HXV4ZBEXAMPLE.pem /path/to/cert-HKZYKTAIG2ECMXY
API Version 2014-02-01
75
Amazon Elastic Compute Cloud User Guide
Creating an AMI from an Instance Store-Backed Linux
Instance
IBH3HXV4ZBEXAMPLE.pem [email protected]
aws.com:/tmp/cert/
pk-HKZYKTAIG2ECMXYIBH3HXV4ZBEXAMPLE.pem 100% 717 0.7KB/s 00:00
cert-HKZYKTAIG2ECMXYIBH3HXV4ZBEXAMPLE.pem 100% 685 0.7KB/s 00:00
2. Prepare the bundle to upload to Amazon S3 using the ec2-bundle-vol command. Be sure to specify
the -e option to exclude the directory where your credentials are stored. By default, the bundle
process excludes files that might contain sensitive information. These files include *.sw, *.swo,
*.swp, *.pem, *.priv, *id_rsa*, *id_dsa* *.gpg, *.jks, */.ssh/authorized_keys, and
*/.bash_history. To include all of these files, use the --no-filter option. To include some of
these files, use the --include option.
Important
By default, the AMI bundling process creates a compressed, encrypted collection of files in
the /tmp directory that represent your root volume. If you do not have enough free disk
space in /tmp to store the bundle, you need to specify a different location for the bundle to
be stored with the -d /path/to/bundle/storage option. Some instances have ephemeral
storage mounted at /mnt or /media/ephemeral0 that you can use, or you can also
create (p. 526), attach (p. 529), and mount (p. 532) a new Amazon EBS volume to store the
bundle.
a. The ec2-bundle-vol command needs to run as root. For most commands, you can use sudo
to gain elevated permissions, but in this case, you should run sudo -E su to keep your
environment variables.
[ec2-user ~]$ sudo -E su
b. Run the ec2-bundle-vol command with the following arguments. If you do not have enough
available disk space in /tmp to store your bundle, specify a location that has available space
with the -d /path/to/bundle/storage option. For HVM instances, be sure to add the
--partition flag; otherwise, your AMI will not boot. For more information on this command
and its available options, see ec2-bundle-vol in the Amazon Elastic Compute Cloud Command
Line Reference.
[root ec2-user]# $EC2_AMITOOL_HOME/bin/ec2-bundle-vol -k /tmp/cert/pk-
HKZYKTAIG2ECMXYIBH3HXV4ZBEXAMPLE.pem -c /tmp/cert/cert-HKZYKTAIG2ECMXY
IBH3HXV4ZBEXAMPLE.pem -u your_aws_account_id -r x86_64 -e /tmp/cert
It can take a few minutes to create the image. When this command completes, your tmp directory
contains the bundle (image.manifest.xml, plus multiple image.part.xx files).
c. Exit from the root shell.
[root ec2-user]# exit
3. Upload your bundle to Amazon S3 using the ec2-upload-bundle command. Note that if the bundle
prefixes (directories) don't exist in the bucket, this command creates them.
Note
If you specified a path with the -d /path/to/bundle/storage option in Step 2.b (p. 76),
use that same path in the -m option below, instead of /tmp.
API Version 2014-02-01
76
Amazon Elastic Compute Cloud User Guide
Creating an AMI from an Instance Store-Backed Linux
Instance
[ec2-user ~]$ ec2-upload-bundle -b my-s3-bucket/bundle_folder/bundle_name
-m /tmp/image.manifest.xml -a your_access_key_id -s your_secret_access_key
--region us-west-2
4. (Optional) After the bundle is uploaded to Amazon S3, you can remove the bundle from the /tmp
directory on the instance using the following rm command:
Note
If you specified a path with the -d /path/to/bundle/storage option in Step 2.b (p. 76),
use that same path below, instead of /tmp.
[ec2-user ~]$ sudo rm /tmp/image.manifest.xml /tmp/image.part.* /tmp/image
5. Register your AMI using the ec2-register command. Note that you don't need to specify the -O and
-W options if you've set the AWS_ACCESS_KEY and AWS_SECRET_KEY environment variables.
Important
For HVM AMIs, add the --virtualization-type hvm flag.
[ec2-user ~]$ ec2-register my-s3-bucket/bundle_folder/bundle_name/image.mani
fest.xml -n AMI_name -O your_access_key_id -W your_secret_access_key --region
us-west-2
Converting your Instance Store-Backed AMI to an
Amazon EBS-Backed AMI
You can convert an instance store-backed Linux AMI that you own to an Amazon EBS-backed Linux AMI.
Important
You can't convert an instance store-backed Windows AMI to an Amazon EBS-backed Windows
AMI and you cannot convert an AMI that you do not own.
To convert an instance store-backed AMI to an Amazon EBS-backed AMI
1. Launch an Amazon Linux instance from an Amazon EBS-backed AMI. For more information, see
Launching an Instance (p. 300). Amazon Linux instances have the Amazon EC2 command line and
AMI tools pre-installed.
2. Upload the X.509 private key that you used to bundle your instance store-backed AMI to your instance.
We use this key to ensure that only you and Amazon EC2 can access your AMI.
a. Create a temporary directory on your instance for your X.509 private key as follows:
[ec2-user ~]$ mkdir /tmp/cert
b. Copy your X.509 private key from your computer to the /tmp/cert directory on your instance,
using a secure copy tool such as scp (p. 310). The my-private-key parameter in the following
command is the private key you use to connect to your instance with SSH. For example:
you@your_computer:~ $ scp -i my-private-key.pem /path/to/pk-HKZYK
TAIG2ECMXYIBH3HXV4ZBEXAMPLE.pem [email protected]
API Version 2014-02-01
77
Amazon Elastic Compute Cloud User Guide
Converting your Instance Store-Backed AMI to an
Amazon EBS-Backed AMI
1.amazonaws.com:/tmp/cert/
pk-HKZYKTAIG2ECMXYIBH3HXV4ZBEXAMPLE.pem 100% 717 0.7KB/s 00:00
3. Set environment variables for your AWS access key and secret key.
[ec2-user ~]$ export AWS_ACCESS_KEY=your_access_key_id
[ec2-user ~]$ export AWS_SECRET_KEY=your_secret_access_key
4. Prepare an Amazon EBS volume for your new AMI.
a. Create an empty Amazon EBS volume in the same Availability Zone as your instance using the
ec2-create-volume command. Note the volume ID in the command output.
Important
This Amazon EBS volume must be the same size or larger than the original instance
store root volume.
[ec2-user ~]$ ec2-create-volume --size 10 --region us-west-2 --availab
ility-zone us-west-2b
VOLUME volume_id 10 us-west-2b creating 2014-01-24T23:11:45+0000
standard
b. Attach the volume to your Amazon EBS-backed instance using the ec2-attach-volume command.
[ec2-user ~]$ ec2-attach-volume volume_id -i instance_id --device /dev/sdb
--region us-west-2
ATTACHMENT volume_id instance_id /dev/sdb attaching 2014-01-
24T23:15:34+0000
5. Create a folder for your bundle.
[ec2-user ~]$ mkdir /tmp/bundle
6. Download the bundle for your instance store-based AMI to /tmp/bundle using the
ec2-download-bundle command.
[ec2-user ~]$ ec2-download-bundle -b my-s3-bucket/bundle_folder/bundle_name
-m image.manifest.xml -a $AWS_ACCESS_KEY -s $AWS_SECRET_KEY --privatekey
/path/to/pk-HKZYKTAIG2ECMXYIBH3HXV4ZBEXAMPLE.pem -d /tmp/bundle
7. Reconstitute the image file from the bundle using the ec2-unbundle command.
a. Change directories to the bundle folder.
[ec2-user ~]$ cd /tmp/bundle/
b. Run the ec2-unbundle command.
API Version 2014-02-01
78
Amazon Elastic Compute Cloud User Guide
Converting your Instance Store-Backed AMI to an
Amazon EBS-Backed AMI
[ec2-user bundle]$ ec2-unbundle -m image.manifest.xml --privatekey
/path/to/pk-HKZYKTAIG2ECMXYIBH3HXV4ZBEXAMPLE.pem
8. Copy the files from the unbundled image to the new Amazon EBS volume.
[ec2-user bundle]$ sudo dd if=/tmp/bundle/image of=/dev/sdb bs=1M
9. Create a mount point for the new Amazon EBS volume and mount the volume.
[ec2-user bundle]$ sudo mkdir /mnt/ebs
[ec2-user bundle]$ sudo mount /dev/sdb /mnt/ebs
10. Open the /etc/fstab file on the EBS volume with your favorite text editor (such as vim or nano)
and remove any entries for instance store (ephemeral) volumes. Because the Amazon EBS volume
is mounted on /mnt/ebs, the fstab file is located at /mnt/ebs/etc/fstab.
[ec2-user bundle]$ sudo nano /mnt/ebs/etc/fstab
#
LABEL=/ / ext4 defaults,noatime 1 1
tmpfs /dev/shm tmpfs defaults 0 0
devpts /dev/pts devpts gid=5,mode=620 0 0
sysfs /sys sysfs defaults 0 0
proc /proc proc defaults 0 0
/dev/sdb /media/ephemeral0 auto defaults,comment=cloudconfig
0 2
In the above example, the last line should be removed.
11. Unmount the volume and detach it from the instance.
[ec2-user bundle]$ sudo umount /mnt/ebs
[ec2-user bundle]$ ec2-detach-volume volume_id --region us-west-2
ATTACHMENT volume_id instance_id /dev/sdb detaching 2014-01-24T23:15:34+0000
12. Create an AMI from the new Amazon EBS volume as follows.
a. Create a snapshot of the new Amazon EBS volume.
[ec2-user bundle]$ ec2-create-snapshot --region us-west-2 -d
"your_snapshot_description" -O $AWS_ACCESS_KEY -W $AWS_SECRET_KEY
volume_id
SNAPSHOT snapshot_id volume_id pending 2014-01-25T00:18:48+000
1234567891011 10 your_snapshot_description
b. Check to see that your snapshot is complete.
[ec2-user bundle]$ ec2-describe-snapshots --region us-west-2 snapshot_id
SNAPSHOT snapshot_id volume_id completed 2014-01-25T00:18:48+0000 100%
1234567891011 10 your_snapshot_description
API Version 2014-02-01
79
Amazon Elastic Compute Cloud User Guide
Converting your Instance Store-Backed AMI to an
Amazon EBS-Backed AMI
c. Identify the architecture and the kernel image (aki) used on the original AMI with the
ec2-describe-images command. You need the AMI ID of the original instance store-backed
AMI for this step.
[ec2-user bundle]$ ec2-describe-images --region us-west-2 ami-id
IMAGE ami-8ef297be amazon/amzn-ami-pv-2013.09.2.x86_64-s3 amazon available
public x86_64 machine aki-fc8f11cc instance-store paravirtual xen
In this example, the architecture is x86_64 and the kernel image ID is aki-fc8f11cc. Use
these values in the following step. If the output of the above command also lists an ari ID, take
note of that as well.
d. Register your new AMI with the snapshot ID of your new Amazon EBS volume and the values
from the previous step. If the previous command output listed an ari ID, include that in the
following command with --ramdisk ari_id.
[ec2-user bundle]$ ec2-register --region us-west-2 -n your_new_ami_name
-s snapshot_id -a x86_64 --kernel aki-fc8f11cc
IMAGE new-ami-id
13. (Optional) After you have tested that you can launch an instance from your new AMI, you can delete
the Amazon EBS volume that you created for this procedure.
$ ec2-delete-volume volume_id
Copying an AMI
You can easily copy the Amazon Machine Images (AMIs) that you own to other AWS regions and scale
your applications to take advantage of AWS's geographically diverse regions.
Copying your AMIs provides the following benefits:
Consistent global deployment: You can copy an AMI from one region to another, enabling you to launch
consistent instances based from the same AMI into different regions.
Scalability: You can more easily design and build world-scale applications that meet the needs of your
users, regardless of their location.
Performance: You can increase performance by distributing your application, as well as locating critical
components of your application in closer proximity to your users. You can also take advantage of
region-specific features, such as instance types or other AWS services.
High availability: You can design and deploy applications across AWS regions, to increase availability.
AMI Copy
You can copy both Amazon EBS-backed AMIs and instance-store-backed AMIs. You can copy an AMI
to as many regions as you like. You can also copy an AMI to the same region. Each copy of an AMI
results in a new AMI with its own unique AMI ID. When you launch an instance from an AMI, we launch
it into the same region as the AMI you select, as shown in the following diagram.
API Version 2014-02-01
80
Amazon Elastic Compute Cloud User Guide
Copying an AMI
When you copy an AMI, the new AMI is fully independent of the source AMI; there is no link to the original
(source) AMI. You can modify the new AMI without affecting the source AMI. The reverse is also true:
you can modify the source AMI without affecting the new AMI. Therefore, if you make changes to the
source AMI and want those changes to be reflected in the AMI in the destination region, you must recopy
the source AMI to the destination region.
We don't copy launch permissions, user-defined tags, or Amazon S3 bucket permissions from the source
AMI to the new AMI. After the copy operation is complete, you can apply launch permissions, user-defined
tags, and Amazon S3 bucket permissions to the new AMI.
We try to find matching AKIs and ARIs for the new AMI in the destination region. If we can't find a matching
AKI or ARI, then we don't copy the AMI. If you are using the AKIs and ARIs that we recommend, the copy
operation registers the AMI with the appropriate AKI and ARI in the destination region. If you get an error
message "Failed to find matching AKI/ARI", it means that the destination region doesn't contain an AKI
or ARI that matches those specified in the source AMI. If your AMI uses a PV-GRUB AKI, then you can
update the AMI to leverage the latest version of PV-GRUB. For more information on PV-GRUB and AKIs,
see Using Your Own Linux Kernels (p. 91).
There are no charges for copying an AMI. However, standard storage and data transfer rates apply.
Copying an Amazon EC2 AMI
Prior to copying an AMI, you must ensure that the contents of the source AMI are updated to support
running in a different region. For example, you should update any database connection strings or similar
application configuration data to point to the appropriate resources. Otherwise, instances launched from
the new AMI in the destination region may still use the resources from the source region, which can impact
performance and cost.
You can copy an AMI using the AWS Management Console or the command line.
To copy an AMI using the console
1. Open the Amazon EC2 console.
2. From the navigation bar, select the region that contains the AMI to copy.
3. In the navigation pane, click AMIs.
4. Select the AMI to copy, click Actions, and then click Copy AMI.
5. In the AMI Copy page, set the following fields, and then click Copy AMI:
Destination region: Select the region to which you want to copy the AMI.
Name: Specify a name for the new AMI.
Description: By default, the description includes information about the source AMI so that you
can identify a copy from the original. You can change this description as necessary.
API Version 2014-02-01
81
Amazon Elastic Compute Cloud User Guide
Copying an Amazon EC2 AMI
6. We display a confirmation page to let you know that the copy operation has been initiated and provide
you with the ID of the new AMI.
To check on the progress of the copy operation immediately, click the provided link to switch to the
destination region. To check on the progress later, click Done, and then when you are ready, use
the navigation pane to switch to the destination region.
The initial status of the destination AMI is pending and the operation is complete when the status
is available.
To copy an AMI using the command line
Copying an AMI from the command line requires that you specify both the source and destination regions.
You specify the source region using the --source-region parameter. For the destination region, you
have two options:
Use the --region parameter.
Set an environmental variable. For more information, see Setting up the CLI Tools (Linux) and Setting
up the CLI Tools (Windows).
You can copy an AMI using one of the following commands. For more information about these command
line interfaces, see Accessing Amazon EC2 (p. 3).
copy-image (AWS CLI)
ec2-copy-image (Amazon EC2 CLI)
Copy-EC2Image (AWS Tools for Windows PowerShell)
Stopping a Pending AMI Copy Operation
You can stop a pending AMI copy using the AWS Management Console or the command line.
To stop an AMI copy operation using the console
1. Open the Amazon EC2 console.
2. From the navigation bar, select the destination region from the region selector.
3. In the navigation pane, click AMIs.
4. Select the AMI you want to stop copying, click Actions, and then click Deregister.
5. When asked for confirmation, click Continue.
To stop an AMI copy operation using the command line
You can use one of the following commands. For more information about these command line interfaces,
see Accessing Amazon EC2 (p. 3).
deregister-image (AWS CLI)
ec2-deregister (Amazon EC2 CLI)
Unregister-EC2Image (AWS Tools for Windows PowerShell)
API Version 2014-02-01
82
Amazon Elastic Compute Cloud User Guide
Stopping a Pending AMI Copy Operation
Deregistering Your AMI
You can deregister an AMI when you have finished using it. After you deregister an AMI, you can't use
it to launch new instances.
When you deregister an AMI, it doesn't affect any instances that you've already launched from the AMI.
You'll continue to incur usage costs for these instances. Therefore, if you are finished with these instances,
you should terminate them.
The procedure that you'll use to clean up your AMI depends on whether it is backed by Amazon EBS or
instance store.
Topics
Cleaning Up Your Amazon EBS-Backed AMI (p. 83)
Cleaning Up Your Instance Store-Backed AMI (p. 84)
Cleaning Up Your Amazon EBS-Backed AMI
When you deregister an Amazon EBS-backed AMI, it doesn't affect the snapshot that we created when
you created the AMI. You'll continue to incur usage costs for this snapshot in Amazon EBS. Therefore,
if you are finished with the snapshot, you should delete it.
The following diagram illustrates the process for cleaning up your Amazon EBS-backed AMI.
To clean up your Amazon EBS-backed AMI
1. Open the Amazon EC2 console.
2. In the navigation pane, click AMIs. Select the AMI, click Actions, and then click Deregister. When
prompted for confirmation, click Continue.
The AMI status is now unavailable.
3. In the navigation pane, click Snapshots. Select the snapshot and click Delete Snapshot. When
prompted for confirmation, click Yes, Delete.
4. (Optional) If you are finished with an instance that you launched from the AMI, terminate it. In the
navigation pane, click Instances. Select the instance, click Actions, and then click Terminate. When
prompted for confirmation, click Yes, Terminate.
API Version 2014-02-01
83
Amazon Elastic Compute Cloud User Guide
Deregistering Your AMI
Cleaning Up Your Instance Store-Backed AMI
When you deregister an instance store-backed AMI, it doesn't affect the files that you uploaded to Amazon
S3 when you created the AMI.You'll continue to incur usage costs for these files in Amazon S3. Therefore,
if you are finished with these files, you should delete them.
The following diagram illustrates the process for cleaning up your instance store-backed AMI.
To clean up your instance store-backed AMI
1. Deregister the AMI using the ec2-deregister command as follows.
ec2-deregister ami_id
The AMI status is now unavailable.
2. Delete the bundle using the ec2-delete-bundle command as follows.
ec2-delete-bundle -b myawsbucket/myami -a your_access_key_id -s
your_secret_access_key -p image
3. (Optional) If you are finished with an instance that you launched from the AMI, you can terminate it
using the ec2-terminate-instances command as follows.
ec2-terminate-instances instance_id
4. (Optional) If you are finished with the Amazon S3 bucket that you uploaded the bundle to, you can
delete the bucket. To delete an Amazon S3 bucket, open the Amazon S3 console, select the bucket,
click Actions, and then click Delete.
Amazon Linux
Amazon Linux is provided by Amazon Web Services (AWS). It is designed to provide a stable, secure,
and high-performance execution environment for applications running on Amazon EC2. It also includes
packages that enable easy integration with AWS, including launch configuration tools and many popular
AWS libraries and tools. AWS provides ongoing security and maintenance updates to all instances running
Amazon Linux.
API Version 2014-02-01
84
Amazon Elastic Compute Cloud User Guide
Cleaning Up Your Instance Store-Backed AMI
To launch an Amazon Linux instance, use an Amazon Linux AMI. AWS provides Amazon Linux AMIs to
Amazon EC2 users at no additional cost.
Topics
Finding the Amazon Linux AMI (p. 85)
Launching and Connecting to an Amazon Linux Instance (p. 85)
Identifying Amazon Linux AMI Images (p. 85)
Included AWS Command Line Tools (p. 86)
cloud-init (p. 87)
Repository Configuration (p. 88)
Adding Packages (p. 89)
Accessing Source Packages for Reference (p. 89)
Developing Applications (p. 90)
Instance Store Access (p. 90)
Product Life Cycle (p. 90)
Security Updates (p. 90)
Support (p. 91)
Finding the Amazon Linux AMI
For a list of the latest Amazon Linux AMIs, see Amazon Linux AMIs.
Launching and Connecting to an Amazon Linux
Instance
After locating your desired AMI, note the AMI ID. You can use the AMI ID to launch and then connect to
your instance.
Amazon Linux does not allow remote root SSH by default. Also, password authentication is disabled to
prevent brute-force password attacks. To enable SSH logins to an Amazon Linux instance, you must
provide your key pair to the instance at launch. You must also set the security group used to launch your
instance to allow SSH access. By default, the only account that can log in remotely using SSH is ec2-user;
this account also has sudo privileges. If you want to enable remote root log in, please be aware that it is
less secure than relying on key pairs and a secondary user.
For information about launching and using your Amazon Linux instance, see Launch Your Instance (p. 300).
For information about connecting to your Amazon Linux instance, see Connecting to Your Linux/Unix
Instance (p. 309).
Identifying Amazon Linux AMI Images
Each image contains a unique /etc/image-id that identifies the AMI. This file contains information
about the image.
The following is an example of the /etc/image-id file:
[ec2-user ~]$ cat /etc/image-id
image_name="amzn-ami-pv"
image_version="2014.03"
image_arch="x86_64"
API Version 2014-02-01
85
Amazon Elastic Compute Cloud User Guide
Finding the Amazon Linux AMI
image_file="amzn-ami-pv-2014.03.rc-1.x86_64.ext4"
image_stamp="6270-181c"
image_date="20140320044105"
recipe_name="amzn ami"
recipe_id="5f291ea8-31de-0e3c-05c2-8f26-942c-852a-0d5f98fa"
The image_name, image_version, and image_arch items come from the build recipe that Amazon
used to construct the image. The image_stamp is simply a unique random hex value generated during
image creation. The image_date item is in YYYYMMDDhhmmss format, and is the UTC time of image
creation. The recipe_name and recipe_id refer to the name and ID of the build recipe Amazon used
to construct the image, which identifies the current running version of Amazon Linux. This file will not
change as you install updates from the yum repository.
Amazon Linux contains an /etc/system-release file that specifies the current release that is installed.
This file is updated through yum and is part of the system-release RPM.
The following is an example of an /etc/system-release file:
[ec2-user ~]$ cat /etc/system-release
Amazon Linux AMI release 2014.03
Amazon Linux also contains a machine readable version of the /etc/system-release file found in
/etc/system-release-cpe and follows the CPE specification from MITRE (CPE).
Included AWS Command Line Tools
The following popular command line tools for AWS integration and usage have been included in Amazon
Linux or in the default repositories:
aws-amitools-ec2
aws-apitools-as
aws-apitools-cfn
aws-apitools-common
aws-apitools-ec2
aws-apitools-elb
aws-apitools-iam
aws-apitools-mon
aws-apitools-rds
aws-cfn-bootstrap
aws-cli
aws-scripts-ses
To simplify the configuration of these tools, a simple script has been included to prepare
AWS_CREDENTIAL_FILE, JAVA_HOME, AWS_PATH, PATH, and product-specific environment variables
after a credential file has been installed.
Also, to allow the installation of multiple versions of the API and AMI tools, we have placed symbolic links
to the desired versions of these tools in /opt/aws, as described here:
/opt/aws/bin
Symbolic links to /bin directories in each of the installed tools directories.
API Version 2014-02-01
86
Amazon Elastic Compute Cloud User Guide
Included AWS Command Line Tools
/opt/aws/{apitools|amitools}
Products are installed in directories of the form name-version and a symbolic link name that is
attached to the most recently installed version.
/opt/aws/{apitools|amitools}/name/environment.sh
Used by /etc/profile.d/aws-apitools-common.sh to set product-specific environment
variables, such as EC2_HOME.
cloud-init
The cloud-init package is an open source application built by Canonical that is used to bootstrap
Linux images in a cloud computing environment, such as Amazon EC2. Amazon Linux contains a
customized version of cloud-init. It enables you to specify actions that should happen to your instance
at boot time. You can pass desired actions to cloud-init through the user data fields when launching
an instance. This means you can use common AMIs for many use cases and configure them dynamically
at startup. Amazon Linux also uses cloud-init to perform initial configuration of the ec2-user account.
For more information about cloud-init, see https://help.ubuntu.com/community/CloudInit.
Amazon Linux uses the following cloud-init actions (configurable in /etc/sysconfig/cloudinit):
action: INIT (always runs)
Sets a default locale
Sets the hostname
Parses and handles user data
action: CONFIG_SSH
Generates host private SSH keys
Adds a user's public SSH keys to .ssh/authorized_keys for easy login and administration
action: PACKAGE_SETUP
Prepares yum repo
Handles package actions defined in user data
action: RUNCMD
Runs a shell command
action: RUN_USER_SCRIPTS
Executes user scripts found in user data
action: CONFIG_MOUNTS
Mounts ephemeral drives
action: CONFIG_LOCALE
Sets the locale in the locale configuration file according to user data
Supported User-Data Formats
The cloud-init package supports user-data handling of a variety of formats:
Gzip
If user-data is gzip compressed, cloud-init decompresses the data and handles it appropriately.
MIME multipart
Using a MIME multipart file, you can specify more than one type of data. For example, you could
specify both a user-data script and a cloud-config type. Each part of the multipart file can be handled
by cloud-init if it is one of the supported formats.
Base64 decoding
API Version 2014-02-01
87
Amazon Elastic Compute Cloud User Guide
cloud-init
If user-data is base64-encoded, cloud-init determines if it can understand the decoded data as
one of the supported types. If it understands the decoded data, it decodes the data and handles it
appropriately. If not, it returns the base64 data intact.
User-Data script
Begins with #! or Content-Type: text/x-shellscript.
The script is executed by /etc/init.d/cloud-init-user-scripts during the first boot cycle.
This occurs late in the boot process (after the initial configuration actions are performed).
Include file
Begins with #include or Content-Type: text/x-include-url.
This content is an include file. The file contains a list of URLs, one per line. Each of the URLs is read,
and their content passed through this same set of rules. The content read from the URL can be
gzipped, MIME-multi-part, or plain text.
Cloud Config Data
Begins with #cloud-config or Content-Type: text/cloud-config.
This content is cloud-config data. See the examples for a commented example of supported
configuration formats.
Cloud Boothook
Begins with #cloud-boothook or Content-Type: text/cloud-boothook.
This content is boothook data. It is stored in a file under /var/lib/cloud and then executed
immediately.
This is the earliest "hook" available. Note that there is no mechanism provided for running it only one
time. The boothook must take care of this itself. It is provided with the instance ID in the environment
variable INSTANCE_ID. Use this variable to provide a once-per-instance set of boothook data.
Repository Configuration
Beginning with the 2011.09 release of Amazon Linux, Amazon Linux AMIs are treated as snapshots in
time, with a repository and update structure that always gives you the latest packages when you run yum
update -y.
The repository structure is configured to deliver a continuous flow of updates that allow you to roll from
one version of Amazon Linux to the next. For example, if you launch an instance from an older version
of the Amazon Linux AMI (such as 2013.09 or earlier) and run yum update -y, you end up with the
latest packages.
You can disable rolling updates for Amazon Linux by enabling the lock-on-launch feature. The
lock-on-launch feature locks your newly launched instance to receive updates only from the specified
release of the AMI. For example, you can launch a 2013.09 AMI and have it receive only the updates
that were released prior to the 2014.03 AMI, until you are ready to migrate to the 2014.03 AMI. To enable
lock-on-launch in new instances, launch it with the following user data passed to cloud-init, using
either the Amazon EC2 console or the ec2-run-instances command with the -f flag.
#cloud-config
repo_releasever: 2013.09
To lock existing instances to their current AMI release version
1. Edit /etc/yum.conf.
2. Comment out releasever=latest.
3. Run yum clean all to clear the cache.
API Version 2014-02-01
88
Amazon Elastic Compute Cloud User Guide
Repository Configuration
Adding Packages
Amazon Linux is designed to be used with online package repositories hosted in each Amazon EC2
region. These repositories provide ongoing updates to packages in the Amazon Linux AMI, as well as
access to hundreds of additional common open source server applications. The repositories are available
in all regions and are accessed using yum update tools, as well as on the Amazon Linux AMI packages
site. Hosting repositories in each region enables us to deploy updates quickly and without any data transfer
charges. The packages can be installed by issuing yum commands, such as the following example:
[ec2-user ~]$ sudo yum install httpd
Access to the Extra Packages for Enterprise Linux (EPEL) repository is configured, but it is not enabled
by default. EPEL provides third-party packages in addition to those that are in the Amazon Linux
repositories. The third-party packages are not supported by AWS.
If you find that Amazon Linux does not contain an application you need, you can simply install the
application directly on your Amazon Linux instance. Amazon Linux uses RPMs and yum for package
management, and that is likely the simplest way to install new applications. You should always check to
see if an application is available in our central Amazon Linux repository first, because many applications
are available there. These applications can easily be added to your Amazon Linux instance.
To upload your applications onto a running Amazon Linux instance, use scp or sftp and then configure
the application by logging on to your instance.Your applications can also be uploaded during the instance
launch by using the PACKAGE_SETUP action from the built-in cloud-init package. For more information,
see cloud-init (p. 87).
Important
If your instance is running in a virtual private cloud (VPC), you must attach an Internet Gateway
to the VPC in order to contact the yum repository. For more information, see Internet Gateways
in the Amazon Virtual Private Cloud User Guide.
Accessing Source Packages for Reference
You can view the source of packages you have installed on your instance for reference purposes by using
tools provided in Amazon Linux. Source packages are available for all of the packages included in Amazon
Linux and the online package repository. Simply determine the package name for the source package
you want to install and use the get_reference_source command to view source within your running
instance. For example:
[ec2-user ~]$ get_reference_source -p bash
The following is a sample response:
Requested package: bash
Found package from local RPM database: bash-4.1.2-15.17.amzn1.x86_64
Corresponding source RPM to found package :
bash-4.1.2-15.17.amzn1.src.rpm
Are these parameters correct? Please type 'yes' to continue: yes
Source RPM downloaded to:
/usr/src/srpm/debug/bash-4.1.2-15.17.amzn1.src.rpm
The source RPM is placed in the /usr/src/srpm/debug directory of your instance. From there, it can
be unpacked, and, for reference, you can view the source tree using standard RPM tools. After you finish
debugging, the package is available for use.
API Version 2014-02-01
89
Amazon Elastic Compute Cloud User Guide
Adding Packages
Important
If your instance is running in a virtual private cloud (VPC), you must attach an Internet Gateway
to the VPC in order to contact the yum repository. For more information, see Internet Gateways
in the Amazon Virtual Private Cloud User Guide.
Developing Applications
A full set of Linux development tools is provided in the yum repository for Amazon Linux. To develop
applications on Amazon Linux, select the development tools you need with yum. Alternatively, many
applications developed on CentOS and other similar distributions should run on Amazon Linux.
Instance Store Access
The instance store drive ephemeral0 is mounted in /media/ephemeral0 only on Amazon instance
store-backed AMIs. This is different than many other images that mount the instance store drive under
/mnt.
Product Life Cycle
The Amazon Linux AMI is updated regularly with security and feature enhancements. If you do not need
to preserve data or customizations on your Amazon Linux instances, you can simply relaunch new
instances with the latest Amazon Linux AMI. If you need to preserve data or customizations for your
Amazon Linux instances, you can maintain those instances through the Amazon Linux yum repositories.
The yum repositories contain all the updated packages. You can chose to apply these updates to your
running instances.
Older versions of the AMI and update packages will continue to be available for use, even as new versions
are released. In some cases, if you're seeking support for an older version of Amazon Linux; through
AWS Support, we might ask you to move to newer versions as part of the support process.
Security Updates
Security updates are provided via the Amazon Linux AMI yum repositories as well as via updated Amazon
Linux AMIs. Security alerts are published in the Amazon Linux AMI Security Center. For more information
on AWS security policies or to report a security problem, go to the AWS Security Center.
Amazon Linux AMIs are configured to download and install security updates at launch time. This is
controlled via a cloud-init setting called repo_upgrade. The following snippet of cloud-init
configuration shows how you can change the settings in the user data text you pass to your instance
initialization:
#cloud-config
repo_upgrade: security
The possible values for the repo_upgrade setting are as follows:
security
Apply outstanding updates that Amazon marks as security updates.
bugfix
Apply updates that Amazon marks as bug fixes. Bug fixes are a larger set of updates, which include
security updates and fixes for various other minor bugs.
all
Apply all applicable available updates, regardless of their classification.
API Version 2014-02-01
90
Amazon Elastic Compute Cloud User Guide
Developing Applications
none
Do not apply any updates to the instance on startup.
The default setting for repo_upgrade is security. That is, if you don't specify a different value in your
user data, by default, the Amazon Linux AMI performs the security upgrades at launch for any packages
installed at that time. The Amazon Linux AMI also notifies you of any updates to the installed packages
by listing the number of available updates upon login using the /etc/motd file. To install these updates,
you need to run sudo yum upgrade on the instance.
Important
If your instance is running in a virtual private cloud (VPC), you must attach an Internet Gateway
to the VPC in order to contact the yum repository. For more information, see Internet Gateways
in the Amazon Virtual Private Cloud User Guide.
Support
Support for installation and use of the base Amazon Linux AMI is included through subscriptions to AWS
Support. For more information, see AWS Support.
We encourage you to post any questions you have about Amazon Linux to the Amazon EC2 forum.
Using Your Own Linux Kernels
To enable user-provided kernels on instances, Amazon has published Amazon Kernel Images (AKIs)
that use a system called PV-GRUB. PV-GRUB is a paravirtual boot loader that runs a patched version
of GNU GRUB 0.97. When you start an instance, PV-GRUB loads the kernel specified by your image's
menu.lst file.
PV-GRUB understands standard grub.conf or menu.lst commands, which allows it to work with all
currently supported Linux distributions. Older distributions such as Ubuntu 10.04 LTS, Oracle Enterprise
Linux or CentOS 5.x require a special "ec2" or "xen" kernel package, while newer distributions include
the required drivers in the default kernel package.
Most modern paravirtual AMIs use a PV-GRUB AKI by default (including all of the paravirtual Linux AMIs
available in the Amazon EC2 Launch Wizard Quick Start menu), so there are no additional steps that
you need to take to use a different kernel on your instance, provided that the kernel you want to use is
compatible with your distribution. You can verify that the kernel image for an AMI is a PV-GRUB AKI by
executing the following command with the Amazon EC2 command line tools (substituting the kernel image
ID you want to check):
$ ec2-describe-images -a -F image-id=aki-880531cd
IMAGE aki-880531cd amazon/pv-grub-hd0_1.04-x86_64.gz ...
The name field of the output should contain pv-grub.
Topics
Limitations of PV-GRUB (p. 92)
Configuring GRUB (p. 92)
Amazon PV-GRUB Kernel Image IDs (p. 93)
Updating PV-GRUB (p. 95)
API Version 2014-02-01
91
Amazon Elastic Compute Cloud User Guide
Support
Limitations of PV-GRUB
PV-GRUB has the following limitations:
You can't use the 64-bit version of PV-GRUB to start a 32-bit kernel or vice versa.
You can't specify an Amazon ramdisk image (ARI) when using a PV-GRUB AKI.
AWS has tested and verified that PV-GRUB works with these file system formats: EXT2, EXT3, EXT4,
JFS, XFS, and ReiserFS. Other file system formats might not work.
PV-GRUB can boot kernels compressed using the gzip, bzip2, lzo, and xz compression formats.
Cluster AMIs don't support or need PV-GRUB, because they use full hardware virtualization (HVM).
While paravirtual instances use PV-GRUB to boot, HVM instance volumes are treated like actual disks,
and the boot process is similar to the boot process of a bare metal operating system with a partitioned
disk and bootloader.
PV-GRUB versions 1.03 and earlier don't support GPT partitioning; they support MBR partitioning only.
If you plan to use a logical volume manager (LVM) with Amazon EBS volumes, you need a separate
boot partition outside of the LVM. Then you can create logical volumes with the LVM.
Configuring GRUB
To boot PV-GRUB, a GRUB menu.lst file must exist in the image; the most common location for this
file is /boot/grub/menu.lst.
The following is an example of a menu.lst configuration file for booting an AMI with a PV-GRUB AKI.
In this example, there are two kernel entries to choose from: Amazon Linux 2013.09 (the original
kernel for this AMI), and Vanilla Linux 3.11.6 (a newer version of the Vanilla Linux kernel from
https://www.kernel.org/). The Vanilla entry was copied from the original entry for this AMI, and the kernel
and initrd paths were updated to the new locations. The default 0 parameter points the boot loader
to the first entry it sees (in this case, the Vanilla entry), and the fallback 1 parameter points the
bootloader to the next entry if there is a problem booting the first.
default 0
fallback 1
timeout 0
hiddenmenu
title Vanilla Linux 3.11.6
root (hd0)
kernel /boot/vmlinuz-3.11.6 root=LABEL=/ console=hvc0
initrd /boot/initrd.img-3.11.6
title Amazon Linux 2013.09 (3.4.62-53.42.amzn1.x86_64)
root (hd0)
kernel /boot/vmlinuz-3.4.62-53.42.amzn1.x86_64 root=LABEL=/ console=hvc0
initrd /boot/initramfs-3.4.62-53.42.amzn1.x86_64.img
You don't need to specify a fallback kernel in your menu.lst file, but we recommend that you have a
fallback when you test a new kernel. PV-GRUB can fall back to another kernel in the event that the new
kernel fails. Having a fallback kernel allows the instance to boot even if the new kernel isn't found.
PV-GRUB checks the following locations for menu.lst, using the first one it finds:
(hd0)/boot/grub
(hd0,0)/boot/grub
API Version 2014-02-01
92
Amazon Elastic Compute Cloud User Guide
Limitations of PV-GRUB
(hd0,0)/grub
(hd0,1)/boot/grub
(hd0,1)/grub
(hd0,2)/boot/grub
(hd0,2)/grub
(hd0,3)/boot/grub
(hd0,3)/grub
Note that PV-GRUB 1.03 and earlier only check one of the first two locations in this list.
Amazon PV-GRUB Kernel Image IDs
PV-GRUB AKIs are available in all Amazon EC2 regions. There are AKIs for both 32-bit and 64-bit
architecture types. Most modern AMIs use a PV-GRUB AKI by default.
We recommend that you always use the latest version of the PV-GRUB AKI, as not all versions of the
PV-GRUB AKI are compatible with all instance types. Use the following command to get a list of the
PV-GRUB AKIs for the current region:
$ ec2-describe-images -o amazon --filter "name=pv-grub-*.gz"
Note that PV-GRUB is the only AKI available in the ap-southeast-2 region. You should verify that any
AMI you want to copy to this region is using a version of PV-GRUB that is available in this region.
The following are the current AKI IDs for each region. There is no longer any difference between the hd0
and hd00 AKIs, though we continue to provide both naming schemes for backward compatibility. You
should register new AMIs using an hd0 AKI.
ap-northeast-1, Asia Pacific (Tokyo) Region
Image Name Image ID
pv-grub-hd0_1.04-i386.gz aki-136bf512
pv-grub-hd0_1.04-x86_64.gz aki-176bf516
pv-grub-hd00_1.04-i386.gz aki-196bf518
pv-grub-hd00_1.04-x86_64.gz aki-1f6bf51e
ap-southeast-1, Asia Pacific (Singapore) Region
Image Name Image ID
pv-grub-hd0_1.04-i386.gz aki-ae3973fc
pv-grub-hd0_1.04-x86_64.gz aki-503e7402
pv-grub-hd00_1.04-i386.gz aki-563e7404
pv-grub-hd00_1.04-x86_64.gz aki-5e3e740c
API Version 2014-02-01
93
Amazon Elastic Compute Cloud User Guide
Amazon PV-GRUB Kernel Image IDs
ap-southeast-2, Asia Pacific (Sydney) Region
Image Name Image ID
pv-grub-hd0_1.04-i386.gz aki-cd62fff7
pv-grub-hd0_1.04-x86_64.gz aki-c362fff9
pv-grub-hd00_1.04-i386.gz aki-c162fffb
pv-grub-hd00_1.04-x86_64.gz aki-3b1d8001
eu-west-1, EU (Ireland) Region
Image Name Image ID
pv-grub-hd0_1.04-i386.gz aki-68a3451f
pv-grub-hd0_1.04-x86_64.gz aki-52a34525
pv-grub-hd00_1.04-i386.gz aki-5ea34529
pv-grub-hd00_1.04-x86_64.gz aki-58a3452f
sa-east-1, South America (Sao Paulo) Region
Image Name Image ID
pv-grub-hd0_1.04-i386.gz aki-5b53f446
pv-grub-hd0_1.04-x86_64.gz aki-5553f448
pv-grub-hd00_1.04-i386.gz aki-5753f44a
pv-grub-hd00_1.04-x86_64.gz aki-5153f44c
us-east-1, US East (Northern Virginia) Region
Image Name Image ID
pv-grub-hd0_1.04-i386.gz aki-8f9dcae6
pv-grub-hd0_1.04-x86_64.gz aki-919dcaf8
pv-grub-hd00_1.04-i386.gz aki-659ccb0c
pv-grub-hd00_1.04-x86_64.gz aki-499ccb20
us-gov-west-1, AWS GovCloud (US)
Image Name Image ID
pv-grub-hd0_1.04-i386.gz aki-1fe98d3c
pv-grub-hd0_1.04-x86_64.gz aki-1de98d3e
pv-grub-hd00_1.04-i386.gz aki-63e98d40
API Version 2014-02-01
94
Amazon Elastic Compute Cloud User Guide
Amazon PV-GRUB Kernel Image IDs
Image Name Image ID
pv-grub-hd00_1.04-x86_64.gz aki-61e98d42
us-west-1, US West (Northern California) Region
Image Name Image ID
pv-grub-hd0_1.04-i386.gz aki-8e0531cb
pv-grub-hd0_1.04-x86_64.gz aki-880531cd
pv-grub-hd00_1.04-i386.gz aki-960531d3
pv-grub-hd00_1.04-x86_64.gz aki-920531d7
us-west-2, US West (Oregon) Region
Image Name Image ID
pv-grub-hd0_1.04-i386.gz aki-f08f11c0
pv-grub-hd0_1.04-x86_64.gz aki-fc8f11cc
pv-grub-hd00_1.04-i386.gz aki-e28f11d2
pv-grub-hd00_1.04-x86_64.gz aki-e68f11d6
Updating PV-GRUB
We recommend that you always use the latest version of the PV-GRUB AKI, as not all versions of the
PV-GRUB AKI are compatible with all instance types. Also, older versions of PV-GRUB are not available
in all regions, so if you copy an AMI that uses an older version to a region that does not support that
version, you will be unable to boot instances launched from that AMI until you update the kernel image.
Use the following procedures to check your instance's version of PV-GRUB and update it if necessary.
To check your PV-GRUB version
1. Find the kernel ID for your instance.
$ ec2-describe-instance-attribute instance_id --kernel --region region
kernel instance_id aki-fc8f11cc
The kernel ID for this instance is aki-fc8f11cc.
2. View the version information of that kernel ID.
$ ec2-describe-images aki-fc8f11cc --region region
IMAGE aki-fc8f11cc amazon/pv-grub-hd0_1.04-x86_64.gz ...
This kernel image is PV-GRUB 1.04. If your PV-GRUB version is not the newest version (as shown
in Amazon PV-GRUB Kernel Image IDs (p. 93)), you should update it using the following procedure.
API Version 2014-02-01
95
Amazon Elastic Compute Cloud User Guide
Updating PV-GRUB
To update your PV-GRUB version
If your instance is using an older version of PV-GRUB, you should update it to the latest version.
1. Identify the latest PV-GRUB AKI for your region and processor architecture from Amazon PV-GRUB
Kernel Image IDs (p. 93).
2. Stop your instance. Your instance must be stopped to modify the kernel image used.
$ ec2-stop-instances instance_id --region region
INSTANCE instance_id stopped stopped
3. Modify the kernel image used for your instance.
$ ec2-modify-instance-attribute --kernel kernel_id --region region instance_id
4. Restart your instance.
$ ec2-start-instances --region region instance_id
API Version 2014-02-01
96
Amazon Elastic Compute Cloud User Guide
Updating PV-GRUB
Amazon EC2 Instances
If you're new to Amazon EC2, see the following topics to get started:
What Is Amazon EC2? (p. 1)
Setting Up with Amazon EC2 (p. 19)
Getting Started with Amazon EC2 Linux Instances (p. 24)
Getting Started with Amazon EC2 Windows Instances
Instance Lifecycle (p. 297)
Before you launch a production environment, you need to answer the following questions.
Q. What purchasing option best meets my needs?
Amazon EC2 supports On-Demand Instances (the default), Spot Instances (p. 121), and Reserved
Instances (p. 198). For more information, see Amazon EC2 Pricing.
Q. What instance type best meets my needs?
Amazon EC2 provides different instance types to enable you to choose the CPU, memory, storage,
and networking capacity that you need to run your applications. For more information, see Instance
Types (p. 97).
Q. Which type of root volume meets my needs?
Each instance is backed by Amazon EBS or backed by instance store. Select an AMI based on which
type of root volume you need. For more information, see Storage for the Root Device (p. 50).
Q. Would I benefit from using a virtual private cloud?
If you can launch instances in either EC2-Classic or EC2-VPC, you'll need to decide which platform
meets your needs. For more information, see Supported Platforms (p. 487) and Amazon EC2 and
Amazon Virtual Private Cloud (VPC) (p. 485).
Instance Types
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. Select an instance type based on the requirements of the application or software that you
plan to run on your instance.
Amazon EC2 provides each instance with a consistent and predictable amount of CPU capacity, regardless
of its underlying hardware.
API Version 2014-02-01
97
Amazon Elastic Compute Cloud User Guide
Instance Types
Amazon EC2 dedicates some resources of the host computer, such as CPU, memory, and instance
storage, to a particular instance. Amazon EC2 shares other resources of the host computer, such as the
network and the disk subsystem, among instances. If each instance on a host computer tries to use as
much of one of these shared resources as possible, each receives an equal share of that resource.
However, when a resource is under-utilized, an instance can consume a higher share of that resource
while it's available.
Each instance type provides higher or lower minimum performance from a shared resource. For example,
instance types with high I/O performance have a larger allocation of shared resources. Allocating a larger
share of shared resources also reduces the variance of I/O performance. For most applications, moderate
I/O performance is more than enough. However, for applications that require greater or more consistent
I/O performance, consider an instance type with higher I/O performance.
The maximum transmission unit (MTU) for an instance depends on its instance type. The following instance
types provide 9001 MTU (jumbo frames): CC2, C3, R3, CG1, CR1, G2, HS1, HI1, I2, and M3. The other
instance types provide 1500 MTU (Ethernet v2 frames).
To obtain additional, dedicated capacity for Amazon EBS I/O, you can launch some instance types as
Amazon EBS-optimized instances. For more information, see Amazon EBS-Optimized Instances (p. 114).
To optimize your instances for high performance computing (HPC) applications, you can launch some
instance types in a placement group. For more information, see Placement Groups (p. 115).
When you launch your instance, it uses one of two types of virtualization: paravirtual (PV) or hardware
virtual machine (HVM). The virtualization type is determined by the AMI used to launch the instance;
some instance types support both PV and HVM while others support only one or the other. HVM
virtualization uses hardware-assist technology provided by the AWS platform. With HVM virtualization,
the guest VM runs as if it were on a native hardware platform, except that it still uses PV network and
storage drivers for improved performance.
Available Instance Types
Amazon EC2 provides the instance types listed in the following table.
Instance Types Instance Family
m1.small | m1.medium | m1.large | m1.xlarge | m3.medium |
m3.large | m3.xlarge | m3.2xlarge
General purpose
c1.medium | c1.xlarge | c3.large | c3.xlarge | c3.2xlarge
| c3.4xlarge | c3.8xlarge | cc2.8xlarge
Compute optimized
m2.xlarge | m2.2xlarge | m2.4xlarge | r3.large | r3.xlarge
| r3.2xlarge | r3.4xlarge | r3.8xlarge | cr1.8xlarge
Memory optimized
hi1.4xlarge | hs1.8xlarge | i2.xlarge | i2.2xlarge |
i2.4xlarge | i2.8xlarge
Storage optimized
t1.micro Micro instances
cg1.4xlarge | g2.2xlarge GPU instances
Hardware Specifications
For more information about the hardware specifications for each Amazon EC2 instance type, see Instance
Type Details.
API Version 2014-02-01
98
Amazon Elastic Compute Cloud User Guide
Available Instance Types
To determine which instance type best meets your needs, we recommend that you launch an instance
and use your own benchmark application. Because you pay by the instance hour, it's convenient and
inexpensive to test multiple instance types before making a decision. If your needs change, you can resize
your instance later on. For more information, see Resizing Your Instance (p. 118).
Micro Instances
Micro instances (t1.micro) provide a small amount of consistent CPU resources and allow you to
increase CPU capacity in short bursts when additional cycles are available. They are well suited for lower
throughput applications and websites that require additional compute cycles periodically.
The t1.micro instance is available as an Amazon EBS-backed instance only.
This documentation describes how t1.micro instances work so that you can understand how to apply
them. It's not our intent to specify exact behavior, but to give you visibility into the instance's behavior so
you can understand its performance (to a greater degree than you typically get with, for example, a
multi-tenant shared web hosting system).
Topics
Hardware Specifications (p. 99)
Optimal Application of Micro Instances (p. 99)
Available CPU Resources During Spikes (p. 101)
When the Instance Uses Its Allotted Resources (p. 102)
Comparison with the m1.small Instance Type (p. 103)
AMI Optimization for Micro Instances (p. 105)
Hardware Specifications
For more information about the hardware specifications for each Amazon EC2 instance type, see Instance
Type Details.
Optimal Application of Micro Instances
A t1.micro instance provides spiky CPU resources for workloads that have a CPU usage profile similar
to what is shown in the following figure.
API Version 2014-02-01
99
Amazon Elastic Compute Cloud User Guide
Micro Instances
The instance is designed to operate with its CPU usage at essentially only two levels: the normal low
background level, and then at brief spiked levels much higher than the background level. We allow the
instance to operate at up to 2 EC2 compute units (ECUs) (one ECU provides the equivalent CPU capacity
of a 1.0-1.2 GHz 2007 Opteron or 2007 Xeon processor). The ratio between the maximum level and the
background level is designed to be large. We designed t1.micro instances to support tens of requests
per minute on your application. However, actual performance can vary significantly depending on the
amount of CPU resources required for each request on your application.
Your application might have a different CPU usage profile than that described in the preceding section.
The next figure shows the profile for an application that isn't appropriate for a t1.micro instance. The
application requires continuous data-crunching CPU resources for each request, resulting in plateaus of
CPU usage that the t1.micro instance isn't designed to handle.
The next figure shows another profile that isn't appropriate for a t1.micro instance. Here the spikes in
CPU use are brief, but they occur too frequently to be serviced by a micro instance.
API Version 2014-02-01
100
Amazon Elastic Compute Cloud User Guide
Micro Instances
The next figure shows another profile that isn't appropriate for a t1.micro instance. Here the spikes
aren't too frequent, but the background level between spikes is too high to be serviced by a t1.micro
instance.
In each of the preceding cases of workloads not appropriate for a t1.micro instance, we recommend
that you consider using a different instance type. For more information about instance types, see Instance
Types (p. 97).
Available CPU Resources During Spikes
When your instance bursts to accommodate a spike in demand for compute resources, it uses unused
resources on the host. The amount available depends on how much contention there is when the spike
occurs. The instance is never left with zero CPU resources, whether other instances on the host are
spiking or not.
API Version 2014-02-01
101
Amazon Elastic Compute Cloud User Guide
Micro Instances
When the Instance Uses Its Allotted Resources
We expect your application to consume only a certain amount of CPU resources in a period of time. If
the application consumes more than your instance's allotted CPU resources, we temporarily limit the
instance so it operates at a low CPU level. If your instance continues to use all of its allotted resources,
its performance will degrade. We will increase the time that we limit its CPU level, thus increasing the
time before the instance is allowed to burst again.
If you enable CloudWatch monitoring for your t1.micro instance, you can use the "Avg CPU Utilization"
graph in the AWS Management Console to determine whether your instance is regularly using all its
allotted CPU resources. We recommend that you look at the maximum value reached during each given
period. If the maximum value is 100%, we recommend that you use Auto Scaling to scale out (with
additional t1.micro instances and a load balancer), or move to a larger instance type. For more
information, see the Auto Scaling Developer Guide.
The following figures show the three suboptimal profiles from the preceding section and what it might
look like when the instance consumes its allotted resources and we have to limit its CPU level. If the
instance consumes its allotted resources, we restrict it to the low background level.
The next figure shows the situation with the long plateaus of data-crunching CPU usage. The CPU hits
the maximum allowed level and stays there until the instance's allotted resources are consumed for the
period. At that point, we limit the instance to operate at the low background level, and it operates there
until we allow it to burst above that level again. The instance again stays there until the allotted resources
are consumed and we limit it again (not seen on the graph).
The next figure shows the situation where the requests are too frequent. The instance uses its allotted
resources after only a few requests and so we limit it. After we lift the restriction, the instance maxes out
its CPU usage trying to keep up with the requests, and we limit it again.
API Version 2014-02-01
102
Amazon Elastic Compute Cloud User Guide
Micro Instances
The next figure shows the situation where the background level is too high. Notice that the instance
doesn't have to be operating at the maximum CPU level for us to limit it. We limit the instance when it's
operating above the normal background level and has consumed its allotted resources for the given
period. In this case (as in the preceding one), the instance can't keep up with the work, and we limit it
again.
Comparison with the m1.small Instance Type
The t1.micro instance provides different levels of CPU resources at different times (up to 2 ECUs). By
comparison, the m1.small instance type provides 1 ECU at all times. The following figure illustrates the
difference.
API Version 2014-02-01
103
Amazon Elastic Compute Cloud User Guide
Micro Instances
The following figures compare the CPU usage of a t1.micro instance with an m1.small instance for
the various scenarios we've discussed in the preceding sections.
The first figure that follows shows an optimal scenario for a t1.micro instance (the left graph) and how
it might look for an m1.small instance (the right graph). In this case, we don't need to limit the t1.micro
instance. The processing time on the m1.small instance would be longer for each spike in CPU demand
compared to the t1.micro instance.
The next figure shows the scenario with the data-crunching requests that used up the allotted resources
on the t1.micro instance, and how they might look with the m1.small instance.
API Version 2014-02-01
104
Amazon Elastic Compute Cloud User Guide
Micro Instances
The next figure shows the frequent requests that used up the allotted resources on the t1.micro instance,
and how they might look on the m1.small instance.
The next figure shows the situation where the background level used up the allotted resources on the
t1.micro instance, and how it might look on the m1.small instance.
AMI Optimization for Micro Instances
We recommend that you follow these best practices when optimizing an AMI for the t1.micro instance
type:
Design the AMI to run on 600 MB of RAM
Limit the number of recurring processes that use CPU time (for example, cron jobs, daemons)
In Linux, you can optimize performance using swap space and virtual memory (for example, by setting
up swap space in a separate partition from the root file system).
API Version 2014-02-01
105
Amazon Elastic Compute Cloud User Guide
Micro Instances
In Windows, when you perform significant AMI or instance configuration changes (for example, enable
server roles or install large applications), you might see limited instance performance, because these
changes can be memory intensive and require long-running CPU resources. We recommend that you
first use a larger instance type when performing these changes to the AMI, and then run the AMI on a
t1.micro instance for normal operations.
I2 Instances
I2 instances are optimized to deliver tens of thousands of low-latency, random I/O operations per second
(IOPS) to applications. They are well suited for the following scenarios:
NoSQL databases (for example, Cassandra and MongoDB)
Clustered databases
Online transaction processing (OLTP) systems
You can cluster I2 instances in a placement group. Cluster placement groups provide low latency and
high-bandwidth connectivity between the instances within a single Availability Zone. For more information,
see Placement Groups (p. 115).
You can enable enhanced networking capabilities for I2 instances. For more information, see Enabling
Enhanced Networking on Linux Instances in a VPC (p. 516) or Enabling Enhanced Networking on Windows
Instances in a VPC.
Topics
Hardware Specifications (p. 106)
I2 Instance Limitations (p. 106)
SSD Storage (p. 107)
SSD I/O Performance (p. 107)
Hardware Specifications
For more information about the hardware specifications for each Amazon EC2 instance type, see Instance
Type Details.
I2 Instance Limitations
You must launch an I2 instance using an HVM AMI. We support the following Linux distributions: Amazon
Linux, Ubuntu, Red Hat Enterprise Linux, and SUSE Enterprise Linux. We support the following versions
of Windows: Microsoft Windows Server 2012 and Microsoft Windows Server 2008 R2. If you'd like to use
an HVM AMI for a different operating system, let us know by posting to the Amazon EC2 forum.
We limit the number of I2 instances that you can run. If you need more I2 instances than the default limits
described in the following table, you can request more I2 instances using the Amazon EC2 Instance
Request Form.
Default Instance Limit Instance Size
8 i2.xlarge
8 i2.2xlarge
4 i2.4xlarge
2 i2.8xlarge
API Version 2014-02-01
106
Amazon Elastic Compute Cloud User Guide
I2 Instances
SSD Storage
The primary data storage for I2 instances is SSD-based instance storage. Like all instance storage, these
volumes persist only for the life of the instance. When you terminate an instance, the applications and
data in its instance store is erased. When you use an Amazon EBS-backed AMI, you can start and stop
your instance. However, when you stop an instance, the data stored in the Amazon EBS volume persists,
but data in the instance store volumes doesn't persist. We recommend that you regularly back up or
replicate the data you've stored in instance storage.
For more information about instance store volumes, see Amazon EC2 Instance Store (p. 582).
SSD I/O Performance
To ensure the best IOPS performance from your I2 instance, we recommend that you use the most recent
version of the Amazon Linux AMI, or another Linux AMI with kernel version 3.8 or later. If you use a Linux
AMI with kernel version 3.8 or later and utilize all the SSD-based instance store volumes available to the
instance, you can get at least the minimum random IOPS (4,096 byte block size) listed in the following
table. Otherwise, you'll get lower IOPS performance than what is shown in the table.
First Write IOPS Read IOPS Instance Size
35,000 35,000 i2.xlarge
75,000 75,000 i2.2xlarge
155,000 175,000 i2.4xlarge
315,000 365,000 i2.8xlarge
As you fill the SSD-based instance storage for your instance, the number of write IOPS that you can
achieve decreases. This is due to the extra work the SSD controller must do to find available space,
rewrite existing data, and erase unused space so that it can be rewritten. This process of garbage collection
results in internal write amplification to the SSD, expressed as the ratio of SSD write operations to user
write operations. This decrease in performance is even larger if the write operations are not in multiples
of 4,096 bytes or not aligned to a 4,096-byte boundary. If you write a smaller amount of bytes or bytes
that are not aligned, the SSD controller must read the surrounding data and store the result in a new
location. This pattern results in significantly increased write amplification, increased latency, and
dramatically reduced I/O performance.
SSD controllers can use several strategies to reduce the impact of write amplification. One such strategy
is to reserve space in the SSD instance storage so that the controller can more efficiently manage the
space available for write operations. This is called over-provisioning. The SSD-based instance store
volumes provided to an I2 instance don't have any space reserved for over-provisioning. To reduce write
amplification, you should leave 10% of the volume unpartitioned so that the SSD controller can use it for
over-provisioning. This decreases the storage that you can use, but increases performance.
You can also use the TRIM command to notify the SSD controller whenever you no longer need data
that you've written. This provides the controller with more free space, which can reduce write amplification
and increase performance. For more information about using TRIM commands, see the documentation
for the operating system for your instance.
HI1 Instances
HI1 instances (hi1.4xlarge) can deliver tens of thousands of low-latency, random I/O operations per
second (IOPS) to applications. They are well suited for the following scenarios:
NoSQL databases (for example, Cassandra and MongoDB)
API Version 2014-02-01
107
Amazon Elastic Compute Cloud User Guide
HI1 Instances
Clustered databases
Online transaction processing (OLTP) systems
You can cluster HI1 instances in a placement group. For more information, see Placement Groups (p. 115).
By default, you can run up to two hi1.4xlarge instances. If you need more than two hi1.4xlarge
instances, you can request more using the Amazon EC2 Instance Request Form.
Topics
Hardware Specifications (p. 108)
Disk I/O Performance (p. 108)
SSD Storage (p. 108)
Hardware Specifications
The hi1.4xlarge instance type is based on solid-state drive (SSD) technology.
For more information about the hardware specifications for each Amazon EC2 instance type, see Instance
Type Details.
Disk I/O Performance
Using Linux paravirtual (PV) AMIs, HI1 instances can deliver more than 120,000 4 KB random read IOPS
and between 10,000 and 85,000 4 KB random write IOPS (depending on active logical block addressing
span) to applications across two SSD data volumes. For hardware virtual machines (HVM) and Windows
AMIs, performance is approximately 90,000 4 KB random read IOPS and between 9,000 and 75,000 4
KB random write IOPS.
The maximum sequential throughput on all AMI types (Linux PV, Linux HVM, and Windows) per second
is approximately 2 GB read and 1.1 GB write.
SSD Storage
This section contains important information you need to know about SSD storage. With SSD storage:
The primary data source is an instance store with SSD storage.
Read performance is consistent and write performance can vary.
Write amplification can occur.
The TRIM command is not currently supported.
Instance Store with SSD Storage
The hi1.4xlarge instances use an Amazon EBS-backed root device. However, their primary data
storage is provided by the SSD volumes in the instance store. Like other instance store volumes, these
instance store volumes persist only for the life of the instance. Because the root device of the hi1.4xlarge
instance is Amazon EBS-backed, you can still start and stop your instance. When you stop an instance,
your application persists, but your production data in the instance store does not persist. For more
information about instance store volumes, see Amazon EC2 Instance Store (p. 582).
Variable Write Performance
Write performance depends on how your applications utilize logical block addressing (LBA) space. If your
applications use the total LBA space, write performance can degrade by about 90 percent. Benchmark
API Version 2014-02-01
108
Amazon Elastic Compute Cloud User Guide
HI1 Instances
your applications and monitor the queue depth (the number of pending I/O requests for a volume) and
I/O size.
Write Amplification
Write amplification refers to an undesirable condition associated with flash memory and SSDs, where
the actual amount of physical information written is a multiple of the logical amount intended to be written.
Because flash memory must be erased before it can be rewritten, the process to perform these operations
results in moving (or rewriting) user data and metadata more than once. This multiplying effect increases
the number of writes required over the life of the SSD, which shortens the time that it can reliably operate.
The hi1.4xlarge instances are designed with a provisioning model intended to minimize write
amplification.
Random writes have a much more severe impact on write amplification than serial writes. If you are
concerned about write amplification, allocate less than the full tebibyte of storage for your application
(also known as over provisioning).
The TRIM Command
The TRIM command enables the operating system to notify an SSD that blocks of previously saved data
are considered no longer in use. TRIM limits the impact of write amplification.
TRIM support is not available for HI1 instances. For TRIM support, use I2 instances. For more information,
see I2 Instances (p. 106).
HS1 Instances
HS1 instances (hs1.8xlarge) provide very high storage density and high sequential read and write
performance per instance. They are well suited for the following scenarios:
Data warehousing
Hadoop/MapReduce
Parallel file systems
You can cluster HS1 instances in a placement group. For more information, see Placement Groups (p. 115).
By default, you can run up to two HS1 instances. If you need more than two HS1 instances, you can
request more using the Amazon EC2 Instance Request Form.
Topics
Hardware Specifications (p. 109)
Disk I/O Performance (p. 110)
Storage Information (p. 110)
Hardware Specifications
HS1 instances support both Amazon Elastic Block Store (Amazon EBS)-backed and instance store-backed
Amazon Machine Images (AMIs). HS1 instances support both paravirtual (PV) and hardware virtual
machine (HVM) AMIs. HS1 instances are capable of delivering 2.4 GB per second of sequential read and
2.6 GB per second of sequential write performance when using a block size of 2 MiB.
For customers using Microsoft Windows Server, HS1 instances are only supported with the Microsoft
Windows Server AMIs for Cluster Instance Type. HS1 instances do not currently support Amazon EBS
API Version 2014-02-01
109
Amazon Elastic Compute Cloud User Guide
HS1 Instances
optimization, but provide high bandwidth networking and can also be used with Amazon EBS provisioned
I/O operations per second (IOPS) volumes for improved consistency and performance.
For more information about the hardware specifications for each Amazon EC2 instance type, see Instance
Type Details.
Disk I/O Performance
HS1 instances are capable of delivering 2.6 GB per second of sequential read and write performance
when using a block size of 2 MiB.
Storage Information
This section contains important information you need to know about the storage used with HS1 instances.
Instance Store with HS1 Instances
HS1 instances support both instance store and Amazon EBS root device volumes. However, even when
using an Amazon EBS-backed instance, primary data storage is provided by the hard disk drives in the
instance store. Like other instance store volumes, these instance store volumes persist only for the life
of the instance. Therefore, when you stop an instance (when using an Amazon EBS-backed root volume),
your application persists, but your production data in the instance store does not persist. For more
information about instance store volumes, see Amazon EC2 Instance Store (p. 582).
Disk Initialization
If you plan to run an HS1 instance in a steady state for long periods of time, we recommend that you zero
the hard disks first for improved performance. This process can take as long as six hours to complete.
Setting the Memory Limit
Many Linux-based AMIs come with CONFIG_XEN_MAX_DOMAIN_MEMORY set to 70. We recommend that
you set this as appropriate for 117 GiB of memory.
Setting the User Limit (ulimit)
Many Linux-based AMIs come with a default ulimit of 1024. We recommend that you increase the ulimit
to 2048.
R3 Instances
R3 instances are optimized to deliver high memory performance and high sustainable bandwidth. They
are well suited for the following scenarios:
Relational databases and NoSQL databases (for example, MongoDB)
In-memory analytics
Memcache/Redis applications (for example, Elasticache)
You can cluster R3 instances in a placement group. Cluster placement groups provide low latency and
high-bandwidth connectivity between the instances within a single Availability Zone. For more information,
see Placement Groups (p. 115).
You can enable enhanced networking capabilities for R3 instances. For more information, see Enabling
Enhanced Networking on Linux Instances in a VPC (p. 516) or Enabling Enhanced Networking on Windows
Instances in a VPC.
API Version 2014-02-01
110
Amazon Elastic Compute Cloud User Guide
R3 Instances
Topics
Hardware Specifications (p. 111)
Operating System Support (p. 111)
HVM AMI Support (p. 111)
Default R3 Instance Limits (p. 111)
SSD Storage (p. 111)
SSD I/O Performance (p. 112)
TRIM Support (p. 112)
Hardware Specifications
For more information about the hardware specifications for each Amazon EC2 instance type, see Instance
Type Details.
Operating System Support
We support the following Linux operating systems: Amazon Linux, Ubuntu, Red Hat Enterprise Linux,
and SUSE Enterprise Linux. In, addition, you can launch R3 instances using Microsoft Windows Server
2012 and Microsoft Server 2008 R2 AMIs. If you'd like to use an HVM AMI for a different operating system,
let us know by posting to the Amazon EC2 forum.
HVM AMI Support
R3 instances have high-memory (up to 244 GiB of RAM), and require 64-bit operating systems to take
advantage of that capacity. HVM AMIs provide superior performance in comparison to paravirtual (PV)
AMIs on high-memory instance types. For these reasons, R3 instances support 64-bit HVM AMIs only.
In addition, HVM AMIs are required to leverage the benefits of enhanced networking.
Default R3 Instance Limits
We limit the number of R3 instances that you can run simultaneously. If you need more R3 instances
than the default limits described in the following table, you can request more by using the Amazon EC2
Instance Request Form.
Default Instance Limit Instance Type
20 r3.large
20 r3.xlarge
20 r3.2xlarge
10 r3.4xlarge
5 r3.8xlarge
SSD Storage
The primary data storage for R3 instances is SSD-based instance storage. Like all instance storage,
these volumes persist only for the life of the instance. When you terminate an instance, the applications
and data in its instance store are erased. When you use an Amazon EBS-backed AMI, you have the
option to stop your instance and restart it later; however, when you stop an instance, the data stored in
API Version 2014-02-01
111
Amazon Elastic Compute Cloud User Guide
R3 Instances
the Amazon EBS volumes persist, but data in the instance store volumes is lost. We recommend that
you regularly back up or replicate the data you've stored in instance storage.
For more information about instance store volumes, see Amazon EC2 Instance Store (p. 582).
SSD I/O Performance
The largest R3 instances (r3.8xlarge) are capable of providing up to 150,000 4 kilobyte (KB) random
read IOPS and up to 130,000 4 KB random first write IOPS. To ensure the best IOPS performance from
your R3 instance, we recommend that you use the most recent version of the Amazon Linux AMI, or
another Linux AMI with a kernel version of 3.8 or later. If you do not use a Linux AMI with a kernel version
of 3.8 or later, you will not achieve the maximum IOPS performance available for this instance type.
TRIM Support
You can also use the TRIM command to notify the SSD controller whenever you no longer need data
that you've written. This provides the controller with more free space, which can reduce write amplification
and increase performance. For more information about using TRIM commands, see the operating
system-specific documentation for your instance.
GPU Instances
If you require high parallel processing capability, you'll benefit from using GPU instances, which provide
access to NVIDIA GPUs with up to 1,536 CUDA cores and 4 GB of video memory. You can use GPU
instances to accelerate many scientific, engineering, and rendering applications by leveraging the Compute
Unified Device Architecture (CUDA) or OpenCL parallel computing frameworks. You can also use them
for graphics applications, including game streaming, 3-D application streaming, and other graphics
workloads.
GPU instances run as HVM-based instances. Hardware virtual machine (HVM) virtualization uses
hardware-assist technology provided by the AWS platform. With HVM virtualization, the guest VM runs
as if it were on a native hardware platform, except that it still uses paravirtual (PV) network and storage
drivers for improved performance. This enables Amazon EC2 to provide dedicated access to one or more
discrete GPUs in each GPU instance.
You can cluster GPU instances into a cluster placement group. Cluster placement groups provide low
latency and high-bandwidth connectivity between the instances within a single Availability Zone. For more
information, see Placement Groups (p. 115).
Topics
Hardware Specifications (p. 112)
GPU Instance Limitations (p. 112)
AMIs for GPU Instances (p. 113)
Installing the NVIDIA Driver on Linux (p. 113)
Installing the NVIDIA Driver on Windows (p. 114)
Hardware Specifications
For more information about the hardware specifications for each Amazon EC2 instance type, see Instance
Type Details.
GPU Instance Limitations
GPU instances currently have the following limitations:
API Version 2014-02-01
112
Amazon Elastic Compute Cloud User Guide
GPU Instances
They aren't available in every region.
They must be launched from HVM AMIs.
They can't access the GPU unless the NVIDIA drivers are installed.
They aren't available for use with Amazon DevPay.
We limit the number of instances that you can run. For more information, see How many instances can
I run in Amazon EC2? in the Amazon EC2 FAQ. To request an increase in these limits, use the following
form: Request to Increase Amazon EC2 Instance Limit.
AMIs for GPU Instances
To help you get started, NVIDIA provides AMIs for GPU instances for Amazon Linux and Windows. These
reference AMIs include the NVIDIA driver, which enables full functionality and performance of the NVIDIA
GPUs. For a list of AMIs with the NVIDIA driver, see AWS Marketplace (NVIDIA GRID).
You can launch a CG1 instance using any HVM AMI.
You can launch a G2 instance using Windows Server 2012 and Windows Server 2008 R2 AMIs. In
addition, you can launch Linux HVM AMIs with the following operating systems: Amazon Linux, SUSE
Enterprise Linux, and Ubuntu. If you encounter the following error when launching a G2 instance from
an AMI for a different operating system, contact Customer Service or reach out through the Amazon EC2
forum.
Client.UnsupportedOperation: Instances of type 'g2.2xlarge' may not be launched
from AMI <ami-id>.
After you launch a G2 instance, you can create your own AMI from the instance. However, if you create
a snapshot of the root volume of the instance, register it as an AMI, and then launch a G2 instance, you'll
get the Client.UnsupportedOperation error. To launch a G2 instance from your own AMI, you must
create the AMI from a G2 instance using the console (select the instance, click Actions, and then click
Create Image), create-image (AWS CLI), or ec2-create-image (Amazon EC2 CLI).
Installing the NVIDIA Driver on Linux
A GPU instance must have the appropriate NVIDIA driver. The NVIDIA driver you install must be compiled
against the kernel that you intend to run on your instance.
Amazon provides updated and compatible builds of the NVIDIA kernel drivers for each official kernel
upgrade. If you decide to use a different NVIDIA driver version than the one Amazon provides, or decide
to use a kernel that's not an official Amazon build, you must uninstall the Amazon-provided NVIDIA
packages from your system to avoid conflicts with the versions of the drivers you are trying to install.
Use this command to uninstall Amazon-provided NVIDIA packages:
$ sudo yum erase nvidia cudatoolkit
The Amazon-provided CUDA toolkit package has dependencies on the NVIDIA drivers. Uninstalling the
NVIDIA packages erases the CUDA toolkit.You must reinstall the CUDA toolkit after installing the NVIDIA
driver.
You can download NVIDIA drivers from http://www.nvidia.com/Download/Find.aspx. Select a driver for
the NVIDIA GRID K520 (G2 instances) or Tesla M-Class M2050 (CG1 instances) for Linux 64-bit systems.
For more information about installing and configuring the driver, open the ADDITIONAL INFORMATION
tab on the download page for the driver on the NVIDIA website and click the README link.
API Version 2014-02-01
113
Amazon Elastic Compute Cloud User Guide
GPU Instances
Manually Install the NVIDIA Driver
To install the driver for an Amazon Linux AMI
1. Make sure the kernel-devel package is installed and matches the version of the kernel you are
currently running.
$ yum install kernel-devel-`uname -r`
2. Run the self-install script to install the NVIDIA driver. For example:
$ /root/NVIDIA-Linux-x86_64_319.60.run
3. Reboot the instance. For more information, see Reboot Your Instance (p. 322).
4. Confirm that the driver is functional. The response for the following command lists the installed NVIDIA
driver version and details about the GPUs.
$ /usr/bin/nvidia-smi -q -a
Installing the NVIDIA Driver on Windows
To install the NVIDIA driver on your Windows instance, log on to your instance as Administrator using
Remote Desktop. You can download NVIDIA drivers from http://www.nvidia.com/Download/Find.aspx.
Select a driver for the NVIDIA GRID K520 (G2 instances) or Tesla M-Class M2050 (CG1 instances) for
your version of Windows Server. Open the folder where you downloaded the driver and double-click the
installation file to launch it. Follow the instructions to install the driver and reboot your instance as required.
To verify that the GPU is working properly, check device manager.
When using Remote Desktop, GPUs that use the WDDM driver model are replaced with a non-accelerated
Remote Desktop display driver. In order to access your GPU hardware, you must use a different remote
access tool, such as VNC. You can also use one of the GPU AMIs from the AWS Marketplace because
they provide remote access tools that support 3-D acceleration.
Amazon EBS-Optimized Instances
An Amazon EBS-optimized instance uses an optimized configuration stack and provides additional,
dedicated capacity for Amazon EBS I/O. This optimization provides the best performance for your Amazon
EBS volumes by minimizing contention between Amazon EBS I/O and other traffic from your instance.
When you use an Amazon EBS-optimized instance, you pay an additional low, hourly fee for the dedicated
capacity.
Amazon EBS optimization enables instances to fully utilize the IOPS provisioned on an Amazon EBS
volume. Amazon EBS-optimized instances deliver dedicated throughput to Amazon EBS, with options
between 500 Mbps and 2,000 Mbps, depending on the instance type you use. When attached to an
Amazon EBS-optimized instance, Provisioned IOPS volumes are designed to deliver within 10 percent
of their provisioned performance 99.9 percent of the time in a given year. For more information, see
Provisioned IOPS Volumes (p. 526).
The table below describes the instance types that can be launched as Amazon EBS-optimized instances,
the dedicated Amazon EBS throughput they provide, and the maximum number of input/output operations
per second (IOPS) that you can drive over the Amazon EBS connection.
API Version 2014-02-01
114
Amazon Elastic Compute Cloud User Guide
Amazon EBS-Optimized Instances
Max 16K IOPS** Dedicated EBS Throughput (Mbps)* Instance
Type
8,000 1,000 c1.xlarge
4,000 500 c3.xlarge
8,000 1,000 c3.2xlarge
16,000 2,000 c3.4xlarge
8,000 1,000 g2.2xlarge
4,000 500 i2.xlarge
8,000 1,000 i2.2xlarge
16,000 2,000 i2.4xlarge
4,000 500 m1.large
8,000 1,000 m1.xlarge
4,000 500 m2.2xlarge
8,000 1,000 m2.4xlarge
4,000 500 m3.xlarge
8,000 1,000 m3.2xlarge
4,000 500 r3.xlarge
8,000 1,000 r3.2xlarge
16,000 2,000 r3.4xlarge
To launch an Amazon EBS-optimized instance, select the Launch as EBS-optimized instance option
in the launch wizard. If the instance type that you've selected can't be launched as an Amazon
EBS-optimized instance, this option is not available.
To launch an Amazon EBS-optimized instance using the AWS CLI, use the run-instances command with
the --ebs-optimized option.
To launch an Amazon EBS-optimized instance using Amazon EC2 CLI, use the ec2-run-instances
command with the --ebs-optimized option.
Placement Groups
A placement group is a logical grouping of instances within a single Availability Zone. Using placement
groups enables applications to participate in a low-latency, 10 Gbps network. Placement groups are
recommended for applications that benefit from low network latency, high network throughput, or both.
To provide the lowest latency, and the highest packet-per-second network performance for your placement
group, choose an instance type that supports enhanced networking. For more information, see Enhanced
Networking (p. 516).
First, you create a placement group and then you launch multiple instances into the placement group.
We recommend that you launch the number of instances that you need in the placement group in a single
launch request. If you try to add more instances to the placement group later, you increase your chances
of getting an insufficient capacity error.
API Version 2014-02-01
115
Amazon Elastic Compute Cloud User Guide
Placement Groups
If you stop an instance in a placement group and then start it again, it still runs in the placement group.
However, the start fails if there isn't enough capacity for the instance.
If you receive a capacity error when launching an instance in a placement group, stop and restart the
instances in the placement group, and then try the launch again.
Topics
Placement Group Limitations (p. 116)
Launching Instances into a Placement Group (p. 116)
Deleting a Placement Group (p. 117)
Placement Group Limitations
Placement groups have the following limitations:
A placement group can't span multiple Availability Zones.
The name you specify for a placement group a name must be unique within your AWS account.
The following are the only instance types that you can use when you launch an instance into a placement
group:
Compute optimized: c3.large | c3.xlarge | c3.2xlarge | c3.4xlarge | c3.8xlarge |
cc2.8xlarge
GPU: cg1.4xlarge | g2.2xlarge
Memory optimized: cr1.8xlarge | r3.large | r3.xlarge | r3.2xlarge | r3.4xlarge |
r3.8xlarge
Storage optimized: hi1.4xlarge | hs1.8xlarge | i2.xlarge | i2.2xlarge | i2.4xlarge |
i2.8xlarge
You can't merge placement groups. Instead, you must terminate the instances in one placement group,
and then relaunch those instances into the other placement group.
A placement group can span peered VPCs; however, you will not get full-bisection bandwidth between
instances in peered VPCs. For more information about VPC peering connections, see VPC Peering in
the Amazon Virtual Private Cloud User Guide.
Launching Instances into a Placement Group
We suggest that you create an AMI specifically for the instances that you'll launch into a placement group.
To launch an instance into a placement group using the console
1. Open the Amazon EC2 console.
2. Create an AMI for your instances.
a. From the Amazon EC2 dashboard, click Launch Instance. After you complete the wizard, click
Launch.
b. Connect to your instance. (For more information, see Connect to Your Instance (p. 308).)
c. Install software and applications on the instance, copy data, or attach additional Amazon EBS
volumes.
d. In the navigation pane, click Instances, select your instance, click Actions, and then click Create
Image. Provide the information requested by the Create Image dialog box, and then click Create
Image.
e. (Optional) You can terminate this instance if you have no further use for it.
API Version 2014-02-01
116
Amazon Elastic Compute Cloud User Guide
Placement Groups
3. Create a placement group.
a. In the navigation pane, click Placement Groups.
b. Click Create Placement Group.
c. In the Create Placement Group dialog box, provide a name for the placement group that is
unique in the AWS account you're using, and then click Create.
When the status of the placement group is available, you can launch instances into the
placement group.
4. Launch your instances into the placement group.
a. In the navigation pane, click Instances.
b. Click Launch Instance. Complete the wizard as directed, taking care to select the following:
The AMI that you created
The number of instances that you'll need
The placement group that you created
To create a placement group using the command line
You can use one of the following commands. For more information about these command line interfaces,
see Accessing Amazon EC2 (p. 3).
create-placement-group (AWS CLI)
ec2-create-placement-group (Amazon EC2 CLI)
New-EC2PlacementGroup (AWS Tools for Windows PowerShell)
If you prefer, you can use the ec2-create-image command to create your AMI, the
ec2-create-placement-group command to create your placement group, and use the ec2-run-instances
command to launch an instance into the placement group.
Deleting a Placement Group
You can delete a placement group if you need to replace it or no longer need a placement group. Before
you can delete your placement group, you must terminate all instances that you launched into the placement
group.
To delete a placement group using the console
1. Open the Amazon EC2 console.
2. In the navigation pane, click Instances.
3. Select and terminate all instances in the placement group. (You can verify that the instance is in a
placement group before you terminate it by checking the value of Placement Group in the details
pane.)
4. In the navigation pane, click Placement Groups.
5. Select the placement group, and then click Delete Placement Group.
6. When prompted for confirmation, click Yes, Delete.
API Version 2014-02-01
117
Amazon Elastic Compute Cloud User Guide
Placement Groups
To delete a placement group using the command line
You can use one of the following sets of commands. For more information about these command line
interfaces, see Accessing Amazon EC2 (p. 3).
terminate-instances and delete-placement-group (AWS CLI)
ec2-terminate-instances and ec2-delete-placement-group (Amazon EC2 CLI)
Stop-EC2Instance and Remove-EC2PlacementGroup(AWS Tools for Windows PowerShell)
Resizing Your Instance
As your needs change, you might find that your instance is over-utilized (the instance type is too small)
or under-utilized (the instance type is too large). If this is the case, you can change the size of your
instance. For example, if your t1.micro instance is too small for its workload, you can change it to an
m1.small instance.
The process for resizing an instance varies depends on the type of its root device volume, as follows:
If the root device for your instance is an Amazon EBS volume, you can easily resize your instance by
changing its instance type.
If the root device for your instance is an instance store volume, you must migrate to a new instance.
To determine the root device type of your instance, open the Amazon EC2 console, click Instances,
select the instance, and check the value of Root device type in the details pane. The value is either ebs
or instance store.
For more information about root device volumes, see Storage for the Root Device (p. 50).
Topics
Resizing an Amazon EBS-backed Instance (p. 118)
Resizing an Instance Store-backed Instance (p. 119)
Resizing an Amazon EBS-backed Instance
You must stop your Amazon EBS-backed instance before you can change its instance type. When you
stop and start an instance, we move it to new hardware. If the instance is running in EC2-Classic, we
give it new public and private IP addresses, and disassociate any Elastic IP address that's associated
with the instance. Therefore, to ensure that your users can continue to use the applications that you're
hosting on your instance uninterrupted, you must re-associate any Elastic IP address after you restart
your instance. For more information, see Stop and Start Your Instance (p. 319).
Use the following procedure to resize an Amazon EBS-backed instance using the AWS Management
Console.
To resize an Amazon EBS-backed instance
1. Open the Amazon EC2 console.
2. In the navigation pane, click Instances, and select the instance.
3. [EC2-Classic] If the instance has an associated Elastic IP address, write down the Elastic IP address
and the instance ID shown in the details pane.
4. Click Actions, and then click Stop.
5. In the confirmation dialog box, click Yes, Stop. It can take a few minutes for the instance to stop.
API Version 2014-02-01
118
Amazon Elastic Compute Cloud User Guide
Resizing Instances
[EC2-Classic] When the instance state becomes stopped, the Elastic IP, Public DNS, Private
DNS, and Private IPs fields in the details pane are blank to indicate that the old values are no longer
associated with the instance.
6. With the instance still selected, click Actions, and then click Change Instance Type. Note that this
action is disabled if the instance state is not stopped.
7. In the Change Instance Type dialog box, in the Instance Type list, select the type of instance that
you need, and then click Apply.
8. To restart the stopped instance, select the instance, click Actions, and then click Start.
9. In the confirmation dialog box, click Yes, Start. It can take a few minutes for the instance to enter
the running state.
[EC2-Classic] When the instance state is running, the Public DNS, Private DNS, and Private IPs
fields in the details pane contain the new values that we assigned to the instance.
10. [EC2-Classic] If your instance had an associated Elastic IP address, you must reassociate it as
follows:
a. In the navigation pane, click Elastic IPs.
b. Select the Elastic IP address that you wrote down before you stopped the instance.
c. Click Associate Address.
d. Select the instance ID that you wrote down before you stopped the instance, and then click
Associate.
Resizing an Instance Store-backed Instance
You can create an image from your current instance, launch a new instance from this image with the
instance type you need, and then terminate the original instance that you no longer need. To ensure that
your users can continue to use the applications that you're hosting on your instance uninterrupted, you
must take any Elastic IP address that you've associated with your current instance and associate it with
the new instance.
To resize an instance store-backed instance
1. (Optional) If the instance you are resizing has an associated Elastic IP address, record the Elastic
IP address now so that you can associate it with the resized instance later.
2. Create an AMI from your instance store-backed instance by satisfying the prerequisites and following
the procedures in Creating an Instance Store-Backed Linux AMI (p. 72). When you are finished
creating a new AMI from your instance, return to this procedure.
3. Open the Amazon EC2 console and in the navigation pane, select AMIs. From the filter lists, select
Owned by me, and select the image you created in the previous step. Notice that AMI Name is the
name that you specified when you registered the image and Source is your Amazon S3 bucket.
Note
If you do not see the AMI that you created in the previous step, make sure that the console
displays the region that you created your AMI in.
4. Click Launch. When you specify options in the launch wizard, be sure to specify the new instance
type that you need. It can take a few minutes for the instance to enter the running state.
5. (Optional) If the instance that you started with had an associated Elastic IP address, you must
associate it with the new instance as follows:
a. In the navigation pane, click Elastic IPs.
b. Select the Elastic IP address that you recorded at the beginning of this procedure.
c. Click Associate Address.
API Version 2014-02-01
119
Amazon Elastic Compute Cloud User Guide
Resizing Instances
d. Select the instance ID of the new instance, and then click Associate.
6. (Optional) You can terminate the instance that you started with, if it's no longer needed. Select the
instance and check its instance ID against the instance ID that you wrote down at the beginning of
this procedure to verify that you are terminating the correct instance. Click Actions, and then click
Terminate.
API Version 2014-02-01
120
Amazon Elastic Compute Cloud User Guide
Resizing Instances
Spot Instances
If you have flexibility on when your application will run, you can bid on unused Amazon EC2 compute
capacity, called Spot Instances, and lower your costs significantly. Set by Amazon EC2, the Spot Price
for these instances fluctuates periodically depending on the supply of and demand for Spot Instance
capacity.
To use Spot Instances, you place a Spot Instance request (your bid) specifying the maximum price you
are willing to pay per hour per instance. If the maximum price of your bid is greater than the current Spot
Price, your request is fulfilled and your instances run until you terminate them or the Spot Price increases
above your maximum price. Your instance can also be terminated when your bid price equals the market
price, even when there is no increase in the market price. This can happen when demand for capacity
rises, or when supply fluctuates.
Note
You can run Amazon EC2 Spot Instances on the following platforms: Amazon Linux/UNIX, SUSE
Linux Enterprise Server, and Windows (without SQL Server). Spot Instances are not available
in the AWS Free Usage Tier program.
You will often pay less per hour than your maximum bid price. The Spot Price is adjusted periodically as
requests come in and the available supply of instances changes. Everyone pays that same Spot Price
for that period regardless of whether their maximum bid price was higher, and you will never pay more
than your hourly maximum bid price.
For product and pricing information, see the following pages:
Amazon EC2 Spot Instances
AWS Service Pricing Overview
Amazon EC2 On-Demand Instances Pricing
Quick Look: Getting Started with Spot Instances
Video
The following video shows how to launch your first Spot Instance using the AWS Management Console.
This video includes instructions on placing a bid, determining when the instance is fulfilled, and canceling
the instance. Getting Started with Spot Instances
Checklist for Getting Started with Spot Instances
If you want to get started working with Spot Instances, here are the resources you need to get going.
Getting Started with Spot Instances (p. 122)
Viewing Spot Instance Pricing History (p. 125)
Creating a Spot Instance Request (p. 127)
Finding Running Spot Instances (p. 130)
Canceling Spot Instance Requests (p. 132)
Fundamentals of Spot Instances (p. 134)
Placing Spot Requests (p. 135)
Tagging Spot Instance Requests (p. 144)
Understanding Spot Instance Provisioning, Pricing, and Interruption (p. 145)
Protecting Your Spot Instance Data Against Interruptions (p. 147)
Walkthroughs: Using Spot Instances with AWS Services (p. 149)
API Version 2014-02-01
121
Amazon Elastic Compute Cloud User Guide
Spot Instances
Managing Spot Instances with Auto Scaling (p. 149)
Using CloudFormation Templates to Launch Spot Instances (p. 164)
Launching Amazon Elastic MapReduce Job Flows with Spot Instances (p. 165)
Launching Spot Instances in Amazon Virtual Private Cloud (p. 165)
Advanced Tasks (p. 168)
Subscribe to Your Spot Instance Data Feed (p. 168)
Programming Spot Instances the with AWS Java SDK (p. 171)
Starting Clusters on Spot Instances (p. 196)
What's New in Spot Instances
Here's a quick look at what's new in Spot Instances:
Spot Instance Limits (p. 135)
Getting Started with Spot Instances
In this section, you will get started using Spot Instances.You'll walk through what you need to know before
you begin and the prerequisites you need to get started.You'll learn about the tools you will use for specific
Spot Instance tasks, and then you'll step through the main tasks.
If you are new to Spot Instances, take a look at Prerequisites for Using Spot Instances (p. 123) to make
sure you can take full advantage of the benefits of this Amazon EC2 product. If you have been using
Amazon EC2 and you're ready to proceed, click one of the items in the following list to get going.
Topics
Prerequisites for Using Spot Instances (p. 123)
Using the AWS Management Console for Spot Instances (p. 123)
Using the AWS CLI and the EC2 CLI Tools for Spot Instances (p. 124)
Using AWS Java SDK for Spot Instances (p. 125)
Viewing Spot Instance Pricing History (p. 125)
Creating a Spot Instance Request (p. 127)
Finding Running Spot Instances (p. 130)
Canceling Spot Instance Requests (p. 132)
Before requesting a Spot Instance, consider configuring your Amazon Machine Image (AMI) so that your
application does the following tasks:
Automatically performs the tasks you want at start-up because the instance will start asynchronously
without notification. For example, if you're using batch processes, you could set up your AMI to pull
jobs from an Amazon Simple Queue Service (Amazon SQS) queue.
Stores important data regularly in a place that wont be affected by instance termination. For example,
you could store your data using Amazon Simple Storage Service (Amazon S3), Amazon SimpleDB, or
Amazon Elastic Block Store (Amazon EBS).
Important
Although Spot Instances can use Amazon EBS-backed AMIs, be aware that you can't stop
and start Spot Instances launched from an AMI that has an Amazon EBS root device. For
information about Amazon EBS, see Amazon Elastic Block Store (Amazon EBS).
Handles termination gracefully.
API Version 2014-02-01
122
Amazon Elastic Compute Cloud User Guide
Getting Started with Spot Instances
For information about creating AMIs, see Creating Your Own AMI (p. 49).
Prerequisites for Using Spot Instances
To work with Amazon EC2 Spot Instances, read and complete the instructions described in Getting Started
with Amazon EC2 Linux Instances (p. 24), which provides information on creating your Amazon EC2
account and credentials.
In addition, there are a variety of tools you can use to work with Spot Instances. Whichever you choosethe
AWS Management Console, the AWS Command Line Interface (AWS CLI), the Amazon EC2 command
line interface (EC2 CLI), or the Amazon EC2 application programming interface (EC2 API)you will have
specific tools for assessing Spot price history, submitting Spot Instance requests (also called bids), and
managing your Spot requests and instances. You can also use, develop, and manage your applications
using the AWS SDKs. For more information, see Tools for Amazon Web Services.
In this topic, you get an overview of the AWS Management Console, and the AWS CLI and Amazon EC2
CLI tools available for Spot Instances. We assume that you have read and completed the instructions
described in the following guides. They walk you through setting up your environment for use with the
tools:
AWS Management ConsoleGetting Started with AWS Management Console
AWS CLIAWS Command Line Interface User Guide
Amazon EC2 CLISetting Up the Amazon EC2 Tools
For information about using the Amazon EC2 API, see Making API Requests (p. 664). For information
about API actions, see the Amazon Elastic Compute Cloud API Reference.
Using the AWS Management Console for Spot Instances
In the AWS Management Console, the EC2 console has tools specifically designed for Spot Instance
request tasks. The EC2 console also has general tools that you can use to manage the instances launched
when your requests are fulfilled.
The Spot Requests page is the main way you interact with your Spot Instance requests.
Spot Instance Pricing History gives you an insight in the pricing patterns for specific Spot Instance
types in Availability Zones over a defined period.
API Version 2014-02-01
123
Amazon Elastic Compute Cloud User Guide
Getting Started with Spot Instances
Use the Request Spot Instances page to submit a Spot Instance request and specify the details of
the instance to be launched when your request succeeds.
Use the Instances page to manage the instances launched when your Spot request succeeds.
Using the AWS CLI and the EC2 CLI Tools for Spot Instances
The AWS CLI and the Amazon EC2 CLI tools have commands that are specifically designed for managing
Spot requests. The following table lists the commands you use for Spot request tasks. To manage the
instances launched when your Spot request is fulfilled, use the same commands that you use for
On-Demand EC2 instances.
Amazon EC2 CLI AWS CLI Task
ec2-describe-spot-price-history aws ec2
describe-spot-price-history
Viewing Spot Instance Pricing
History (p. 125).
API Version 2014-02-01
124
Amazon Elastic Compute Cloud User Guide
Getting Started with Spot Instances
Amazon EC2 CLI AWS CLI Task
ec2-describe-spot-instance-requests aws ec2
describe-spot-instance-requests
Finding Running Spot
Instances (p. 130).
ec2-request-spot-instances aws ec2
request-spot-instances
Creating a Spot Instance
Request (p. 127).
ec2-create-spot-datafeed-subscription aws ec2
create-spot-datafeed-subscription
Subscribe to Your Spot Instance
Data Feed (p. 170).
ec2-describe-spot-datafeed-subscription aws ec2
describe-spot-datafeed-subscription
Data Feed Filename and
Format (p. 168).
ec2-delete-spot-datafeed-subscription aws ec2
delete-spot-datafeed-subscription
Delete a Spot Instance Data
Feed (p. 170).
ec2-cancel-spot-instance-requests aws ec2
cancel-spot-instance-requests
Canceling Spot Instance
Requests (p. 132).
Using AWS Java SDK for Spot Instances
Java developers can go to the AWS SDK for Java to consult the Java tutorials on Spot Instances:
Tutorial: Amazon EC2 Spot Instances (p. 172)
Tutorial: Advanced Amazon EC2 Spot Request Management (p. 180)
Viewing Spot Instance Pricing History
The Spot Price represents the price above which you have to bid to guarantee that a single Spot request
is fulfilled. When your bid is above the Spot Price, your Spot Instance is launched, and if the Spot Price
rises above your bid price, your Spot Instance is terminated. You might choose to bid above the current
Spot Price so that your Spot request is fulfilled quickly. However, before specifying a price with which
you want to bid for your Spot Instance, we recommend that you view the Spot Price history. You can view
the Spot Price history for the last 90 days for any pool of Spot Instances sharing the same instance type,
operating system, and Availability Zone.
For example, let's say you want to bid on a Linux/UNIX t1.micro instance to be launched in the us-east-1
region. To view past prices in this Spot pool, specify these values using the Spot Instance Pricing
History page of the AWS Management Console, the DescribeSpotPriceHistory API action, or
ec2-describe-spot-price-history CLI command. If you need to launch your Spot Instance in a
specific Availability Zone, you can specify that Availability Zone when retrieving the Spot Price history.
After you review the Spot Price history, you might choose to bid at a price that would have given you 75
percent Spot Instance uptime in the past. Or, you might choose to bid two times the current Spot Price
because doing so would have given you 99 percent uptime in the past. However you frame your bid, keep
in mind that past performance of Spot Prices is not a guarantee of future results. Spot Prices vary based
on real-time supply and demand conditions, and the conditions that generated certain Spot Prices or
pricing patterns in the past may not repeat themselves in the future.
Note
Make sure you have set up the prerequisites for working with Amazon EC2. If you haven't, see
Prerequisites for Using Spot Instances (p. 123).
If you are using an API version earlier than 2011-05-15, the DescribeSpotPriceHistory
action or the ec2-describe-spot-price-history command will return the lowest price
across the region for the given time period and the prices will be returned in chronological order.
API Version 2014-02-01
125
Amazon Elastic Compute Cloud User Guide
Getting Started with Spot Instances
AWS Management Console
To view Spot Price history
1. From the Amazon EC2 console, click Spot Requests in the navigation pane.
The Spot Requests pane opens on the right. It will list your Spot requests if you have any.
2. At the top of the pane, click Pricing History.
The console displays the Spot Instance Pricing History page.
3. If you want to view the Spot Price history for specific Availability Zones, click the Availability Zone
list and select an Availability Zone.
The Spot Instance Pricing History page displays the Spot Instance pricing history for all zones or
the zone you selected.
4. To view Spot pricing details, move your cursor across the graph to specific points in time. A vertical
line follows the movement of your cursor, and the table below the graph displays the Spot prices for
different Availability Zones and the date and time pointed to by your cursor and the vertical line.
5. Using the price history as a guide, select a price that you think would likely keep your instances
running for the period of time you need.
Amazon EC2 Command Line Interface (CLI) Tools
To view Spot Price history
1. Enter the following command:
$ ec2-describe-spot-price-history -H --instance-type m1.xlarge
Amazon EC2 returns output similar to the following:
SPOTINSTANCEPRICE 0.384000 2011-05-25T11:37:48-0800 m1.xlarge
Windows us-east-1a
SPOTINSTANCEPRICE 0.384000 2011-05-25T11:37:48-0800 m1.xlarge
Windows us-east-1d