Created
May 15, 2017 17:11
-
-
Save mooyoul/6838f8b4624c33f5a03b5357946dd370 to your computer and use it in GitHub Desktop.
CloudFront Metrics via CloudWatch API
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
const AWS = require('aws-sdk'); | |
const cloudwatch = new AWS.CloudWatch(); | |
const endDate = new Date(); | |
const startDate = new Date(endDate.getTime() - (3600 * 24 * 1000)); // 1 day ago | |
cloudwatch.getMetricStatistics({ | |
Namespace: 'AWS/CloudFront', | |
MetricName: 'Requests', | |
StartTime: startDate, | |
Period: 60 * 60, // per each 1 hour period | |
EndTime: endDate, | |
Dimensions: [ | |
{ Name: 'Region', Value: 'Global' }, | |
{ Name: 'DistributionId', Value: 'TARGET_CLOUDFRONT_DIST_ID' }, | |
], | |
Statistics: ['Sum'], | |
}, (e, data) => { | |
if (e) { // handle error if an error occurred | |
console.error(e); | |
return; | |
} | |
console.log(data); | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment