AWS setting up command line tools in Cygwin

Posted on Tuesday, October 23, 2012



I use the amazon command line tools a lot, its often a quicker way to accomplish things quickly versus the AWS web interface,  though the AWS web interface has gotten a lot better over the past few years)


In this guide I am going to show how to set up the command lines tools using Cygwin, I have another (slightly different guide for Ubuntu)


This guide of course assumes you already have an Amazon AWS account.



Cygwin AWS setup


First you need a place to put all the keys you will use from AWS.    These keys will be referenced by your program

Open up Cygwin and from the home directory create a “.ec2” folder .


       > mkdir ~/.ec2



Get the keys setup


Now get some keys to put in there.

































Click on My Account/Console  ->  Security Credentials



Sign in using your username/password



Scroll down to the “Access Credentials” and select the X.509 Certificates and click Create a new Certificate.








































Click on Download Private Key File and save the file to the .ec2 folder




















Then click on the “Download X.509 Certificate” button and save the certificate to the .ec2 folder


Now log into AWS Management Console

Open up http://aws.amazon.com [1]






















Click on My Account/Console -> AWS Management Console








Click on EC2
































Click on Key Pairs under the “Network & Security”

















Click on Create Key Pair

















Give it a name and click create.
























A prompt to save this file will appear, save it to the .ec2 directory




Install Command line tools



And do a quick search for command-line. 


 








Here is a EC2 command line tool.  You will see that there are different command line tools for different AWS services  (EC2, RDS, etc)  For now just get the EC2 command line tool



This is the main EC2 command line API tool to look for.

It is located at
http://aws.amazon.com/developertools/351









Click on Download the Amazon EC2 API tools from Amazon S3
Create a folder in your home directory named ec2-api-tools


       >  cd
       >  mkdir ec2-api-tools


Now unzip the downloaded command line tools into this directory



       >  cd ~/ec2-api-tools
       >  unzip /cygdrive/c/Users/patman/Downloads/ec2-api-tools.zip
       >  mv ec2-api-tools-1.6.4/* .
       >  rm -r ec2-api-tools-1.6.4
       >  ls -alh










This should put a bin and a lib folder





Edit .bashrc


Edit .bashrc


       >    cd
       >    vi .bashrc


Add the following to the end of the file   


export EC2_HOME=$HOME/ec2-api-tools
export EC2_PRIVATE_KEY=$HOME/.ec2/pk-XXXXX.pem
export EC2_CERT=$HOME/.ec2/cert-XXXXX.pem
export PATH=$PATH:$EC2_HOME/bin
export JAVA_HOME=/cygdrive/c/Windows/System32/java







If your "default" region is not going to be the east coast you can set your default region in your bash file


EC2_URL=https://ec2.us-west-2.amazon.com


This would be for the Oregon (us-west-2) region


Now run source


       >  source .bashrc



You may need to close and reopone the Cygwin window as source does not seem to work, at least for me.


Now attempt to run this command


       >  ec2-describe-keypairs



If you want to check a different region than your default region use the --region flag


> ec2-describe-keypairs --region us-west-2




You may get an error like this


If this is the case then within Cygwin run the following commands
(assuming you have Java installed on your machine)


       >  mkdir -p /cygdrive/c/Windows/System32/java/bin
       >  cp /cygdrive/c/Windows/System32/java.exe /cygdrive/c/Windows/System32/java/bin/


Now rerun the command.
This will list your keypairs


(I whited my actual numbers out J )



References
[1]  Amazon Web Services 
       http://aws.amazon.com
       Visited 10/2012
[2] AWS Developer Tools 
       Visited 10/2012

   

4 comments:

  1. You might want to add setting the Region Endpoint to the tutorial. I use US-WEST-2 (Oregon) for everything, and the ec2-describe-keypairs wasn't returning any data because it was defaulting to US-EAST-1 (N. Virginia). Once I added:

    export EC2_URL=https://ec2.us-west-2.amazonaws.com

    to my .bashrc, then everything started working.

    Thanks for the tutorial!

    Toolie

    ReplyDelete
    Replies

    1. Very good point, and thanks for the catch. Remember what you want your default region to be and set it.

      If you happen to use more than one region most command line commands have a region flag you can set. For example

      ec2-describe-keypairs --region us-west-2

      Would be for Oregon

      I will update the guide to better explain this.

      Delete
  2. $ ec2-describe-keypairs
    Client.UnsupportedProtocol: SOAP is not supported for API version [2014-05-01]. Please refer to the following documentation for more details: http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/using-soap-api.html

    ReplyDelete
    Replies
    1. Oops looks like its time to redo the tutorial and update my tools as well. I just have done a lot of command line builds in AWS in the last few months so I did not notice the change.

      Delete