Skip to content

Instantly share code, notes, and snippets.

@cdtweb
Created May 6, 2022 17:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cdtweb/19cd2113f2fb07dbc1b418472ddcb498 to your computer and use it in GitHub Desktop.
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
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