Amazon EC2 How to – Part 4: setup API Tools (Windows)

by Alexander Weiß

So far I only wrote about the Amazon EC2 Management Console. But there is another way to manage the Amazon Cloud: The Amazon EC2 API Tools. It offers tools for many purposes, but is not easy to set up. Here’s a how to setup Amazon EC2 Command Line Tool in Windows.

First we have to set up the environment. You need to install the Java Run Time Environment and the Amazon EC2 API Tools:

  1. Install Java. You can download it here.
  2. Verify that java is included in the OS search path, e.g. open a shell and execute the command “java –version”. If you get an error, check if the environment variable JAVA_HOME is set. If that is not the case use the command “setx” to set the path (run it as an admin): [Environment]::SetEnvironmentVariable('JAVA_HOME','C:\Program File (x86)\java\jre7'.'Machine')
  3. Download the Amazon EC2 API Tools here.
  4. Extract the tools to the directory C:\EC2.
  5. Verify that the directory C:\EC2\bin exists. If the folder is missing, there could be a subfolder called something like ec2-api-tools-vXXX. If that is the case move the content of the subfolder to the folder C:\EC2.
  6. Set the environment variable EC2_HOME: setx EC2_HOME C:\EC2 (You have to run the command from a shell with administrator privileges)
  7. Verify that the variable is set correctly: dir %EC2_HOME% (You should see the directory content of C:\ec2\bin. If you get a “File Not Found” message as the result, something didn’t work. Make sure you use a shell with administrator privileges )
  8. You can add C:\ec2\bin to your path variable: [Environment]::SetEnvironmentVariable('Path','%PATH%;C:\EC2\bin','Machine')

The next step is to provide your credentials for the API Tools, so they know who you are:

  1. Go to the Amazon Web Services homepage
  2. Click on “My Account/Console” -> ”Security Credentials”
  3. Sign in and go to the section “Access Credentials”. Not the “Access Key ID” and the “Secret Access Key”. To get the last one you have to click on the link “Show”:
How to set up Amazon EC2 API Tools: access credentials

How to set up Amazon EC2 API Tools: access credentials

  1. You can use these keys with the command line options –O (–aws-access-key) or –W (–aws-secret-key).
  2. If you use them regularly it is easier to set the according environment variables. Be careful, and only set the environment variables, if you are sure that nobody will ever be able to read them. They grant access to your AWS infrastructure. You can cahnge the ‘Machine’ part to ‘User’ if you want that the variable are only available for the User who executes the command.
    [Environment]::SetEnvironmentVariable('AWS_ACCESS_KEY', 'your-aws-access-key', 'Machine')
    [Environment]::SetEnvironmentVariable('AWS_SECRET_KEY', 'your-aws-secret-key', 'Machine')

Verify that everything is working as intended by typing “ec2-describe-regions”. The output should look similar to this screenshot:

How to set up Amazon EC2 API Tools: display regions

How to set up Amazon EC2 API Tools: display regions

Now you are nearly done. Before you can use the Amazon EC2 API Tools to manage your instances you have to tell them in which regions your instances are running:

  1. Get the URL for your region by running the “ec2-describe-regions” command
  2. Set the EC2_URL environment variable to your region URL, e.g. “ec2.us-west-1.amazonaws.com”:
    [Environment]::SetEnvironmentVariable('EC2_URL', 'https://ec2.us-west-1.amazonaws.com', 'Machine')

Now you are ready to manage EC2 with the Amazon EC2 Command Line Tools. You’ll find an
overview of the commands here.

The Amazon EC2 API Tools supply very powerful tools for managing EC2. I will introduce some of the API Tools in future blog posts. If you are interested about any API Tool let me know and I’ll write about them as soon as possible.

VN:F [1.9.22_1171]
Rating: 0.0/10 (0 votes cast)
VN:F [1.9.22_1171]
Rating: 0 (from 0 votes)