You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Node.js实现CloudWatch指定时间范围日志条数统计遇阻求助

Node.js实现CloudWatch指定时间范围日志条数统计遇阻求助

大家好,我最近在做用Node.js调用CloudWatch Insights API统计指定时间范围日志条数的功能,在CloudWatch Insights控制台里执行查询是能拿到正常输出的,但用代码跑出来的结果却不对,想请教下各位大佬有没有解决办法?

我的代码如下:

async function main(){

const logGroupName = '/aws/apprunner/<Name of your Log Group>';

const timestamp = new Date();

let queryCount = `stats count() as total`;

const params = {

startTime: '1675103400000',

endTime: '1675189799000',

queryString: queryCount,

logGroupName: logGroupName

};

// 1. Start the query. When we start a query, this returns a queryId for us to use on our next step.

const data = await cloudWatchLogs.startQuery(params).promise();

const { queryId } = data;

console.debug('query id', queryId);

// 2. Send Insight query to CloudwatchLogs

const insightData = await cloudWatchLogs.getQueryResults({ queryId })

.promise();

console.log(insightData);

return ;

}

main();

运行后得到的输出是:

{
  results: [],
  statistics: { recordsMatched: 0, recordsScanned: 0, bytesScanned: 0 },
  status: 'Running'
}

我就是想从返回结果里拿到正确的日志计数,但现在不仅匹配记录数为0,查询状态还一直显示Running,控制台明明能查到数据,代码里却跑成这样,有没有人能帮我看看问题出在哪或者该怎么调整代码呀?

备注:内容来源于stack exchange,提问作者naveen

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.23 15:27:53