Created
January 1, 2020 06:43
-
-
Save sanudatta11/50137b72b7c7762f523864a118a3f121 to your computer and use it in GitHub Desktop.
This Script Purges a Log Group but doesn't delete the Log Group. It Shows Current Progress and Confirms with you before deleting the streams
This file contains hidden or 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
#!/usr/bin/env bash | |
LOG_GROUP_NAME=${1:?log group name is not set} | |
echo Getting stream names... | |
LOG_STREAMS=$( | |
aws logs describe-log-streams \ | |
--log-group-name ${LOG_GROUP_NAME} \ | |
--query 'logStreams[*].logStreamName' \ | |
--output table | | |
awk '{print $2}' | | |
grep -v ^$ | | |
grep -v DescribeLogStreams | |
) | |
echo These streams will be deleted: | |
printf "${LOG_STREAMS}\n" | |
echo Total $(wc -l <<<"${LOG_STREAMS}") streams | |
echo | |
while true; do | |
read -p "Prceed? " yn | |
case $yn in | |
[Yy]*) break ;; | |
[Nn]*) exit ;; | |
*) echo "Please answer yes or no." ;; | |
esac | |
done | |
for name in ${LOG_STREAMS}; do | |
printf "Delete stream ${name}... " | |
aws logs delete-log-stream --log-group-name ${LOG_GROUP_NAME} --log-stream-name ${name} && echo OK || echo Fail | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment