Skip to content

Instantly share code, notes, and snippets.

@arashilmg
Created February 8, 2020 10:13
Show Gist options
  • Save arashilmg/5ee795ae87dc8b6c72c76c9080730e07 to your computer and use it in GitHub Desktop.
Save arashilmg/5ee795ae87dc8b6c72c76c9080730e07 to your computer and use it in GitHub Desktop.
AWSLogs fuzzyfinder (realtime and past)
function awslogzf() {
local PROFILE=`cat ~/.aws/credentials | egrep "\[" | sed "s/\[\(.*\)\]/\1/" | fzf `;
local GROUP=`awslogs groups --profile $PROFILE | fzf `;
local SELECTTIEM=`echo -e "realtime\npast" | fzf +m`;
if [[ $SELECTTIEM == "realtime" ]]; then
local TIMESPAN="-w" ;
else
local MINSAGO=$(for i in `seq 10 10 10080`; do echo $i "->" $(date -d -${i}min) ; done | fzf --prompt="10minutes from: "| tr "\t" " " | tr -s " " | cut -d " " -f1 | sort -n | sed -e 1b -e '$!d');
local FROM=`echo $MINSAGO | cut -d " " -f2 `
local TILL=`echo $MINSAGO | cut -d " " -f1 `
local TIMESPAN="-s ${FROM}m -e `echo $TILL-10 |bc`m";
fi;
set -x;
awslogs get $GROUP -S $TIMESPAN --profile $PROFILE;
{ set +x ;} 2> /dev/null ;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment