Created
November 30, 2022 14:44
-
-
Save deybhayden/e38b9e3d1d46433073e1c4c31b9337bf to your computer and use it in GitHub Desktop.
AWS scripts
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 | |
) | |
test $? -ne 0 && exit | |
echo These streams will be deleted: | |
printf "${LOG_STREAMS}\n" | |
echo Total $(wc -l <<<"${LOG_STREAMS}") streams | |
echo | |
while true; do | |
read -p "Proceed? " 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