I am new to AWS SDK (and nodejs) and I am trying to get cloudwatch's getMetricData to work. Im using a simple Cloudwatch query to grab the CPU utilization of an instance. But no matter what I do, I just keep getting this
{
ResponseMetadata: { RequestId: '5253fbfc-5aa2-4dfb-871b-1453f8610d80' },
MetricDataResults: [
{
Id: 'q1',
Label: 'q1',
Timestamps: [],
Values: [],
StatusCode: 'Complete',
Messages: []
}
],
Messages: [
{
Code: 'MaxQueryTimeRangeExceeded',
Value: 'Max time window exceeded for query'
}
]
}
here is my code
const AWS = require("aws-sdk");
AWS.config.loadFromPath("./config.json");
var cloudwatch = new AWS.CloudWatch({apiVersion: "2010-08-01"});
var params = {
StartTime: new Date('june 06, 2022 17:30'),
EndTime: new Date('june 06, 2022 18:00'),
MetricDataQueries: [
{
Id: 'q1',
Expression: "SELECT AVG(CPUUtilization) FROM SCHEMA(\"AWS/EC2\", InstanceId) WHERE InstanceId = 'i-**********'",
Period: '600'
},
],
};
cloudwatch.getMetricData(params, function(err, data) {
if (err) console.log(err, err.stack);
else console.log(data);
});