To be able to execute the many API command line tools you will need to setup and configure the authentication correctly.
This will help you to do just that.
1. Download the Autoscalling CLI, CloudWatch and ec2-API-Tools
cd /opt
wget “http://ec2-downloads.s3.amazonaws.com/AutoScaling-2011-01-01.zip”
unzip AutoScaling-2011-01-01.zip && mv AutoScaling-2011-01-01.zip AutoScaling
wget “http://ec2-downloads.s3.amazonaws.com/CloudWatch-2010-08-01.zip”
unzip CloudWatch-2010-08-01.zip && mv CloudWatch-2010-08-01.zip cloudwatch
wget “http://www.amazon.com/gp/redirect.html/ref=aws_rc_ec2tools?location=http://s3.amazonaws.com/ec2-downloads/ec2-api-tools.zip&token=A80325AA4DAB186C80828ED5138633E3F49160D9”
unzip ec2-api-tools.zip && mv ec2-api-tools ec2tools
2-Setup CLI add this to /etc/profile
Considering cert_aws.pem is your certificate
#SET EC2 CMDS
export JAVA_HOME=/usr/lib/jvm/java-1.6.0-openjdk.x86_64/
export AWS_AUTO_SCALING_HOME=/opt/AutoScaling
export AWS_CLOUDWATCH_HOME=/opt/cloudwatch
export EC2_HOME=/opt/ec2tools
#export EC2_PRIVATE_KEY=$AWS_AUTO_SCALING_HOME/cert_aws.pem
#export EC2_CERT=$AWS_AUTO_SCALING_HOME/cert_aws.pem
export PATH=$PATH:$AWS_AUTO_SCALING_HOME/bin:$EC2_HOME/bin:$AWS_CLOUDWATCH_HOME/bin
export AWS_AUTO_SCALING_URL=https://autoscaling.us-east-1.amazonaws.com
export AWS_CREDENTIAL_FILE=/opt/AutoScaling/key.txt
3. Get the Access Credentials from IAM menu save it to somewhere
Go to the user menu and > Manage Access Key > Create New Key
Save that to the format of the file /opt/AutoScaling/key.txt has to be:
AWSAccessKeyId=
AWSSecretKey=
Make sure /opt/AutoScaling/key.txt is only accessed by root!
4. Testing
source /etc/profile
as-describe-scaling-activities
as-describe-adjustment-types
The script:

#!/bin/bash
# script to get running instances of specific name
# by Felipe Ferreira Sept 2013
#Requirements: AWS tools installed and working without asking for password (how to setup)
#Requirements-link = http://felipeferreira.net/?p=1341
#SET EC2 CMDS
export JAVA_HOME=/usr/lib/jvm/java-1.6.0-openjdk.x86_64/
export AWS_AUTO_SCALING_HOME=/opt/AutoScaling
export AWS_CLOUDWATCH_HOME=/opt/cloudwatch
export PATH=$PATH:$AWS_AUTO_SCALING_HOME/bin:$EC2_HOME/bin:$AWS_CLOUDWATCH_HOME/bin
export AWS_AUTO_SCALING_URL=https://autoscaling.us-east-1.amazonaws.com
export AWS_CREDENTIAL_FILE=/opt/AutoScaling/key.txt
###################################################################
NAME="amzvarnish00"
NAME=$1
TMP="/tmp/insta.txt"
`/opt/ec2tools/bin/ec2-describe-instances |grep -A3 $NAME |awk '{ print $4 }' |grep ec2 > $TMP`
INSTANCE=`cat $TMP`
NI=`grep -c ec2 $TMP`
MSG="OK - $NI Instances of $NAME are: $INSTANCE|instances=$NI"
echo $MSG
rm -f $NI
exit 0
[root@nagios1 libexec]# cat check_aws.sh
#!/bin/bash
#This script uses AWS command line tools to get information from Amazon CloudWatch metrics
#Should be used with nagios
#by Felipe Ferreira May 2013
#Requirements: AWS tools installed and working without asking for password (how to setup)
#Requirements-link = http://felipeferreira.net/?p=1341
#SET EC2 CMDS
export JAVA_HOME=/usr/lib/jvm/java-1.6.0-openjdk.x86_64/
export AWS_AUTO_SCALING_HOME=/opt/AutoScaling
export AWS_CLOUDWATCH_HOME=/opt/cloudwatch
export PATH=$PATH:$AWS_AUTO_SCALING_HOME/bin:$EC2_HOME/bin:$AWS_CLOUDWATCH_HOME/bin
export AWS_AUTO_SCALING_URL=https://autoscaling.us-east-1.amazonaws.com
export AWS_CREDENTIAL_FILE=/opt/AutoScaling/key.txt
VERBOSE=0
outputDebug() {
    if [ $VERBOSE -gt 0 ] ; then
        echo -e "$1"
    fi
}
if [ $# -eq 0 ] ; then
    TEMP="-h"
else
    TEMP=`getopt -o vh -l 'versbose,help,d:,n:,t:,p:,s:,w:,c:' -- "$@"`
fi
outputDebug "Processing Args $TEMP"
if [ $? != 0 ] ; then echo "Terminating..." >&2 ; exit 1 ; fi
eval set -- "$TEM

P"
while true ; do
    case "$1" in
        -v|--verbose) VERBOSE=1 ; outputDebug "Verbose Mode ON" ; shift ;;
        -h|--help) echo "Usage: $0 [--d DIMENSION] [--n NAMESPACE] [--t TYPE] [--p PERIOD] [--s STATISTC(Average|Sum)]  [--w WARN] [--c CRITICAL]  [-v|--verbose] " ; exit 0;;
        --d) outputDebug "Option $1 is $2" ; DIMENSION=$2 ; shift 2;;
        --n) outputDebug "Option $1 is $2" ; NAMESPACE=$2 ; shift 2;;
        --t) outputDebug "Option $1 is $2" ; TYPE=$2 ; shift 2;;
        --p) outputDebug "Option $1 is $2" ; PERIOD=$2 ; shift 2;;
        --s) outputDebug "Option $1 is $2" ; STATS=$2 ; shift 2;;
        --w) outputDebug "Option $1 is $2" ; WARN=$2 ; shift 2;;
        --c) outputDebug "Option $1 is $2" ; CRIT=$2 ; shift 2;;
        --) shift ; break ;;
        *) echo "Internal error! - found $1 and $2" ; exit 3 ;;
    esac
done
CMD="mon-get-stats  $TYPE --namespace '${NAMESPACE}' --statistics ${STATS} --period ${PERIOD} --dimensions '${DIMENSION}'"
outputDebug "Executing: \n $CMD"
#RESULT=`eval ${C

MD}|tail -n1|awk '{ printf "%.0f\n",$3}'|cut -b0-4`
RESULT=`eval ${CMD}|tail -n1|awk '{ printf "%.0f\n",$3}'`
outputDebug "Result of cmd is: $RESULT"
if [ $RESULT -gt $CRIT ]; then
   echo "CRITICAL - $DIMENSION ${TYPE}=${RESULT} |$TYPE=$RESULT"
   exit 2
elif [ $RESULT -gt $WARN ]; then
   echo "WARNING - $DIMENSION ${TYPE}=${RESULT} |$TYPE=$RESULT"
   exit 1
else
   echo "OK - $DIMENSION ${TYPE}=${RESULT} |$TYPE=$RESULT"
   exit 0
fi

To setup Auto-Scale check out my script at http://felipeferreira.net/?p=1337

Tags: , , , , , , , , , , ,

Leave a Reply

Your email address will not be published. Required fields are marked *