Deleting old cloudwatch log groups

Wonder if anyone has a nice command line they use to delete old cloudwatch log groups? While the stack might have been deleted, finding a lot of the cloudwatch log groups remain… trying to see how difficult it would be to see when the last event happened to each and delete the group if it is over a month ago etc

Is there a reason you would need to automate this? You can take care of the existing ones manually, and from now on you can add cloudwatch groups to CFN templates. Would that work?

A bit much for manual - over 700 at the moment, and each one would have to dive into the logstreams to see last event timestamp, hence the hope :slightly_smiling_face:

Do you have a retention policy set? You could just remove log groups which have no events remaining

Thats also getting added into the CDK for these, but nothing on the existing ones

Oh, but that might be an easier thing to apply I see

Awesome, thanks! Will check back tomorrow, but here is the command for anyone else:
aws logs describe-log-groups --query 'logGroups[].logGroupName' --output text | xargs -r -n1 aws logs put-retention-policy --retention-in-days 30 --log-group-name

I think in the console you can select all on the page and update the log retention all at once for the selected

CLI or boto3 would be my next suggestion, best of luck!