Last Updated: January 06, 2019
· skyzyx

Remove all CloudWatch Log Groups for Lambda functions forwarding to SumoLogic

Once upon a time, I was forwarding my logs from CloudWatch Logs over to Sumo Logic for its advanced querying abilities. But with the new CloudWatch Logs Insights feature that shipped at re:Invent 2018, we no longer need to ship the logs.

Sumo Logic recommends using a Lambda function (which we called "sumologic") for pushing the logs from CWL to SL, and that Lambda function itself also generates log files. After de-integrating with Sumo Logic and deleting the Lambda function, we wanted to quickly clean-up the Sumo Logic Lambda function LogGroups in CloudWatch Logs (that was a mouthful). I used the Unified AWS CLI Tools.

for lg in $(aws logs describe-log-groups --query "logGroups[?logGroupName | contains(@, 'aws/lambda/sumologic')].logGroupName" --output text); do
    echo "$lg";
    aws logs delete-log-group --log-group-name "$lg";