Skip to content

Instantly share code, notes, and snippets.

@ryanblock
Last active February 27, 2021 15:31
Show Gist options
  • Save ryanblock/bbe13e3fab9d1b5385754d548429b497 to your computer and use it in GitHub Desktop.
Save ryanblock/bbe13e3fab9d1b5385754d548429b497 to your computer and use it in GitHub Desktop.
Destroy CloudWatch logs
// I like using dotenv locally but that's up to you
// require('dotenv').config()
const aws = require('aws-sdk')
// eslint-disable-next-line
let logs = [
// Insert your logs here, eg '/aws/lambda/begin-production-foo',
]
const cloudwatchlogs = new aws.CloudWatchLogs()
/**
* Find some log groups that need to go
*/
let params = {}
let logGroups = []
function getLogs() {
cloudwatchlogs.describeLogGroups(params, function(err, data) {
if (err) console.log(err)
else {
data.logGroups.forEach(l => {
logGroups.push(l.logGroupName)
})
if (data.nextToken) {
params.nextToken = data.nextToken
getLogs()
}
}
})
}
getLogs()
/**
* Destroy some logs in the logs array
* Uncomment to unleash destruction
*/
// let timer = 0
// logs.forEach(log => {
// console.log(log, timer)
// timer += 500
// let params = { logGroupName: log }
// setTimeout(function del() {
// cloudwatchlogs.deleteLogGroup(params,
// function(err, data) {
// if (err) console.log(err.message)
// else console.log(data)
// })
// }, timer)
// })
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment