Creating an AMI
There are several techniques for creating an AMI offering a mix of ease of use and detailed
customization levels. The easiest method involves starting from an existing public AMI and modifying it
according to your requirements, as described in the section called “Starting with an Existing AMI” .
Another approach is to build a fresh installation either on a stand-alone machine or on an empty file
system mounted by loopback. This essentially entails building an operating system installation from
scratch and is described in the section called “Creating via a Loopback File” .
Once the installation package has been built to your satisfaction it needs to be bundled and uploaded to
Amazon S3 as described in the section called “Bundling an AMI” .
Starting with an Existing AMI
This is the quickest and easiest of the methods to get a new working AMI. Start with an existing public
AMI or one of your own. You can then modify that as you see fit and subsequently create a new AMI
with the ec2-bundle-vol utility, as decribed later in the section called “Bundling an AMI” .
Select an AMI
The first step is to locate an AMI that contains the packages and services that you require. This can be
one of your own AMIs or one of the public AMIs provided by Amazon EC2. Use ec2-describe-images
to get a list of available AMIs, as is shown below, then select one of the listed AMIs and note its AMI
ID, e.g. ami-61a54008:
PROMPT> ec2-describe-images
IMAGE ami-60a54009 ec2-public-images/base-fc4-apache.manifest 475219833042
available public
IMAGE ami-61a54028 <your-s3-bucket>/image.manifest 495219933132 available
private
IMAGE ami-61a54008 ec2-public-images/getting-started.manifest 475219833042
available public
IMAGE ami-6ea54007 ec2-public-images/base-fc3-mysql.manifest 475219833042
available public
Generate a Keypair
This step is only required if you've selected one of the public AMIs provided by Amazon EC2. A
public/private keypair must be created to ensure that you, and only you, have access to the instances that
you launch.
PROMPT> ec2-create-keypair gsg-keypair
KEYPAIR gsg-keypair
1f:51:ae:28:bf:89:e9:d8:1f:25:5d:37:2d:7d:b8:ca:9f:f5:f1:6f
-----BEGIN RSA PRIVATE KEY-----
MIICXAIBAAKBgQC2i/Sgs5BGGd4sunpYQfEkcprgzP9M/hnVJTc1j0nZBeIE2JBuLRSNoqkO7Gw8
nBcdNptaLedzqN8t78jGkX1TPWVAKJTfxRSvU/oViGJaRqIBar0Mpc/wC27kyzHezUNS5+mvONb3
4h/j2EZwDLY75Uxrpka0aN6OkvyIP5gYMQIDAQABAoGAOKH65tBOdjEYSHAh/LeYhGI5wnxWyCAd
C49cLXWix32XvUEircu2kKpiIIsgmT0jvqBuWe/b2noNo0a81z3TzzRYyLvn5J8mUlL6a8nsssQ3
xCHkGM+SE7ZzfBS5WUkbh5Exd3ZXKfCJvJW6auOzJ581JB5yUNbqixWzHuQGGAECQQDwq4LQoyb5
OVSpZwSy+GW/p0yRsqRp89ECNQ+hySGBjkSXBcbt75C+5ebo88/V2V4QOGGa0T0tMsMgKTJ8oukh
AkEAwiyoFM0Zwk0Os3rBZ8PyZoNW5e5SBwrEbLRv4JCaNiQme0ighsDr2bL/nGLI7p13g22+9REM
i/WAmsln50H9EQJASMun6tGepT2pFQBbFIM7y4egCmXdg0rDSoagLtB2eQh+SKvvquKOhp9lg8rT
b5yq7f8PztNBTN2Q1baAVeC04QJAGgN5kS/ZH5rLOWhcuNYbh3hZD/zZqG/c2ONjiaZVwqMdNK8K
MoNuFYBRllX1rWITPNxbFOHv2GBPlm0dKnJAwQJBAOgwjgLY3UpXFX9ZvG4RGEYgfui49Ffz10CH
5sSZpsFYn42E6a2NUJeL4hTzfbGTQ8iCIVjOXFH/9XLTDCNQEPM=
-----END RSA PRIVATE KEY-----
Amazon EC2
Developer Guide
3
The resulting private key must be saved in a local file for later use. Create a file named
id_rsa-gsg-keypair and paste into it all lines starting with the line
"-----BEGIN PRIVATE KEY-----" and ending with the line "-----END PRIVATE KEY-----".
Confirm that the file contents looks exactly as shown below.
-----BEGIN RSA PRIVATE KEY-----
MIICXAIBAAKBgQC2i/Sgs5BGGd4sunpYQfEkcprgzP9M/hnVJTc1j0nZBeIE2JBuLRSNoqkO7Gw8
nBcdNptaLedzqN8t78jGkX1TPWVAKJTfxRSvU/oViGJaRqIBar0Mpc/wC27kyzHezUNS5+mvONb3
4h/j2EZwDLY75Uxrpka0aN6OkvyIP5gYMQIDAQABAoGAOKH65tBOdjEYSHAh/LeYhGI5wnxWyCAd
C49cLXWix32XvUEircu2kKpiIIsgmT0jvqBuWe/b2noNo0a81z3TzzRYyLvn5J8mUlL6a8nsssQ3
xCHkGM+SE7ZzfBS5WUkbh5Exd3ZXKfCJvJW6auOzJ581JB5yUNbqixWzHuQGGAECQQDwq4LQoyb5
OVSpZwSy+GW/p0yRsqRp89ECNQ+hySGBjkSXBcbt75C+5ebo88/V2V4QOGGa0T0tMsMgKTJ8oukh
AkEAwiyoFM0Zwk0Os3rBZ8PyZoNW5e5SBwrEbLRv4JCaNiQme0ighsDr2bL/nGLI7p13g22+9REM
i/WAmsln50H9EQJASMun6tGepT2pFQBbFIM7y4egCmXdg0rDSoagLtB2eQh+SKvvquKOhp9lg8rT
b5yq7f8PztNBTN2Q1baAVeC04QJAGgN5kS/ZH5rLOWhcuNYbh3hZD/zZqG/c2ONjiaZVwqMdNK8K
MoNuFYBRllX1rWITPNxbFOHv2GBPlm0dKnJAwQJBAOgwjgLY3UpXFX9ZvG4RGEYgfui49Ffz10CH
5sSZpsFYn42E6a2NUJeL4hTzfbGTQ8iCIVjOXFH/9XLTDCNQEPM=
-----END RSA PRIVATE KEY-----
Launch an Instance
You are now ready to launch an instance of the AMI you selected above.
PROMPT> ec2-run-instances ami-61a54008 -k gsg-keypair
INSTANCE i-10a64379 ami-61a54008 EC2 pending gsg-keypair
The instance ID in the second field of the output is a unique identifier for the instance and can be used
subsequently to manipulate your instance, e.g. to terminate it.
Important
Once you launch an instance, you will be billed per hour for CPU time. Make sure you
terminate any instances which you don't intend to leave running indefinitely.
It will take a few minutes for the instance to launch. You can follow its progress by running:
PROMPT> ec2-describe-instances i-10a64379
RESERVATION r-fea54097 495219933132 EC2
INSTANCE i-10a64379 ami-61a54008 domU-
12-34-31-00-00-05.usma1.compute.amazonaws.com EC2 running gsg-keypair
When the status field reads "running", the instance has been created and has started booting. There may
still be a short time before it is accessible over the network, however. The DNS name displayed in the
sample output above will be different from that assigned to your instance. Make sure you use the
appropriate one.
Authorize Network Access
In order to be able to reach the running instance from the Internet, you need to enable access for the ssh
service which runs on port 22:
PROMPT> ec2-authorize default -p 22
PERMISSION default ALLOWS tcp 22 22 FROM CIDR
0.0.0.0/0
Connect to the Instance
Now that you have a running instance, you can log in and modify it according to your requirements. If
you launched a public Amazon EC2 AMI, you can use the following command to log in with your own
Amazon EC2
Developer Guide
4
Previous Page Next Page