How to set up the EC2 API Tools under Linux (Ubuntu 12.04 LTS)

by Alexander Weiß

A few weeks ago I wrote about setting up the EC2 API Tools under Windows. I decided to write the How to for Windows because there are not many guides for Windows available. Today I decided to write a guide for Linux, because I don’t want to give the impression, that I recommend Windows. In fact, it’s rather the opposite.

This guide is based on a fresh Ubuntu 12.04 LTS installation. If you use another distribution or version, you might have to alter the commands in this post to match them to your environment.

First you have to install a Java Runtime Environment, because the EC2 API Tools are written in Java. You can use the command “apt-get install default-jre” to install the OpenJDK Runtime Environment. If you want to install the Java Runtime environment from Oracle you have to download it form their website.

The EC2 API Tools require an environment variable “JAVA_HOME”, which points to the home directory of Java. You can either set it every time you open a new shell by using the export command. But if you plan to use the EC2 API Tools more than once in a while it is better to include it in the shell start-up scripts.

You can easily figure out where the Java executable lies by running the “which” command:

which java

The output should be “/usr/bin/java” and the correct path for the “JAVA_HOME” variable is “/usr”. Set the environment variable by executing the following command:

export JAVA_HOME=/usr

Verify that the variable is configured correctly:

$JAVA_HOME/bin/java –version

You shouldn’t get an error, but a display of the Java version.

Setting up the EC2 API Tools

The next step is to install the EC2 API Tools. However, calling it installation is kind of misleading here, because you don’t install anything you just have to download the tools, unzip them and configure some environment variables. You can download the EC2 API Tools here.

But before I write about the installation, I want to make a small excursion for the security aware among you: If you want to verify that the zip-file you have downloaded is not manipulated by a third party, you can validate the signature of the zip file with gpg. If you don’t know how to validate a signature with gpg, you can follow this guide.

The first environment variable you have to set is the “EC2_HOME” variable. It should point to the bin directory of the EC2 API Tools’ installation path. Before you know the path you have to unzip the EC2 API Tool file you have downloaded.

You probably don’t want your EC2 API Tools lying around in your download directory, so create a directory for them. After that unzip the files into the directory and move the files to the right directory, because they get unzipped into a subfolder:

mkdir /opt/ec2
unzip –d /opt/ec2 ec2-api-tools.zip
mv /opt/ec2/ec2-api-tools/* /opt/ec2/

If you used the same directory as I did, you have to set the “EC2_HOME” variable to “/opt/ec2”:

export EC2_HOME=/opt/ec2

You should also add the path to the EC2 API Tools’ bin directory to the PATH environment variable, because it will save you some typing:

export PATH=$PATH:$EC2_HOME/bin

Setting up AWS credentials for EC2 API Tools

To authenticate yourself to the EC2 API you have to invoke the EC2 API Tools commands with two parameters “aws-access-key” and “aws-secret-key”. As you don’t want to type the parameters and the keys every time you use the EC2 API Tools, you should set two more environment variables.

But first we have to know the value of both keys. Go to the Amazon Web Services homepage ( http://aws.amazon.com )  and click on “My Account/Console” -> ”Security Credentials”. Sign in and go to the section “Access Credentials”. Note the “Access Key ID” and the “Secret Access Key”. To get the last one you have to click on the link “Show”.

Now set the two environment variables:

export AWS_SECRET_KEY=”your AWS secret key”
export AWS_ACCESS_KEY=”your AWS access key”

Congratulations, you are done now. If you want to check if you have done everything right execute the command “ec2-describe-regions”. If you get a list of all EC2 regions you have done well and the EC2 API Tools are ready to use.

Advantages of using Linux

As I said in the beginning of the article I recommend using the EC2 API Tools under Linux. There are some advantages compared to using them under Windows:

  1. Many scripts, which make use of the EC2 API Tools and which can be found in the Internet, are written for Linux and require other Linux tools to work
  2. Many of the third party applications you can find in the Internet rely on the EC2 API Tools. Most of them are developed under Linux, so you might not use them under Windows or run into trouble if you want to use them under Windows
  3. The biggest advantage in my eyes is that the user base is much bigger for Linux. So if you run into any problems it should be a lot easier to find a solution or at least find someone who can help you

But I want to point out that the EC2 API Tools work perfectly under Windows. I often use them under Windows myself, but I often switch to Linux if I want to do something out of the ordinary. Do you share my experience? Is anybody running the tools under Cygwin?

VN:F [1.9.22_1171]
Rating: 10.0/10 (1 vote cast)
VN:F [1.9.22_1171]
Rating: +1 (from 1 vote)
How to set up the EC2 API Tools under Linux (Ubuntu 12.04 LTS), 10.0 out of 10 based on 1 rating