Skip to content

Instantly share code, notes, and snippets.

@pocari
Created July 7, 2017 03:41
Show Gist options
  • Save pocari/c3bdbfd4d09733fcce2620c47477dd35 to your computer and use it in GitHub Desktop.
Save pocari/c3bdbfd4d09733fcce2620c47477dd35 to your computer and use it in GitHub Desktop.
cloudwatchのログをpecoる
#!/bin/bash
if [ -z "$LOG_GROUP" ]; then
LOG_GROUP=$(aws logs describe-log-groups | jq -r ".logGroups[].logGroupName" | grep -v "/aws/lambda/" | peco)
if [ -z "$LOG_GROUP" ]; then
exit 1
fi
fi
LOG_STREAM=$(aws logs describe-log-streams \
--log-group-name=${LOG_GROUP} \
--order-by=LastEventTime --descending | \
jq -r '.logStreams[] | .logStreamName + "@" + ((.lastEventTimestamp // .creationTime) | (. / 1000) + (3600 * 9) | strftime("%Y-%m-%d %H:%M:%S"))' | \
column -t -s "@" | peco | awk '{print $1}'
)
if [ -z "$LOG_STREAM" ]; then
exit 2
fi
aws logs get-log-events \
--log-group-name=${LOG_GROUP} \
--log-stream-name=${LOG_STREAM} | \
jq -r '.events[] | (.timestamp | (. / 1000) + (3600 * 9) | strftime("%Y-%m-%d %H:%M:%S")) + "\t" + .message'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment