<commit_before>AWSTemplateFormatVersion: "2010-09-09"
Description: >
  Creates a CloudFront distribution to origin-pull from a Dovetail S3 bucket,
  with an origin-request Lambda to do the actual file stitching.
Metadata:
  AWS::CloudFormation::Interface:
    ParameterGroups:
      - Label:
          default: Stack Dependencies
        Parameters:
          - InfrastructureNotificationsStackName
      - Label:
          default: Distribution Parameters
        Parameters:
          - OriginBucket
          - OriginPath
          - DistributionDomain
          - CertificateArn
          - LambdaFunctionArn
    ParameterLabels:
      OriginBucket:
        default: Origin S3 Bucket
      OriginPath:
        default: Origin S3 Path
      DistributionDomain:
        default: Domain Name
      CertificateArn:
        default: ACM Certificate Arn
      LambdaFunctionArn:
        default: Stitch Function Arn
      InfrastructureNotificationsStackName:
        default: Notifications stack name
Parameters:
  OriginBucket:
    Type: String
    Description: eg. prx-dovetail.s3.amazonaws.com
  OriginPath:
    Type: String
    Description: eg. /stitch-production, /stitch-staging
  DistributionDomain:
    Type: String
    Description: eg. dovetail-cdn.prxu.org
  CertificateArn:
    Type: String
    Description: eg. arn:aws:acm:<region>:<account>:certificate/<guid>
  LambdaFunctionArn:
    Type: String
    Description: eg. arn:aws:lambda:<region>:<account>:function:<name>:<version>
  InfrastructureNotificationsStackName:
    Default: infrastructure-notifications
    Description: The name of a previously launched notifications stack
    Type: String
Resources:
  CloudFrontDistribution:
    Type: "AWS::CloudFront::Distribution"
    Properties:
      DistributionConfig:
        Aliases:
          - !Ref DistributionDomain
        CustomErrorResponses:
          # dovetail uploaded, but file wasn't there!
          - ErrorCachingMinTTL: 0
            ErrorCode: 403
            ResponseCode: 500
            ResponsePagePath: /500.html
          # unrecognized uri or arrangement not in redis
          - ErrorCachingMinTTL: 300
            ErrorCode: 404
          # lambda caught an error
          - ErrorCachingMinTTL: 0
            ErrorCode: 500
          # callback(null, {invalid-response})
          - ErrorCachingMinTTL: 10
            ErrorCode: 502
          # timeout / memory-exceeded / callback(err)
          - ErrorCachingMinTTL: 0
            ErrorCode: 503
          # unknown
          - ErrorCachingMinTTL: 10
            ErrorCode: 504
        DefaultCacheBehavior:
          AllowedMethods: [HEAD, GET]
          CachedMethods: [HEAD, GET]
          Compress: false
          ForwardedValues:
            QueryString: false
          LambdaFunctionAssociations:
            - EventType: origin-request
              LambdaFunctionARN: !Ref LambdaFunctionArn
          TargetOriginId: dovetail-stitch-s3
          ViewerProtocolPolicy : allow-all
        DefaultRootObject: index.html
        Enabled: true
        HttpVersion: http2
        IPV6Enabled: true
        Origins:
          - DomainName: !Ref OriginBucket
            Id: dovetail-stitch-s3
            OriginPath: !Ref OriginPath
            S3OriginConfig: {}
        PriceClass: PriceClass_200<commit_msg>CDN viewer-response hook<commit_after>AWSTemplateFormatVersion: "2010-09-09"
Description: >
  Creates a CloudFront distribution to origin-pull from a Dovetail S3 bucket,
  with an origin-request Lambda to do the actual file stitching.
Metadata:
  AWS::CloudFormation::Interface:
    ParameterGroups:
      - Label:
          default: Stack Dependencies
        Parameters:
          - InfrastructureNotificationsStackName
      - Label:
          default: Distribution Parameters
        Parameters:
          - OriginBucket
          - OriginPath
          - DistributionDomain
          - CertificateArn
          - LambdaFunctionArn
          - LambdaBytesFunctionArn
    ParameterLabels:
      OriginBucket:
        default: Origin S3 Bucket
      OriginPath:
        default: Origin S3 Path
      DistributionDomain:
        default: Domain Name
      CertificateArn:
        default: ACM Certificate Arn
      LambdaFunctionArn:
        default: Stitch Function Arn
      LambdaBytesFunctionArn:
        default: Bytes Logging Function Arn
      InfrastructureNotificationsStackName:
        default: Notifications stack name
Parameters:
  OriginBucket:
    Type: String
    Description: eg. prx-dovetail.s3.amazonaws.com
  OriginPath:
    Type: String
    Description: eg. /stitch-production, /stitch-staging
  DistributionDomain:
    Type: String
    Description: eg. dovetail-cdn.prxu.org
  CertificateArn:
    Type: String
    Description: eg. arn:aws:acm:<region>:<account>:certificate/<guid>
  LambdaFunctionArn:
    Type: String
    Description: eg. arn:aws:lambda:<region>:<account>:function:<name>:<version>
  LambdaBytesFunctionArn:
    Type: String
    Description: eg. arn:aws:lambda:<region>:<account>:function:<name>:<version>
  InfrastructureNotificationsStackName:
    Default: infrastructure-notifications
    Description: The name of a previously launched notifications stack
    Type: String
Resources:
  CloudFrontDistribution:
    Type: "AWS::CloudFront::Distribution"
    Properties:
      DistributionConfig:
        Aliases:
          - !Ref DistributionDomain
        CustomErrorResponses:
          # dovetail uploaded, but file wasn't there!
          - ErrorCachingMinTTL: 0
            ErrorCode: 403
            ResponseCode: 500
            ResponsePagePath: /500.html
          # unrecognized uri or arrangement not in redis
          - ErrorCachingMinTTL: 300
            ErrorCode: 404
          # lambda caught an error
          - ErrorCachingMinTTL: 0
            ErrorCode: 500
          # callback(null, {invalid-response})
          - ErrorCachingMinTTL: 10
            ErrorCode: 502
          # timeout / memory-exceeded / callback(err)
          - ErrorCachingMinTTL: 0
            ErrorCode: 503
          # unknown
          - ErrorCachingMinTTL: 10
            ErrorCode: 504
        DefaultCacheBehavior:
          AllowedMethods: [HEAD, GET]
          CachedMethods: [HEAD, GET]
          Compress: false
          ForwardedValues:
            QueryString: false
          LambdaFunctionAssociations:
            - EventType: origin-request
              LambdaFunctionARN: !Ref LambdaFunctionArn
            - EventType: viewer-response
              LambdaFunctionARN: !Ref LambdaBytesFunctionArn
          TargetOriginId: dovetail-stitch-s3
          ViewerProtocolPolicy : allow-all
        DefaultRootObject: index.html
        Enabled: true
        HttpVersion: http2
        IPV6Enabled: true
        Origins:
          - DomainName: !Ref OriginBucket
            Id: dovetail-stitch-s3
            OriginPath: !Ref OriginPath
            S3OriginConfig: {}
        PriceClass: PriceClass_200
{'fraction_non_alphanumeric': 0.06465517241379311, 'fraction_numerical': 0.015517241379310345, 'mean_word_length': 2.2107933579335795, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2929995', 'n_tokens_mistral': 1934, 'n_tokens_neox': 1783, 'n_words': 463}