I am trying to get number of requests from my Cloudfront instance. Currently, I use function getMetricData provided by aws-sdk in Javascripts. However, I always get an response without any values when I use lambda to query for the metric data, while I can clearly see there are requests when I check the Metric page of CloudWatch on browser.
I already check CloudWatch API document. However, I am not 100% clear about the arguments that I need for getting the "requests" metric data. Here is some code similar to what I did.
const AWS = require('aws-sdk');
exports.handler = async(event) => {
// TODO implement
let endDate = "2020-03-04T13:14:18.546Z";
let startDate = "2020-02-28T13:14:18.546Z";
let cloudwatch = new AWS.CloudWatch();
var params = {
"StartTime": startDate,
"EndTime": endDate,
"MetricDataQueries": [{
"Id": "m1",
"MetricStat": {
"Metric": {
"Namespace": "AWS/CloudFront",
"MetricName": "Requests",
"Dimensions": [{
"Name": "DistributionId",
"Value": "EG12345678" <-- I made this up
}]
},
"Period": 60,
"Stat": "Sum",
"Unit": "Count"
}
}]
};
const response = await cloudwatch.getMetricData(params).promise();
return response
}
I am sure in between the start date and end data that there are more than 100 requests. However, the return values array is simply empty.
Thanks in advance