i want to build a small app that reads the AWS CPU USAGE every 5 minutes lets say, i built the params, call the getMetricsStatistics but it keeps returning me an empty array, you know why? this is the code:
const aws = require('aws-sdk')
const dotenv = require('dotenv').config()
aws.config.setPromisesDependency()
aws.config.update({
accessKeyId: process.env.EC2_ACCESS_KEY,
secretAccessKey: process.env.EC2_SECRET_KEY,
region: 'us-east-1',
})
const s3 = new aws.CloudWatch()
var params = {
EndTime: new Date() /* required */,
/* required */
MetricName: 'EngineCPUUtilization',
Namespace: 'AWS/S3',
StartTime: new Date('Mon Dec 6 2021') /* required */,
/* required */
Dimensions: [
{
Name: 'Per-Instance Metrics' /* required */,
Value: 'i-abbc12a7' /* required */,
},
{
Name: 'StorageType',
Value: 'AllStorageTypes',
},
/* more items */
],
Period: 300 /* required */,
Statistics: ['Average'] /* required */,
}
async function asyncMethod() {
return await s3.getMetricStatistics(params, function (err, data) {
if (err) console.log(err, err.stack)
// an error occurred
else {
console.log(data)
}
}) // successful response
}
const d = asyncMethod()
response is always empty array in the data.Datapoints.