Skip to content

Instantly share code, notes, and snippets.

@imewish
Created February 24, 2023 05:39
Show Gist options
  • Save imewish/ee7ffa3180a503b998803b3ef4b91aaf to your computer and use it in GitHub Desktop.
Save imewish/ee7ffa3180a503b998803b3ef4b91aaf to your computer and use it in GitHub Desktop.
const AWS = require('aws-sdk');
AWS.config.update({ region: 'us-east-1' });
const timer = require('timers/promises'); // Only avail in nodejs v16+
var cloudwatchlogs = new AWS.CloudWatchLogs({ apiVersion: '2014-03-28' });
(async function () {
let nextToken = null;
do {
const logGroupsResponse = await cloudwatchlogs
.describeLogGroups({ limit: 10, nextToken: nextToken })
.promise();
// Do something with the retrieved log groups
for (const group of logGroupsResponse.logGroups) {
console.log(group);
var params = {
filterName: 'subscription filter name',
logGroupName: group.logGroupName,
};
var desparams = {
logGroupName: group.logGroupName /* required */,
};
const logGrpInfo = await cloudwatchlogs.describeSubscriptionFilters(desparams).promise();
if (logGrpInfo.subscriptionFilters.length > 0) {
try {
await cloudwatchlogs
.deleteSubscriptionFilter(params, function (err, data) {
if (err) {
console.log('Error', err.code);
} else {
console.log('Success', data);
}
})
.promise();
} catch (error) {}
}
await timer.setTimeout(1000); // avoid hitting rate limit
}
// Get the next token. If there are no more log groups, the token will be undefined
nextToken = logGroupsResponse.nextToken;
} while (nextToken);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment