AWS recently released feature in CloudFront to view additional cloudwatch metrics.
aws_cloudfront_distribution
terraform "aws_cloudfront_distribution" "cf_name" {
....
additional_metrics = true
....
}
https://aws.amazon.com/about-aws/whats-new/2019/12/cloudfront-realtime-metrics/
https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/viewing-cloudfront-metrics.html#monitoring-console.distributions-additional
Hi, any update on this ? This feature will be greatly appreciated !
I was looking for this as well, but wasn't able to find the functionality implemented in https://github.com/aws/aws-sdk-go. Did I miss it? If not, it's doubtful this can move forward until the SDK supports it.
Apparently the console is using an undocumented API method (UpdateMonitoringSubscription) that is not public yet and not part of any SDK I checked. AWS support confirmed to me that it is not possible yet through SDK.

@piyushsonigra Is there a way to enable real time metrics via terraform now ?
The functionality to manage additional and real-time metrics is already available in the aws-sdk-go since v1.34.13:
You can now manage CloudFront's additional, real-time metrics with the CloudFront API.
@anmolbhatia05 directly inside terraform resource, it's not available yet but you can enable additional metrics using null_resource and local-exec Provisioner and execute AWS cli command.
resource "aws_cloudfront_distribution" "distribution" {
....
....
}
resource "null_resource" "cloudfront_addtional_metrics" {
provisioner "local-exec" {
command = "aws --profile $aws_profile cloudfront create-monitoring-subscription --distribution-id $cloudfront_distribution_id --monitoring-subscription RealtimeMetricsSubscriptionConfig={RealtimeMetricsSubscriptionStatus=Enabled}"
environment = {
aws_profile = var.aws_profile
cloudfront_distribution_id = aws_cloudfront_distribution.distribution.id
}
}
}
Most helpful comment
Apparently the console is using an undocumented API method (

UpdateMonitoringSubscription) that is not public yet and not part of any SDK I checked. AWS support confirmed to me that it is not possible yet through SDK.