How to enable real time metrics on production cloudfront distributions via cloudformation

0

So I see the documentation for this here. https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-cloudfront-monitoringsubscription-monitoringsubscription.html

But how does that actually work in practice? I can't find an example of this any where. Where would "RealtimeMetricsSubscriptionConfig: RealtimeMetricsSubscriptionConfig" go in this cloudformation template?

Resources:
  AssetsDomainCDN:
    Type: AWS::CloudFront::Distribution
    DeletionPolicy: Retain
    Properties:
      DistributionConfig:
        PriceClass: PriceClass_100
        Origins:
          - DomainName: "bar.foo.com"
            Id: "bar.foo.com"
            CustomOriginConfig:
              HTTPPort: 80
              HTTPSPort: 443
              OriginProtocolPolicy: match-viewer
              OriginSSLProtocols:
                - TLSv1.1
        Enabled: true
        HttpVersion: http2
        DefaultCacheBehavior:
          AllowedMethods: [GET, HEAD]
          TargetOriginId: bar.foo.com
          Compress: true
          ViewerProtocolPolicy: allow-all
          ForwardedValues:
            Cookies:
              Forward: none
            Headers: []
            QueryString: false
Sam
asked 9 months ago223 views
2 Answers
3
Accepted Answer

Hello.

I think it will work if you set the template as follows.
https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-cloudfront-monitoringsubscription.html

Resources:
  AssetsDomainCDN:
    Type: AWS::CloudFront::Distribution
    DeletionPolicy: Retain
    Properties:
      DistributionConfig:
        PriceClass: PriceClass_100
        Origins:
          - DomainName: "bar.foo.com"
            Id: "bar.foo.com"
            CustomOriginConfig:
              HTTPPort: 80
              HTTPSPort: 443
              OriginProtocolPolicy: match-viewer
              OriginSSLProtocols:
                - TLSv1.1
        Enabled: true
        HttpVersion: http2
        DefaultCacheBehavior:
          AllowedMethods: [GET, HEAD]
          TargetOriginId: bar.foo.com
          Compress: true
          ViewerProtocolPolicy: allow-all
          ForwardedValues:
            Cookies:
              Forward: none
            Headers: []
            QueryString: false

  MonitoringSubscription:
    Type: AWS::CloudFront::MonitoringSubscription
    Properties: 
      DistributionId: !Ref AssetsDomainCDN
      MonitoringSubscription:
        RealtimeMetricsSubscriptionConfig:
          RealtimeMetricsSubscriptionStatus: Enabled
profile picture
EXPERT
answered 9 months ago
profile picture
EXPERT
reviewed a month ago
profile pictureAWS
EXPERT
reviewed 9 months ago
  • Ah I didn't realize I needed to add a new section. Thanks.

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions