Skip to content

Instantly share code, notes, and snippets.

@vladholubiev
Created January 5, 2021 16:34
Show Gist options
  • Save vladholubiev/571b62290c0aa7bee2775cdbe2ce1de2 to your computer and use it in GitHub Desktop.
Save vladholubiev/571b62290c0aa7bee2775cdbe2ce1de2 to your computer and use it in GitHub Desktop.
Print log groups w/o tags
import {CloudWatchLogs} from 'aws-sdk';
const cw = new CloudWatchLogs({region: 'us-east-1'});
(async () => {
const results: CloudWatchLogs.LogGroup[] = [];
await getAllLogGroups(results, '');
for (const lg of results) {
const {tags} = await cw.listTagsLogGroup({logGroupName: lg.logGroupName}).promise();
if (!tags.Project || !tags.Environment) {
console.log(lg.logGroupName, tags);
}
}
})();
async function getAllLogGroups(results: CloudWatchLogs.LogGroup[], nextToken?: string) {
const resp = await cw
.describeLogGroups({
limit: 50,
...(nextToken ? {nextToken: nextToken} : {})
})
.promise();
if (resp.logGroups.length) {
results.push(...resp.logGroups);
console.log(resp.logGroups.length);
if (resp.nextToken) {
await getAllLogGroups(results, resp.nextToken);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment