Skip to content

Instantly share code, notes, and snippets.

@christianhaller3000
Last active October 2, 2019 08:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save christianhaller3000/e33de2ab23a4267eab1ae8ba819ed032 to your computer and use it in GitHub Desktop.
Save christianhaller3000/e33de2ab23a4267eab1ae8ba819ed032 to your computer and use it in GitHub Desktop.
find logs without retention
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