Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

delete all log streams of a log group using aws cli

In order to delete a log stream from a log group using the CLI command , individual log stream names are required . Is there a way to delete all log streams belonging to a log group using a single command?

like image 386
akhila Avatar asked Feb 09 '17 10:02

akhila


People also ask

How do I delete AWS stream log?

You can achieve this through using --query to target the results of describe-log-streams . This allows you to loop through and delete the results. You can use --query to target all or specific groups or streams. Delete All log groups - Warning, it deletes EVERYTHING!

What are log streams AWS?

AWS::Logs::LogStream A log stream represents the sequence of events coming from an application instance or resource that you are monitoring. There is no limit on the number of log streams that you can create for a log group.

How do you make a CloudWatch log group?

To create a log group Open the CloudWatch console at https://console.aws.amazon.com/cloudwatch/ . In the navigation pane, choose Log groups. Choose Actions, and then choose Create log group. Enter a name for the log group, and then choose Create log group.


1 Answers

You can achieve this through using --query to target the results of describe-log-streams. This allows you to loop through and delete the results.

aws logs describe-log-streams --log-group-name $LOG_GROUP_NAME --query 'logStreams[*].logStreamName' --output table | awk '{print $2}' | grep -v ^$ | while read x; do aws logs delete-log-stream --log-group-name $LOG_GROUP_NAME --log-stream-name $x; done

You can use --query to target all or specific groups or streams.

Delete streams from a specific month

aws logs describe-log-streams --log-group-name $LOG_GROUP --query 'logStreams[?starts_with(logStreamName,`2017/07`)].logStreamName' --output table | awk '{print $2}' | grep -v ^$ | while read x; do aws logs delete-log-stream --log-group-name $LOG_GROUP --log-stream-name $x; done

Delete All log groups - Warning, it deletes EVERYTHING!

aws logs describe-log-groups --query 'logGroups[*].logGroupName' --output table | awk '{print $2}' | grep -v ^$ | while read x; do aws logs delete-log-group --log-group-name $x; done

Clearing specific log groups

aws logs describe-log-groups --query 'logGroups[?starts_with(logGroupName,`$LOG_GROUP_NAME`)].logGroupName' --output table | awk '{print $2}' | grep -v ^$ | while read x; do aws logs delete-log-group --log-group-name $x; done

Credit

like image 121
Stephen Avatar answered Sep 18 '22 06:09

Stephen