Wednesday, May 13, 2009

Amazone Cloud computing : How to

Prerequisites:


Topics

This document assumes that the reader is comfortable working in a Linux/UNIX enviornment

An installation of a Java 5 compatible Java Runtime Environment (JRE) is required. Additionally, accessing Linux and UNIX instances requires access to an SSH client and accessing Windows instances requires access to a Remote Desktop client. For more information, refer to the two following sections.

As a convention, all command line text is prefixed with a generic PROMPT> command line prompt. The actual command line prompt on your machine is likely to be different. We also use $ to indicate a Linux/UNIX specific command and C:\> for a Windows specific command. While we don't currently provide explicit instructions, the tools also work correctly on Mac OS X (which resemble the Linux and UNIX commands). The example output resulting from the command is shown immediately thereafter without any prefix.

[Note]Note

If you are using Cygwin, EC2_HOME, EC2_PRIVATE_KEY, and EC2_CERT must use Linux/UNIX paths (e.g,, /usr/bin instead of C:\usr\bin). However, JAVA_HOME should have a Windows path. Additionally, the value of EC2_HOME cannot contain any spaces, even if the value is quoted or the spaces are escaped.

The Java Runtime Environment

The command line tools used in this guide require Java version 5 or later to run. Either a JRE or JDK installation is acceptable. To view and download JREs for a range of platforms, including Linux/UNIX and Windows, go to http://java.sun.com/j2se/1.5.0/.

The command line tools depend on an environment variable (JAVA_HOME) to locate the Java runtime. This environment variable should be set to the full path of the directory that contains a sub-directory named bin which in turn contains the java (on Linux and UNIX) or the java.exe (on Windows) executable. You might want to simplify things by adding this directory to your path before other versions of Java.

Following is an example of how to set this environment variable in Linux and UNIX.

$ export JAVA_HOME=

You can confirm this by running $JAVA_HOME/bin/java -version and checking the output.

$ $JAVA_HOME/bin/java -version
java version "1.5.0_09"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_09-b03)

Accessing Linux and UNIX Instances through SSH Clients

For some of the examples illustrated in this guide you'll need access to an SSH client. Most Linux and UNIX installations include an SSH client by default. If yours does not, the OpenSSH project provides a free implementation of the full suite of SSH tools. For more information, go to the OpenSSH home page.

Windows users can download and install PuTTY, a free SSH client. To download the client and installation instructions, go to the PuTTY home page. For information on how to use PuTTY with Amazon EC2, see Appendix: PuTTY.

Setting up an Account

To use Amazon EC2, you must sign up for an AWS Account, sign up for Amazon Simple Storage Service (Amazon S3), and sign up for Amazon EC2. These are three different actions that must be performed separately. For information on obtaining an AWS Account, go to the Amazon AWS Home Page. For information on signing up for Amazon S3, see Signing up for Amazon S3. For information on signing up for Amazon EC2, see Signing up for Amazon EC2.

Signing up for Amazon S3

Amazon EC2 AMIs are stored in and retrieved from Amazon S3. This means you need to sign up for Amazon S3. If you already have an Amazon S3 account, you can skip this step.

Amazon S3 Signup Process

1

Go to the Amazon S3 home page.

2

Click the Sign up for this service button.

If you don't already have an AWS account, you are prompted to create one as part of the sign up process.


After signing up for Amazon S3, point to the button labeled Your Web Services Account and select the AWS Access Key Identifiers link on the menu that appears. Be sure to note down your AWS account's Access Key ID and Secret Access Key. You need these to bundle your own image (see Making Your New Amazon Machine Image).

Signing up for Amazon EC2

After you sign up for Amazon S3, you'll need to sign up for Amazon EC2.

Amazon EC2 Signup Process

1

Log into your AWS account and follow the link to Amazon EC2 under the Browse Web Services section on the left.

2

Click Sign Up For Web Service in the top right of the screen and follow the on-screen instructions.


After you sign up for Amazon EC2, you'll want to get your Access Key identifiers.

Access Key Identifiers Process

1

Point to the button labeled Your Web Services Account and select the View Access Key Identifiers link on the menu that appears.

2

Click Create New in the Your X.509 Certificate section to create a new X.509 certificate.

3

Save the certificate and private key. You'll need this when you set up our command line tools (see Setting up the Tools).

4

Create a .ec2 directory in your home directory, and save these files to it with the filenames offered by your browser. You should end up with a PEM-encoded X509 certificate and a private key file named as shown in the following examples.

The following is an example of a PEM encoded signed X.509 certificate.

cert-HKZYKTAIG2ECMXYIBH3HXV4ZBZQ55CLO.pem

The following is an example of an unencrypted, PEM encoded RSA private key that corresponds to the preceding X.509 certificate.

pk-HKZYKTAIG2ECMXYIBH3HXV4ZBZQ55CLO.pem

This X.509 certificate is associated with your account until you generate or upload a new certificate. If you have an existing certificate that you prefer to use, you can return to the Access Key Identifiers upload it later.

5

Finally, you'll need to look up your AWS account ID. You should use this value whenever you need to provide an Amazon EC2 user ID. From the AWS portal page, point to Your Web Services Account and select the Account Activity link on the menu that appears. At the top of this page, locate your the Account Number which is a hyphenated number that looks similar to 4952-1993-3132. This number, with the hyphens removed, is your AWS account ID. In this example, it is 495219933132.


That's it. You're all set to start setting up your tools.


Setting up the Tools

One step remains before you'll be able to use Amazon EC2. You need to get our command line tools and set them up to use your AWS account.

Getting the Command Line Tools

The command line tools are available as a ZIP file in the Amazon EC2 Resource Center. These tools are written in Java and include shell scripts for both Windows 2000/XP and Linux/UNIX/Mac OSX. The ZIP file is self-contained; no installation is required. You just download it and unzip it.

Some additional setup is required in order for the tools to use your AWS account credentials. These are discussed next.

Telling the Tools Where They Live

The command line tools depend on an environment variable (EC2_HOME) to locate supporting libraries. You'll need to set this environment variable before you can use the tools. This should be set to the path of the directory into which the command line tools were unzipped. This directory is named ec2-api-tools-A.B-nnnn (A, B and n are version/release numbers), and contains sub-directories named bin and lib.

On Linux and UNIX, you can set this environment variable as follows.

$ export EC2_HOME=  

On Windows the syntax is slightly different.

C:\> set EC2_HOME=  

In addition, to make your life a little easier, you probably want to add the tools' bin directory to your system PATH. The rest of this guide assumes is done.

On Linux and UNIX, you can update your PATH as follows.

$ export PATH=$PATH:$EC2_HOME/bin 

On Windows the syntax is slightly different.

C:\> set PATH=%PATH%;%EC2_HOME%\bin 
[Note]Note

The Windows environment variables are reset when you close the command window. You might want to set them permanently.

Telling the Tools Who You Are

The command line tools need access to the private key and X.509 certificate you generated after signing up for the Amazon EC2 service (see Setting up an Account).

Since there's nothing stopping you from having more than one AWS account, you need to identify yourself to the command line API tools so they know which credentials to use for requests. It's possible, but tedious, to provide this information on the command line every time you invoke the tools. But it's far simpler to set up some environment variables and be done with it.

Two environment variables are supported to make this possible. They can be set to point at your private key and certificate. If these environment variables are set, the tools use their values to find the relevant credentials. The environment variable EC2_PRIVATE_KEY should reference your private key file, and EC2_CERT should reference your X509 certificate.

On Linux and UNIX, you can set these environment variables as follows.

$ export EC2_PRIVATE_KEY=~/.ec2/pk-HKZYKTAIG2ECMXYIBH3HXV4ZBZQ55CLO.pem 
$ export EC2_CERT=~/.ec2/cert-HKZYKTAIG2ECMXYIBH3HXV4ZBZQ55CLO.pem

On Windows the syntax is slightly different.

C:\> set EC2_PRIVATE_KEY=c:\ec2\pk-HKZYKTAIG2ECMXYIBH3HXV4ZBZQ55CLO.pem 
C:\> set EC2_CERT=c:\ec2\cert-HKZYKTAIG2ECMXYIBH3HXV4ZBZQ55CLO.pem

Changing the Region

By default, the Amazon EC2 tools use the Eastern United States region (us-east-1) with the us-east-1.ec2.amazonaws.com service endpoint. This section describes how to specify a different region.

To specify a different region

  1. View available regions by entering the following:

    PROMPT> ec2-describe-regions

    REGION us-east-1 us-east-1.ec2.amazonaws.com
    REGION eu-west-1 eu-west-1.ec2.amazonaws.com

  2. If you want to change the service endpoint on Linux and UNIX, set the EC2_URL environment variable as follows:

    $ export EC2_URL=https://  
  3. If you want to change the service endpoint on Windows, set the EC2_URL environment variable as follows:

    C:\> set EC2_URL=https://  

You're ready to start using Amazon EC2.

Running an Instance

This section describes how to run an instance that uses Linux or UNIX.

[Note]Note

For information about creating your own AMI, refer to the Amazon Elastic Compute Cloud Developer Guide.

Before We Begin

Before running an instance, verify the requirements in the following table.

Verification Steps

1

Ensure you have a version 1.5.0 compatible Java Runtime installation, and that the JAVA_HOME environment variable has been correctly set. If not, see The Java Runtime Environment.

2

Ensure you have an active Amazon Web Services Account, and that you've signed up for both Amazon S3 and Amazon EC2. If not, see Setting up an Account.

3

Ensure that you have created a directory called .ec2 in your home directory for Linux/UNIX or a directory without spaces in Windows (e.g., C:\EC2), that contains your X.509 certificate and private key, and that they're named correctly. If not, see Signing up for Amazon EC2.

4

Ensure that the EC2_HOME environment variable has been correctly set. If not, see Telling the Tools Where They Live.

5

Ensure that the EC2_CERT and EC2_PRIVATE_KEY environment variables have been correctly set. If not, see Telling the Tools Who You Are.


Once these are correct, you are ready to launch your first instance.

Finding a Suitable AMI

To find a suitable AMI

  1. Use the ec2-describe-images command.

    PROMPT> ec2-describe-images -o self -o amazon | grep machine

    IMAGE ami-2c5fba45 ec2-public-images/demo-paid-AMI-v1.07.manifest.xml amazon available public A79EC0DB i386 machine
    IMAGE ami-bd9d78d4 ec2-public-images/demo-paid-AMI.manifest.xml amazon available public A79EC0DB i386 machine
    IMAGE ami-2f5fba46 ec2-public-images/developer-image-i386-v1.07.manifest.xml amazon available public i386 machine
    IMAGE ami-26b6534f ec2-public-images/developer-image.manifest.xml amazon available public i386 machine
    IMAGE ami-f51aff9c ec2-public-images/fedora-8-i386-base-v1.06.manifest.xml amazon available public i386 machine aki-a71cf9ce ari-a51cf9cc
    IMAGE ami-2b5fba42 ec2-public-images/fedora-8-i386-base-v1.07.manifest.xml amazon available public i386 machine aki-a71cf9ce ari-a51cf9cc
    IMAGE ami-f21aff9b ec2-public-images/fedora-8-x86_64-base-v1.06.manifest.xml amazon available public x86_64 machine aki-b51cf9dcari-b31cf9da
    IMAGE ami-2a5fba43 ec2-public-images/fedora-8-x86_64-base-v1.07.manifest.xml amazon available public x86_64 machine aki-b51cf9dcari-b31cf9da
    IMAGE ami-a21affcb ec2-public-images/fedora-core-6-x86_64-base-v1.06.manifest.xml amazon available public x86_64 machine aki-a53adfccari-a23adfcb
    IMAGE ami-2d5fba44 ec2-public-images/fedora-core-6-x86_64-base-v1.07.manifest.xml amazon available public x86_64 machine aki-a53adfccari-a23adfcb
    IMAGE ami-225fba4b ec2-public-images/fedora-core4-apache-mysql-v1.07.manifest.xml amazon available public i386 machine
    IMAGE ami-25b6534c ec2-public-images/fedora-core4-apache-mysql.manifest.xml amazon available public i386 machine
    IMAGE ami-2e5fba47 ec2-public-images/fedora-core4-apache-v1.07.manifest.xml amazon available public i386 machine
    IMAGE ami-23b6534a ec2-public-images/fedora-core4-apache.manifest.xml amazon available public i386 machine
    IMAGE ami-215fba48 ec2-public-images/fedora-core4-base-v1.07.manifest.xml amazon available public i386 machine
    IMAGE ami-20b65349 ec2-public-images/fedora-core4-base.manifest.xml amazon available public i386 machine
    IMAGE ami-205fba49 ec2-public-images/fedora-core4-i386-base-v1.07.manifest.xml amazon available public i386 machine aki-9b00e5f2
    IMAGE ami-255fba4c ec2-public-images/fedora-core4-mysql-v1.07.manifest.xml amazon available public i386 machine
    IMAGE ami-22b6534b ec2-public-images/fedora-core4-mysql.manifest.xml amazon available public i386 machine
    IMAGE ami-36ff1a5f ec2-public-images/fedora-core6-base-x86_64.manifest.xml amazon available public x86_64 machine
    IMAGE ami-235fba4a ec2-public-images/getting-started-v1.07.manifest.xml amazon available public i386 machine
    IMAGE ami-2bb65342 ec2-public-images/getting-started.manifest.xml amazon available public i386 machine

    The command lists your AMIs and Amazon's public AMIs. The output might not exactly match the preceding example.

  2. Look for the line containing the public image identified by the ec2-public-images/getting-started.manifest.xml value in the third column and note the corresponding value in the second column.

    This is the AMI ID you need. In this example, it is ami-2bb65342.

Generating an SSH Key Pair

You will run an instance of a public AMI. Since it has no password, you need a public/private key pair to login to the instance. One half of this key pair is embedded in your instance, allowing you to login securely without a password using the other half of the key pair. After learning to create your own images, you can choose other mechanisms to allow you to securely login to your new instances. Every key pair you generate requires a name. Be sure to choose a name that is easy to remember.

[Note]Note

If you lose the key pair file, you will not be able to access the instances launched with that key pair. However, you can always generate a new key pair to launch new instances.

To generate a key pair using gsg-keypair

  1. Enter the following information.

    PROMPT>  ec2-add-keypair gsg-keypair 

    Amazon EC2 returns a key pair, similar to the key pair in the following example.

    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-----
    MIIEoQIBAAKCAQBuLFg5ujHrtm1jnutSuoO8Xe56LlT+HM8v/xkaa39EstM3/aFxTHgElQiJLChp
    HungXQ29VTc8rc1bW0lkdi23OH5eqkMHGhvEwqa0HWASUMll4o3o/IX+0f2UcPoKCOVUR+jx71Sg
    5AU52EQfanIn3ZQ8lFW7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rBYvChJZF7LvUH4YmVpHAoGAbZ2X7XvoeEO+uZ58/BGKOIGHByHBDiXtzMhdJr15HTYjxK7OgTZm
    gK+8zp4L9IbvLGDMJO8vft32XPEWuvI8twCzFH+CsWLQADZMZKSsBasOZ/h1FwhdMgCMcY+Qlzd4
    JZKjTSu3i7vhvx6RzdSedXEMNTZWN4qlIx3kR5aHcukCgYA9T+Zrvm1F0seQPbLknn7EqhXIjBaT
    P8TTvW/6bdPi23ExzxZn7KOdrfclYRph1LHMpAONv/x2xALIf91UB+v5ohy1oDoasL0gij1houRe
    2ERKKdwz0ZL9SWq6VTdhr/5G994CK72fy5WhyERbDjUIdHaK3M849JJuf8cSrvSb4g==
    -----END RSA PRIVATE KEY-----

    The private key returned must be saved to a local file so that you can use it later.

  2. Create a file named id_rsa-gsg-keypair and paste the entire key generated in step 1, including the following lines.

    "-----BEGIN RSA PRIVATE KEY-----"
    "-----END RSA PRIVATE KEY-----"
  3. Confirm that the file contents looks similar to the following and save the file.

    You can save the file in any directory, but if you do not put it in your current directory, you should specify the full path when using commands that require the key pair.

     -----BEGIN RSA PRIVATE KEY-----
    MIIEoQIBAAKCAQBuLFg5ujHrtm1jnutSuoO8Xe56LlT+HM8v/xkaa39EstM3/aFxTHgElQiJLChp
    HungXQ29VTc8rc1bW0lkdi23OH5eqkMHGhvEwqa0HWASUMll4o3o/IX+0f2UcPoKCOVUR+jx71Sg
    5AU52EQfanIn3ZQ8lFW7Edp5a3q4DhjGlUKToHVbicL5E+g45zfB95wIyywWZfeW/UUF3LpGZyq/
    ebIUlq1qTbHkLbCC2r7RTn8vpQWp47BGVYGtGSBMpTRP5hnbzzuqj3itkiLHjU39S2sJCJ0TrJx5
    i8BygR4s3mHKBj8l+ePQxG1kGbF6R4yg6sECmXn17MRQVXODNHZbAgMBAAECggEAY1tsiUsIwDl5
    91CXirkYGuVfLyLflXenxfI50mDFms/mumTqloHO7tr0oriHDR5K7wMcY/YY5YkcXNo7mvUVD1pM
    ZNUJs7rw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y1oDoasL0gij1houRe
    2ERKKdwz0ZL9SWq6VTdhr/5G994CK72fy5WhyERbDjUIdHaK3M849JJuf8cSrvSb4g==
    -----END RSA PRIVATE KEY-----
  4. If you're using OpenSSH (or any reasonably paranoid SSH client), you should set the permissions of this file so it is only readable by you.

    On Linux and UNIX, enter the information in the following example.

    $  chmod 700 id_rsa-gsg-keypair ; ls -l id_rsa-gsg-keypair  

    You receive output similar to the following example.

    -rw-------  1 fred flintstones 1701 Jun 19 17:57 id_rsa-gsg-keypair 
[Note]Note

If you are using PuTTY in Windows, convert the private key to PuTTY's format. For more information on using PuTTy with Amazon EC2, see Appendix: PuTTY .

Running an Instance

To launch an instance of your AMI

  1. Use the ec2-run-instances command.

    PROMPT>  ec2-run-instances ami-235fba4a -k gsg-keypair

    Amazon EC2 returns output similar to the following example.


    RESERVATION r-7430c31d 924417782495 default
    INSTANCE i-ae0bf0c7 ami-2bb65342 pending gsg-keypair 0 m1.small 2008-03-21T16:19:25+0000 us-east-1a
  2. Look for the instance ID in the second field and write it down.

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

    It takes a few minutes for the instance to launch.

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

    PROMPT>  ec2-describe-instances i-ae0bf0c7 
    RESERVATION r-7430c31d 924417782495 default
    INSTANCE i-ae0bf0c7 ami-2bb65342 ec2-67-202-7-236.compute-1.amazonaws.com ip-10-251-31-162.ec2.internal running gsg-keypair 0 m1.small 2008-03-21T16:19:25+0000us-east-1a
[Important]Important

After launching an instance, you are billed hourly for running time. If you leave this tutorial at any time, make sure you terminate any instances you have started as described in Terminating Your Instances.

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

Authorizing Network Access to Your Instances

To authorize access to your instance

  • Enter the ec2-authorize command.

    PROMPT>  ec2-authorize default -p 22
    PERMISSION default ALLOWS tcp 22 22 FROM CIDR 0.0.0.0/0
    PROMPT> ec2-authorize default -p 80
    PERMISSION default ALLOWS tcp 80 80 FROM CIDR 0.0.0.0/0

    Since we didn't specify otherwise, your instance was launched in your default group. The first command authorizes network access to instances in your default group on the standard SSH port (22). Similarly, the second command opens up the standard HTTP port (80). For more details on controlling network security groups, see the Amazon EC2 Developer Guide.

[Caution]Caution

In this example, you enable any IP address to access port 22 of the instance. Although this might be acceptable for testing purposes, it is extremely unsafe for production environments. For production systems, you must obtain your public IP address ranges and grant access to those ranges only. For example, if your IP address is 123.123.123.123, you specify 123.123.123.123/32.

Connecting to your Instance

To connect to your instance

  1. Open a web browser and go to http:///, where is your instance's public hostname as returned by ec2-describe-instances (ec2-67-202-51-223.compute-1.amazonaws.com in the example).

    A webpage welcoming you to your instance displays.

    [Note]Note

    If the website times out, your instance might not have finished starting up. Wait a couple of minutes and try again.

  2. Whenever you launch a public AMI that you have not rebundled, run the ec2-get-console-output command and locate the SSH HOST KEY FINGERPRINTS section.

    PROMPT>  ec2-get-console-output instance_id

    ...
    ec2: -----BEGIN SSH HOST KEY FINGERPRINTS-----
    ec2: 2048 bc:89:29:c6:45:4b:b3:e2:c1:41:81:22:cb:3c:77:54
    /etc/ssh/ssh_host_key.pub
    ec2: 2048 fc:8d:0c:eb:0e:a6:4a:6a:61:50:00:c4:d2:51:78:66
    /etc/ssh/ssh_host_rsa_key.pub
    ec2: 1024 b5:cd:88:6a:18:7f:83:9d:1f:3b:80:03:10:17:7b:f5
    /etc/ssh/ssh_host_dsa_key.pub
    ec2: -----END SSH HOST KEY FINGERPRINTS-----

    ...

    Note the fingerprints. You will compare them in the next step.

  3. Use the following command to login as root and exercise full control over this instance as you would any host.

    PROMPT>  ssh -i id_rsa-gsg-keypair root@ec2-67-202-51-223.compute-1.amazonaws.com 
    The authenticity of host 'ec2-67-202-51-223.compute-1.amazonaws.com (216.182.225.42)' can't be established.
    RSA key fingerprint is fc:8d:0c:eb:0e:a6:4a:6a:61:50:00:c4:d2:51:78:66.
    Are you sure you want to continue connecting (yes/no)? yes
    Warning: Permanently added 'ec2-67-202-51-223.compute-1.amazonaws.com' (RSA) to the list of known hosts.
    Last login: Wed Jun 21 08:02:08 2006
    root@ec2-67-202-51-223 #

    If you are launching a public AMI, verify the fingerprint matches one of the fingerprints from the output of the ec2-get-console-output command. If it doesn't, someone might be attempting a "man-in-the-middle" attack.

[Note]Note

Your machine might have a different name for the preceding ssh command or even use different command line options. Consult the documentation for your machine or download one of the clients described in Accessing Linux and UNIX Instances through SSH Clients if you are unsure whether you have such a client installed. For more information about using PuTTY on Windows, see Appendix: PuTTY.

Congratulations

You've set up the tools and used them to run an instance based on a public AMI. You have learned enough to successfully use to run as many standard Linux/UNIX instances as you wish. You can run instances based on any of the public AMIs by following this process.

The next section builds on this success by having you connect to the running instance and customize it to create your own image. If you wish to save this for a later date, be sure to terminate any instances you have started as described in the section called “Terminating Your Instances”.

Cleaning Up

Terminating Your Instances

As soon as your instance starts to boot, you are billed for the resources it consumes. Once you have decided that you no longer require its services, you can terminate an instance using the instance identifier you received in Running an Instance.

[Note]Note

You cannot recover a terminated instance. However, you can launch additional instances of an AMI.

To terminate an instance

  • Execute the following command:

    PROMPT>  ec2-terminate-instances i-10a64379 
    INSTANCE i-10a64379 running shutting-down

    It takes a few minutes for the instance to terminate because Amazon EC2 needs to clean-up your data. For information on checking the status of your instance, see Running an Instance

[Tip]Tip

For Linux and UNIX, you can also terminate your instances by logging onto the instances with your ssh tool and running the "shutdown -h" command. Don't forget the "-h", otherwise you put your instance into single user mode, which is quite useless.

# /sbin/shutdown -h now  

For Windows, you can also terminate your instances by selecting Shutdown from the Start menu or by entering the following from the command line:

C:\> shutdown /s /t 0  

Deregistering Your AMI

If you no longer need your AMI you should deregister it from Amazon EC2.

For this task you'll need your AWS Access Key ID () and AWS Secret Access Key (). For more information on how to find these keys, see Signing up for Amazon S3.

To deregister an AMI

  • Execute the following command:

    PROMPT>  ec2-deregister ami-2bb65342 
    IMAGE ami-2bb65342

Removing Your AMI from Amazon S3

You can delete your deregistered AMIs from Amazon S3. If you don't, Amazon S3 continues to charge you for the space you are using.

The AMI tools contain a command to delete your image. You can get these from the resource center or they are installed on the instance from which you created the image.

To delete your AMI

  • Execute the following command:

    PROMPT> ec2-delete-bundle -b  -p sampleimage -a  -s  
    Deleting AMI bundle parts from https://s3.amazonaws.com/...
    Deleted sampleimage.part.00.
    Deleted sampleimage.part.01.
    Deleted sampleimage.part.02.
    Deleted sampleimage.part.03.
    ...
    Deleted sampleimage.part.23.
    Deleted sampleimage.part.24.
    Delete Bundle complete.
[Note]Note

If you are unable to run the AMI tools, you can use any Amazon S3 utility to delete AMIs.


//Lin u x u niL

No comments:

Post a Comment

tag ur valuable ideas below