How to set up Amazon EC2 command-line tools

This article describes how to set up Amazon Elastic Compute Cloud (Amazon EC2) command-line tools on the Windows and Linux operating systems.

Contents


To set up Amazon EC2 command-line tools on Windows
To set up Amazon EC2 command-line tools on Linux
Amazon EC2 command-line tool examples
 
Note: To learn how to set up Amazon EC2 on the OS X operating system, see Starting Amazon EC2 with OS X (by Robert Sosinski).

To set up Amazon EC2 command-line tools on Windows

  1. Install the latest version of the Sun Java Development Kit (JDK) from the Oracle website.
     
  2. Set the JAVA_HOME environment variable to the Java installation root. More details about how to add environment variables can be found Instruct Wowza Streaming Engine Server to use a specific version of Java.
     
  3. Verify that the JDK is installed properly by entering the following command at a command prompt:
    java -version
    If working properly, the Java version is returned.
     
  4. Download the Amazon EC2 API Tools from Amazon S3.
     
  5. Extract the command-line tools from the compressed (zipped) folder to a folder named %SystemDrive%EC2 such that the following path exists: %SystemDrive%\EC2\bin (for example, C:\EC2\bin).
  6. Add %SystemDrive%\EC2\bin (for example, C:\EC2\bin) to the Path environment variable.
     
  7. Create a folder named %SystemDrive%\EC2\keys and then download your X.509 certificate and your Private Key to this folder. You'll end up with files that look similar to the following:
     
    C:\EC2\keys\pk-THCY4RVPOKCCHPJFIQTDVNMWCJJQPOXU.pem

    C:\EC2\keys\cert-THCY4RVPOKCCHPJFIQTDVNMWCJJQPOXU.pem
  8. Create environment variables that point to the keys and base folder, as shown in the following example (your key/cert file names will be different):
     
    EC2_HOME: C:\EC2

    EC2_PRIVATE_KEY: C:\EC2\keys\pk-THCY4RVPOKCCHPJFIQTDVNMWCJJQPOXU.pem

    EC2_CERT: C:\EC2\keys\cert-THCY4RVPOKCCHPJFIQTDVNMWCJJQPOXU.pem

To set up Amazon EC2 command-line tools on Linux

  1. Install the latest version of the Sun Java Development Kit (JDK) from the Oracle website.
     
  2. Verify that the JDK is installed properly by entering the following in a command shell:
    [user@domain /]# java -verison
  3. Download the Amazon EC2 API Tools from Amazon S3 to your ~/ home directory.
     
  4. Unzip the command-line tools file and extract:
    [user@domain /]# unzip ec2-api-tools.zip -d ~/ec2-tools
    Archive:  ec2-api-tools.zip
    creating: ec2-api-tools-x.x.x.x/
    inflating: ec2-api-tools-x.x.x.x/THIRDPARTYLICENSE.TXT  
    creating: ec2-api-tools-x.x.x.x/bin/
    ....
  5. Login to your Amazon Web Services (AWS) Security Credentials page. In the "Access Credentials" section of the webpage, click the X.509 Certificates tab.
     
  6. Underneath the list of X.509 certificates, click Create a new Certificate. This will create a new Private Key file (pk-xxxxxxxx.pem) and certificate file (cert-xxxxxxxx.pem). Download these files from the X509 Certificate Created dialog box to your Amazon EC2 API Tools install directory (for example, ~/ec2-tools/ec2-api-tools-x.x.x.x/).
     
  7. Set your environment variables. To do this, modify your ~/.bash_profile and add the following:
    export EC2_HOME=~/ec2-tools/ec2-api-tools-x.x.x.x
    export PATH=$PATH:$EC2_HOME/bin
    export EC2_PRIVATE_KEY=`ls $EC2_HOME/pk-*.pem`
    export EC2_CERT=`ls $EC2_HOME/cert-*.pem`
    export JAVA_HOME=/path/to/java/installation
    Where /path/to/java/installation is the Java base installation path (for example, /usr/java/jrex.x.x_xx).

    You can determine your Java installation path by typing the following command:
    [user@domain /]# readlink -f $(which java)
    /usr/java/jrex.x.x_xx/bin/java
    Be sure to strip /bin/java from the path value that's returned as you just need the base installation. Using the preceding example, the JAVA_HOME environment variable is /usr/java/jrex.x.x_xx.

Amazon EC2 command-line tool examples

Note: See Amazon's Commands (CLI Tools) documentation for a complete list of options and attributes for each command.
  1. Get a list of all available Amazon Machine Image (AMI) IDs:
    ec2-describe-images --region us-east-1 -x all
  2. Create a Wowza media server for Amazon EC2 instance using one of our pre-built AMIs with a specific key:
    ec2-run-instances ami-c2fd6dab -k keyfilename
    Where ami-c2fd6dab is the Wowza media server AMI ID and keyfilename is the key file name. The response will contain your new instance ID. This can be used for subsequent terminations.
     
  3. Do the following to terminate the instance (Note: You can't restore the instance after this operation):
    ec2-terminate-instances i-xxxxxxxxxx
    The response will indicate "running shutting-down" if successful.
     
  4. Create a new Amazon EC2 key pair. A key pair is a security credential similar to a password and is specific to an AWS region. The following example creates a key pair for the us-east-1 region (substitute the region of your choice):
    ec2-create-keypair keypairname --region us-east-1
    Where keypairname is the name for the key pair. This will return a string consisting of the Private Key as an unencrypted PEM-encoded PKCS#8 Private Key.

Originally Published: 10-01-2010
 

If you're having problems or want to discuss this article, post in our forum.