<commit_before># stacks/apps/dovetail-cdn-origin-request.yml
AWSTemplateFormatVersion: "2010-09-09"
Transform: AWS::Serverless-2016-10-31

Description: >-
  Creates a Lambda function that will used as the source function for a
  CloudFront Edge function on origin requests for the Dovetail CDN.

Parameters:
  EnvironmentType: { Type: String }
  RootStackName: { Type: String }
  RootStackId: { Type: String }
  CodeS3Bucket: { Type: String }
  CodeS3ObjectKey: { Type: String }
  ArrangerFunctionArn: { Type: String }
  ArrangerWorkspaceBucketArn: { Type: String }
  CloudWatchLogGroupTaggerServiceToken: { Type: String }

Conditions:
  IsProduction: !Equals [!Ref EnvironmentType, Production]

Resources:
  OriginRequestFunction:
    Type: AWS::Serverless::Function
    Properties:
      AssumeRolePolicyDocument:
        Statement:
          - Action: sts:AssumeRole
            Effect: Allow
            Principal:
              Service:
                - edgelambda.amazonaws.com
                - lambda.amazonaws.com
        Version: "2012-10-17"
      CodeUri:
        Bucket: !Ref CodeS3Bucket
        Key: !Ref CodeS3ObjectKey
      Description: !Sub >-
        ${EnvironmentType} Dovetail CDN origin request Edge Lambda
        function sources
      Handler: !If [IsProduction, index-production.handler, index-staging.handler]
      MemorySize: 256
      Runtime: nodejs14.x
      Policies:
        - arn:aws:iam::aws:policy/CloudWatchLambdaInsightsExecutionRolePolicy
        - Statement:
            - Action:
                - lambda:GetFunction
                - lambda:EnableReplication*
                - iam:CreateServiceLinkedRole
              Effect: Allow
              Resource: "*"
          Version: "2012-10-17"
        - Statement:
            - Action: lambda:InvokeFunction
              Effect: Allow
              Resource: !Ref ArrangerFunctionArn # TODO multiple region arrangers
          Version: "2012-10-17"
        - Statement:
            - Action: s3:GetObject
              Effect: Allow
              Resource: !Sub ${ArrangerWorkspaceBucketArn}/* # TODO multiple region arrangers
          Version: "2012-10-17"<commit_msg>Permissions for multiple regions<commit_after># stacks/apps/dovetail-cdn-origin-request.yml
AWSTemplateFormatVersion: "2010-09-09"
Transform: AWS::Serverless-2016-10-31

Description: >-
  Creates a Lambda function that will used as the source function for a
  CloudFront Edge function on origin requests for the Dovetail CDN.

Parameters:
  EnvironmentType: { Type: String }
  RootStackName: { Type: String }
  RootStackId: { Type: String }
  CodeS3Bucket: { Type: String }
  CodeS3ObjectKey: { Type: String }
  ArrangerFunctionArn: { Type: String }
  ArrangerWorkspaceBucketArn: { Type: String }
  CloudWatchLogGroupTaggerServiceToken: { Type: String }

Conditions:
  IsProduction: !Equals [!Ref EnvironmentType, Production]

Resources:
  OriginRequestFunction:
    Type: AWS::Serverless::Function
    Properties:
      AssumeRolePolicyDocument:
        Statement:
          - Action: sts:AssumeRole
            Effect: Allow
            Principal:
              Service:
                - edgelambda.amazonaws.com
                - lambda.amazonaws.com
        Version: "2012-10-17"
      CodeUri:
        Bucket: !Ref CodeS3Bucket
        Key: !Ref CodeS3ObjectKey
      Description: !Sub >-
        ${EnvironmentType} Dovetail CDN origin request Edge Lambda
        function sources
      Handler: !If [IsProduction, index-production.handler, index-staging.handler]
      MemorySize: 256
      Runtime: nodejs14.x
      Policies:
        - arn:aws:iam::aws:policy/CloudWatchLambdaInsightsExecutionRolePolicy
        - Statement:
            - Action:
                - lambda:GetFunction
                - lambda:EnableReplication*
                - iam:CreateServiceLinkedRole
              Effect: Allow
              Resource: "*"
          Version: "2012-10-17"
        - Statement:
            - Action: lambda:InvokeFunction
              Effect: Allow
              Resource:
                - !Ref ArrangerFunctionArn
                - !Sub arn:${AWS::Partition}:lambda:*:${AWS::AccountId}:function:*ArrangerFunction*
          Version: "2012-10-17"
        - Statement:
            - Action: s3:GetObject
              Effect: Allow
              Resource:
                - !Sub ${ArrangerWorkspaceBucketArn}/*
                - !Sub arn:${AWS::Partition}:s3:::*dtcdnarrangerworkspace*
          Version: "2012-10-17"
{'fraction_non_alphanumeric': 0.08737216540684749, 'fraction_numerical': 0.02601156069364162, 'mean_word_length': 2.2366906474820145, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '6530307', 'n_tokens_mistral': 1314, 'n_tokens_neox': 1221, 'n_words': 288}