Skip to content

Instantly share code, notes, and snippets.

@jmlrt
Created June 27, 2017 09:58
Show Gist options
  • Save jmlrt/27e4648261ec096f1ed2c00801327780 to your computer and use it in GitHub Desktop.
Save jmlrt/27e4648261ec096f1ed2c00801327780 to your computer and use it in GitHub Desktop.
#!/bin/bash
#
# Download and compress cloudwatch log for the specified group, stream and date
DATE=$1
CLOUDWATCH_LOG_GROUP=$2
CLOUDWATCH_LOG_STREAM=$3
LOG_FILE="${DATE}-${CLOUDWATCH_LOG_GROUP}-${CLOUDWATCH_LOG_STREAM}.log"
echo "Installing awslog tools"
pip install --user awslogs
echo "Cleaning workspace directory"
find . -name '*.gz' -delete
echo "Retrieving logs on Cloudwatch"
~/.local/bin/awslogs get --no-group --no-stream --start "${DATE} 00:00:00" --end "${DATE} 23:59:59" \
${CLOUDWATCH_LOG_GROUP} ${CLOUDWATCH_LOG_STREAM} > ${LOG_FILE}
echo "Compressing log files"
gzip ${LOG_FILE}.log
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment