Created
May 6, 2022 17:21
-
-
Save cdtweb/19cd2113f2fb07dbc1b418472ddcb498 to your computer and use it in GitHub Desktop.
Find & Delete DataDog Auto-Added Log Group Subscription Filters for AWS CloudWatch Log Groups
This file contains hidden or 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
import boto3 | |
client = boto3.client('logs') | |
logGroupPrefix = '/aws/lambda' | |
response = client.describe_log_groups( | |
logGroupNamePrefix=logGroupPrefix, | |
limit=50 | |
) | |
logGroupNames = [] | |
for i in response['logGroups']: | |
logGroupNames.append(i['logGroupName']) | |
while 'nextToken' in response: | |
response = client.describe_log_groups( | |
logGroupNamePrefix=logGroupPrefix, | |
limit=50, | |
nextToken=response['nextToken'] | |
) | |
for i in response['logGroups']: | |
logGroupNames.append(i['logGroupName']) | |
matchingFilters = [] | |
for logGroupName in logGroupNames: | |
response = client.describe_subscription_filters( | |
logGroupName=logGroupName, | |
filterNamePrefix='DD_LOG' | |
) | |
for i in response['subscriptionFilters']: | |
matchingFilters.append(i) | |
# Delete the DD_LOG_* filters from matching groups | |
for subscriptionFilter in matchingFilters: | |
response = client.delete_subscription_filter( | |
logGroupName=subscriptionFilter['logGroupName'], | |
filterName=subscriptionFilter['filterName'] | |
) | |
print(response) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment