Skip to content

Instantly share code, notes, and snippets.

@deathweaselx86
Created September 25, 2017 16:19
Show Gist options
  • Save deathweaselx86/1e58d9dc9723c7724be9381add0d302b to your computer and use it in GitHub Desktop.
Save deathweaselx86/1e58d9dc9723c7724be9381add0d302b to your computer and use it in GitHub Desktop.
get rid of Serverless created logGroups
'use strict';
const AWS = require('aws-sdk');
const cloudWatchLogs = new AWS.CloudWatchLogs({
apiVersion: '2014-03-28',
region: 'us-east-1'
});
const deleteCWLogs = (logGroupNamePrefix, token) => {
let nextToken = token || undefined;
let params = { limit: 50, logGroupNamePrefix, nextToken };
return cloudWatchLogs.describeLogGroups(params).promise()
.then((data) => {
const promises = [];
data.logGroups.forEach((element) => {
const logGroup = element.logGroupName;
promises.push(cloudWatchLogs.deleteLogGroup({ logGroupName: logGroup }).promise());
})
nextToken = data.nextToken;
return Promise.all(promises);
})
.then((res) => {
if (nextToken) return deleteCWLogs(logGroupNamePrefix, nextToken);
});
}
deleteCWLogs('/aws/lambda/ad-pipeline-deathweaselx86', undefined)
.catch(err => console.log("didn't work", err, "\n", err.stack));
~
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment