Posts

Showing posts from August, 2013

Bash functions to simply finding instance IPs when using AWS CLI

We have both EC2 and VPC nodes. Sometimes it is convenient to run bash commands without having to copy and paste the values from the WebUI. Here are a couple of bash functions to do that: function i2ip () {   local NAME="$1"   local IP   for IP in `ec2-describe-instances --filter instance-state-name=running --filter instance-id=${NAME:?MISSING_VALUE} | grep ^INSTANCE | awk '{ if ( $4 ~ /^ec2/ ) print $4; else print $12; }'` ; do   echo ${IP}   done } function n2ip () {   local NAME="$1"   local IP   for IP in `ec2-describe-instances --filter instance-state-name=running --filter tag:Name=${NAME:?MISSING_VALUE} | grep ^INSTANCE | awk '{ if ( $4 ~ /^ec2/ ) print $4; else print $12; }'` ; do   echo ${IP}   done } you might do something like this: rsync -av --progress logstash $(n2ip rpmbuild-node):/tmp/. where "rpmbuild-node" was the value of a tag "Name" on the instance. I decided to return all of the values so I could handle t