Last active
October 2, 2019 08:18
-
-
Save christianhaller3000/e33de2ab23a4267eab1ae8ba819ed032 to your computer and use it in GitHub Desktop.
find logs without retention
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
const { CloudWatchLogs, EC2 } = require("aws-sdk"); | |
const region = "eu-central-1"; | |
module.exports = (async () => { | |
try { | |
const ec2 = new EC2({ | |
region | |
}); | |
const { Regions } = await ec2.describeRegions().promise(); | |
const logGroupsWithoutRetention = Regions.map(async (awsRegion) => { | |
const cloudwatchlogs = new CloudWatchLogs({ | |
region: awsRegion.RegionName | |
}); | |
const groups = await cloudwatchlogs.describeLogGroups().promise(); | |
return Promise.resolve(groups.logGroups | |
// .filter((group) => group.logGroupName.includes("onex")) | |
// without retention | |
.filter((group) => typeof group.retentionInDays === "undefined") | |
.map((group) => ({ | |
region: awsRegion.RegionName, | |
...group | |
}))); | |
}); | |
const result = await Promise.all(logGroupsWithoutRetention); | |
const all = await Promise.all(result | |
.map(async (logGroups) => Promise.all(logGroups | |
.map((group) => { | |
const cloudwatchlogs = new CloudWatchLogs({ | |
region: group.region | |
}); | |
console.log(`${group.region}/${group.logGroupName}`); | |
return cloudwatchlogs.deleteLogGroup({ | |
"logGroupName": group.logGroupName | |
}).promise(); | |
})) | |
) | |
); | |
console.log(all.length); | |
} catch (e) { | |
console.log(e); | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment