0xsegfault
0xsegfault

Reputation: 3161

Deleting cloudwatch group via cli

I need to delete Cloud watch group via the aws cli and running this script

aws logs describe-log-groups --region eu-west-2 | \
        jq  -r .logGroups[].logGroupName | \
            xargs -L 1 -I {}  aws logs delete-log-group --log-group-name {}

The first bit works fine , returning the log group names. Unfortunately, I cant seem to pipe it to xargs and it returns the following error:

An error occurred (ResourceNotFoundException) when calling the DeleteLogGroup operation: The specified log group does not exist.

i will be appreciative of any pointers.

Upvotes: 1

Views: 257

Answers (1)

John Rotenstein
John Rotenstein

Reputation: 269548

As an alternative to using the AWS CLI, here's a Python script to delete log groups:

import boto3

logs_client = boto3.client('logs')

response = logs_client.describe_log_groups()

for log in response['logGroups']:
    logs_client.delete_log_group(logGroupName=log['logGroupName'])

Upvotes: 2

Related Questions