Created
September 25, 2017 16:19
-
-
Save deathweaselx86/3064218b978c160ba9162883483a7016 to your computer and use it in GitHub Desktop.
get rid of Serverless created logGroups
This file contains 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
'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