Last active
March 6, 2023 15:01
-
-
Save ipmb/008820b4c5556f3366720474680a467a to your computer and use it in GitHub Desktop.
aws_dump_log_stream.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
if [ $# -lt 2 ]; then | |
echo "Usage: $0 <log_group_prefix> <log_stream_name>" | |
exit 1 | |
fi | |
LOG_GROUP_PREFIX=$1 | |
LOG_STREAM_NAME=$2 | |
# Add dashes into UUID if they weren't provided | |
if [[ $LOG_STREAM_NAME =~ ^[0-9a-fA-F]{32}$ ]]; then | |
LOG_STREAM_NAME=$(echo $LOG_STREAM_NAME | sed 's/\([0-9a-fA-F]\{8\}\)\([0-9a-fA-F]\{4\}\)\([0-9a-fA-F]\{4\}\)\([0-9a-fA-F]\{4\}\)\([0-9a-fA-F]\{12\}\)/\1-\2-\3-\4-\5/') | |
fi | |
LOG_GROUPS=$(aws logs describe-log-groups --log-group-name-prefix "$LOG_GROUP_PREFIX" --query "logGroups[].logGroupName" --output text) | |
for LOG_GROUP in $LOG_GROUPS; do | |
LOG_STREAMS=$(aws logs describe-log-streams --log-group-name "$LOG_GROUP" --query "logStreams[].logStreamName" --output text) | |
if [[ "$LOG_STREAMS" == *"$LOG_STREAM_NAME"* ]]; then | |
echo "Found log stream $LOG_STREAM_NAME in log group $LOG_GROUP:" | |
AWS_PAGER="" aws logs get-log-events --log-group-name "$LOG_GROUP" --log-stream-name "$LOG_STREAM_NAME" --output text --query "events[].message" | |
exit 0 | |
fi | |
done | |
echo "Could not find log stream $LOG_STREAM_NAME in log groups with prefix $LOG_GROUP_PREFIX" | |
exit 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment