Here I’ll be posting the basics of getting and setting up the AWS AMI, API and Cloudwatch tools.
This is my first post on a series of entries I plan to include for several features AWS offers such as auto scaling or setting up a ElasticSearch using AWS.
Things you will need:
First let’s download the tools:
$ wget http://s3.amazonaws.com/ec2-downloads/ec2-api-tools.zip
$ wget http://s3.amazonaws.com/ec2-downloads/ec2-ami-tools.zip
$ wget http://ec2-downloads.s3.amazonaws.com/cloudwatch-samples/CloudWatchMonitoringScripts-v1.1.0.zip
$ wget http://ec2-downloads.s3.amazonaws.com/AutoScaling-2011-01-01.zip
Unzip each one in the directory of your choosing. I prefer to move them to /opt/ and unzip them there.
$mv ec2* /opt/
$mv Cloud* /opt/
$mv AutoScaling* /opt/
$cd /opt/
$unzip ec2-api-tools.zip
$unzip ec2-ami-tools.zip
$unzip CloudWatchMonitoringScripts-v1.1.0.zip
$unzip AutoScaling-2011-01-01.zip
Since I want one EC2_HOME directory in my PATH for both the API and AMI tools I copied the commands from /bin in the AMI directory to the API one:
$cp /opt/ec2-ami-tools-1.4.0.9/bin/* /opt/ec2-api-tools-1.6.7.4/bin/
And the library tools as well:
cp -r /opt/ec2-ami-tools-1.4.0.9/lib/ec2 /opt/ec2-api-tools-1.6.7.4/lib/
It seems that not following this step will cause the commands for the AMI tools to fail. Probably since they both require to have EC2_HOME specified in the .bashrc file. It just seems easier to copy them over.
Next you will need to add both the tools and Java to your PATH. You can either do this as a one time thing if you only plan to use the command line tools once or edit your local .bashrc file and editing it.
For the temporary method:
$export JAVA_HOME=/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.25.x86_64/jre
$export EC2_HOME=/opt/ec2-api-tools-1.6.11.0
$export AWS_CLOUDWATCH_HOME=/opt/CloudWatch-1.0.13.4
$export AWS_AUTO_SCALING_HOME=/opt/AutoScaling-1.0.61.2
Now if you’d like to edit the .bashrc file and make it permanent here is what my .bashrc file looks like:
PATH=$PATH:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games
export EC2_HOME=/opt/ec2-api-tools-1.6.7.4
export AWS_CLOUDWATCH_HOME=/opt/CloudWatch-1.0.13.4
export AWS_AUTO_SCALING_HOME=/opt/AutoScaling-1.0.61.2
export AWS_ACCESS_KEY=AWS-KEY-HERE
export AWS_SECRET_KEY=AWS-SECRET-KEY-HERE
export JAVA_HOME=/usr/lib/jvm/java-1.7.0-openjdk-amd64
export PATH=$PATH:$EC2_HOME/bin:$AWS_AUTO_SCALING_HOME/bin:$AWS_CLOUDWATCH_HOME/bin
Don’t forget to source it after:
$source .bashrc
Test it by running the following:
$ec2-describe-regions
$mon-cmd
$as-cmd
If you can enter all those without any errors then you’re good to go.
The AMI tools will require a –cert /path/to/certfile, –privatekey /path/to/keyfile/ –user AWS_ID (no dashes)
Notes:
You CAN copy all the commands from each perspective /bin folder an into one single location and edit the bashrc file accordingly.
Known issue:
running ec2-cmd will not work. It will generate an error: Error: Could not find or load main class com.amazon.aes.webservices.client.cmd. This could be because I didn’t download every AWS tool and obtain every .jar file needed to be in the API’s /lib directory. This won’t prevent the other ec2- commands from working though.
This is a work in progress and if you would like to contribute to this post please leave a comment. If it helps improve this tutorial I’ll update it and of course give credit.
Post By: Gabriel Holder | Add to favorites
Nick
Thursday, May 22, 2014
Great article Gabriel
a
Friday, June 20, 2014
Wonderful beat ! I wish to apprentice at the same time as you
amend your website, how could i subscribe for a blog web site?
The account aided me a appropriate deal. I had been tiny
bit familiar of this your broadcast offered vibrant transparent concept
Jason
Tuesday, October 22, 2013
Thanks gabriel for posting this. I was looking around for something like this. It really helped.