Saturday 9 February 2013

SettingUpAWSapi

Setting Up AWS api:  [ Amazon command line tools ] :

I am using ubuntu 12.10 and for the long time I was getting error while setting up AWS api in my system:

export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64/jre
export EC2_HOME=~/ec2
export EC2_PRIVATE_KEY=<Private_key_path>
export EC2_CERT=<Cert_path>

For other aws api:
export AWS_ELB_HOME=~/elb

export AWS_CLOUDWATCH_HOME=~/cw

PATH=$PATH:$JAVA_HOME/bin:$EC2_HOME/bin

Note:

You can create different scripts, where you specify different EC2_CERT and EC2_PRIVATE_KEY to access your different aws account, example [dev, qa or prod]

For other api call: 
http://aws.amazon.com/developertools/

For AMI CLI: 
http://awsiammedia.s3.amazonaws.com/public/tools/cli/latest/IAMCli.zip

For ElasticBeanstalk CLI:
https://s3.amazonaws.com/elasticbeanstalk/cli/AWS-ElasticBeanstalk-CLI-2.6.0.zip

For ELB CLI:
http://ec2-downloads.s3.amazonaws.com/ElasticLoadBalancing.zip

For AutoScalling CLI:
http://ec2-downloads.s3.amazonaws.com/AutoScaling-2011-01-01.zip


For S3 CLI:
http://code.google.com/p/lits3/downloads/detail?name=LitS3-Commander-0.8.4.zip


Even after above setting I was getting java related error... and I stared trying solving the same issue, checked some on-line links and found lots of people have similar issue. [ I was my mistake that I was keeping all the aws command in a same directory. ]

I removed all the jre and java related package from my ubuntu system and reinstall those pkg again but the similar issue.

The error was something like:
ec2-describe-regions
Error: Could not find or load main class com.amazon.aes.webservices.client.cmd.DescribeRegions

Then I started looking around the JAVA CLASSPATH... again spent some more time. But the good part that I understand that in hard way... after working for long hours. As a SRE/DEVOPS person, when started from Linux System Administrator, understanding java error took some time :)

Started looking the aws command code:

amitmund@amitmundlaptop:~/ec2/bin$ cat ../ec2-api-tools-1.6.0.0/bin/ec2-describe-regions
#!/usr/bin/env bash

# Copyright 2006-2010 Amazon.com, Inc. or its affiliates.  All Rights Reserved.  Licensed under the
# Amazon Software License (the "License").  You may not use this file except in compliance with the License. A copy of the
# License is located at http://aws.amazon.com/asl or in the "license" file accompanying this file.  This file is distributed on an "AS
# IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific
# language governing permissions and limitations under the License.

__ZIP_PREFIX__EC2_HOME="${EC2_HOME:?EC2_HOME is not set}"
__RPM_PREFIX__EC2_HOME=/usr/local/aes/cmdline
"${EC2_HOME}"/bin/ec2-cmd DescribeRegions "$@"

 And then followed the ec2-cmd:

amitmund@amitmundlaptop:~/ec2/bin$ cat ec2-cmd
#!/usr/bin/env bash

# Copyright 2006-2009 Amazon.com, Inc. or its affiliates.  All Rights Reserved.  Licensed under the
# Amazon Software License (the "License").  You may not use this file except in compliance with the License. A copy of the
# License is located at http://aws.amazon.com/asl or in the "license" file accompanying this file.  This file is distributed on an "AS
# IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific
# language governing permissions and limitations under the License.

# This script "concentrates" all of our Java invocations into a single location
# for maintainability.

# 'Globals'
__ZIP_PREFIX__EC2_HOME="${EC2_HOME:-EC2_HOME is not set}"
__RPM_PREFIX__EC2_HOME=/usr/local/aes/cmdline
LIBDIR="${EC2_HOME}/lib"

# Check our Java env
JAVA_HOME=${JAVA_HOME:?JAVA_HOME is not set}

# If a classpath exists preserve it
CP="${CLASSPATH}"

# Check for cygwin bash so we use the correct path separator
case "`uname`" in
    CYGWIN*) cygwin=true;;
esac

# ---- Start of Cygwin test ----

cygprop=""

# And add our own libraries too
if [ "${cygwin}" == "true" ] ; then
    cygprop="-Dec2.cygwin=true"

    # Make sure that when using Cygwin we use Unix
    # Semantics for EC2_HOME
    if [ -n "${EC2_HOME}" ]
    then
        if echo "${EC2_HOME}"|egrep -q '[[:alpha:]]:\\'
        then
            echo
            echo " *INFO* Your EC2_HOME variable needs to specified as a Unix path under Cygwin"
            echo
        fi
    fi

# ---- End of Cygwin Tests ----

    for jar in "${LIBDIR}"/*.jar ; do
        cygjar=$(cygpath -w -a "${jar}")
        CP="${CP};${cygjar}"
    done
else
    for jar in "${LIBDIR}"/*.jar ; do
        CP="${CP}:${jar}"
    done
fi

CMD=$1
shift
"${JAVA_HOME}/bin/java" ${EC2_JVM_ARGS} ${cygprop} -classpath "${CP}" "com.amazon.aes.webservices.client.cmd.${CMD}" $EC2_DEFAULT_ARGS "$@"

 then I found it is looking for classpath and the jar files from the same directory's lib folder from were I have copied the aws commands.

 Later I created a "lib" directory in the same location where I created the "bin" directory for all the aws command line tools and started coping the "jar" files from all the original directory to this "lib" directory and its started working. :)





so.... where I was doing mistake?

I have downloaded all the aip from Amazon site... and it around few different zip files from windows and linux environment...

e.g:

AutoScaling-2010-08-01.zip
CloudWatch-2010-08-01.zip
ec2-api-tools.zip  RDSCli.zip
AWSCloudFormation-cli.zip 
ec2-ami-tools.zip        
IAMCli.zip

But what I did, to set the a single EC2_HOME directory, I extracted all these directory and copied all the aws command from those directories "bin" directory and copied them to ~/ec2/bin and not the related "lib" directory where all the related jar files were there.  Because of that I was getting the following error:

Error: Could not find or load main class com.amazon.aes.webservices.client.cmd.DescribeRegions







No comments:

Post a Comment