const 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);
else {
const 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}`);
}
});