aws-log-group-quickly-search-and-open-log-groups
by David Boyne
Quickly find and open your log groups
// Menu: AWS Log Group// Description: Quickly find and open your log groups// Author: David Boyne// Twitter: @boyney123const AWS = await npm('aws-sdk');const { format } = await npm('date-fns');const region = await env('AWS_REGION');AWS.config.update({ region: region });var cloudwatchlogs = new AWS.CloudWatchLogs();cloudwatchlogs.describeLogGroups({ logGroupNamePrefix: '/aws/' }, async function (err, data) {if (err) inspect(err);// an error occurredelse {// await inspect(data); // successful responseconst groups = data.logGroups.map(({ logGroupName, creationTime, retentionInDays }) => ({name: logGroupName,value: logGroupName,html: `<div><div style="font-size:10px; padding:0; margin:0;">Created ${format(new Date(creationTime), 'yyyy-MM-dd')} | Retention ${retentionInDays} days</div><div style="font-size:14px; font-weight:bold;">${logGroupName}</div></div>`,}));const logGroup = await arg('Search for a log group:', groups);const url = `https://${region}.console.aws.amazon.com/cloudwatch/home?region=${region}#logsV2:log-groups/log-group/${encodeURIComponent(logGroup)}`;exec(`open ${url}`);}});