Last active
May 4, 2020 21:08
-
-
Save justinnaldzin/0bcf99abf9b63c0a0859ba9c29ba4bf5 to your computer and use it in GitHub Desktop.
Delete Logs from Amazon CloudWatch
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
LOG_GROUP='my/log/group' | |
AWS_PROFILE='my-profile' | |
# Delete all log streams within a log group | |
aws logs describe-log-streams --profile $AWS_PROFILE --log-group-name $LOG_GROUP --query 'logStreams[*].logStreamName' --output table | awk '{print $2}' | grep -v ^$ | while read x; do aws logs delete-log-stream --profile $AWS_PROFILE --log-group-name $LOG_GROUP --log-stream-name $x; done | |
# Delete log streams starting with string | |
aws logs describe-log-streams --profile $AWS_PROFILE --log-group-name $LOG_GROUP --query 'logStreams[?starts_with(logStreamName,`2020/04/3`)].logStreamName' --output table | awk '{print $2}' | grep -v ^$ | while read x; do aws logs delete-log-stream --profile $AWS_PROFILE --log-group-name $LOG_GROUP --log-stream-name $x; done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment