<commit_before>AWSTemplateFormatVersion: 2010-09-09
Description: Consumes events produced when an app receives a notification
Parameters:
  Stack:
    Description: Stack name
    Type: String
    Default: mobile-notifications
  App:
    Description: Application name
    Type: String
    Default: eventconsumer
  Stage:
    Description: Stage name
    Type: String
    AllowedValues:
    - CODE
    - PROD
    Default: CODE
  DeployBucket:
    Description: Bucket where RiffRaff uploads artifacts on deploy
    Type: String
    Default: mobile-notifications-dist
Mappings:
  StageVariables:
    CODE:
      BucketStage: code
    PROD:
      BucketStage: prod
Resources:
  Sqs:
    Type: AWS::SQS::Queue
    Properties:
      VisibilityTimeout: 300
  SqsPolicy:
    Type: AWS::SQS::QueuePolicy
    Properties:
      Queues:
      - Ref: Sqs
      PolicyDocument:
        Version: "2012-10-17"
        Id: !Sub "Sqs${Stage}Policy"
        Statement:
        - Resource: !GetAtt Sqs.Arn
          Effect: "Allow"
          Sid: "Allow-User-SendMessage"
          Action:
          - "sqs:*"
          Condition:
            ArnLike:
              aws:SourceArn:
              - !Sub
                - arn:aws:s3:::aws-mobile-event-logs-${BucketStage}
                - BucketStage: !FindInMap [StageVariables, !Ref Stage, BucketStage]
          Principal:
            AWS: "*"
  ExecutionRole:
    Type: AWS::IAM::Role
    DependsOn: Sqs
    Properties:
      AssumeRolePolicyDocument:
        Statement:
        - Effect: Allow
          Principal:
            Service:
            - lambda.amazonaws.com
          Action: sts:AssumeRole
      Path: /
      Policies:
      - PolicyName: logs
        PolicyDocument:
          Statement:
          - Effect: Allow
            Action: logs:CreateLogGroup
            Resource: !Sub "arn:aws:logs:eu-west-1:${AWS::AccountId}:*"
          - Effect: Allow
            Action:
            - logs:CreateLogStream
            - logs:PutLogEvents
            Resource:
            - !Sub "arn:aws:logs:eu-west-1:${AWS::AccountId}:log-group:/aws/lambda/eventconsumer-${Stage}:*"
            - !Sub "arn:aws:logs:eu-west-1:${AWS::AccountId}:log-group:/aws/lambda/eventconsumer-sqs-${Stage}:*"

      - PolicyName: s3
        PolicyDocument:
          Statement:
            Effect: Allow
            Action:
            - s3:*
            Resource:
            - !Sub
              - arn:aws:s3:::aws-mobile-event-logs-${BucketStage}
              - BucketStage: !FindInMap [StageVariables, !Ref Stage, BucketStage]
            - !Sub
              - arn:aws:s3:::aws-mobile-event-logs-${BucketStage}/*
              - BucketStage: !FindInMap [StageVariables, !Ref Stage, BucketStage]

      - PolicyName: Dynamo
        PolicyDocument:
          Statement:
            Effect: Allow
            Action: dynamodb:*
            Resource: !Sub "arn:aws:dynamodb:eu-west-1:${AWS::AccountId}:table/mobile-notifications-reports-${Stage}"
      - PolicyName: SQS
        PolicyDocument:
          Statement:
            Effect: Allow
            Action: sqs:*
            Resource: !GetAtt Sqs.Arn


  SqsLambda:
    Type: AWS::Lambda::Function
    Properties:
      FunctionName: !Sub ${App}-sqs-${Stage}
      Code:
        S3Bucket:
          Ref: DeployBucket
        S3Key: !Sub ${Stack}/${Stage}/${App}/${App}.jar
      Environment:
        Variables:
          Stage: !Ref Stage
          Stack: !Ref Stack
          App: !Ref App
      Description: Consumes queue events
      Handler: com.gu.notifications.events.SqsLambda::handleRequest
      MemorySize: 384
      Role: !GetAtt ExecutionRole.Arn
      Runtime: java8
      Timeout: 300
      ReservedConcurrentExecutions: 1

  S3Bucket:
    Type: AWS::S3::Bucket
    DependsOn:
    - Sqs
    - SqsPolicy
    Properties:
      AccessControl: Private
      BucketName: !Sub
      - aws-mobile-event-logs-${BucketStage}
      - BucketStage: !FindInMap [StageVariables, !Ref Stage, BucketStage]
      LifecycleConfiguration:
        Rules:
          - ExpirationInDays: 21
            Status: Disabled
      NotificationConfiguration:
        QueueConfigurations:
        - Event: s3:ObjectCreated:*
          Queue: !GetAtt Sqs.Arn

  SqsEventSourceMapping:
    Type: AWS::Lambda::EventSourceMapping
    DependsOn:
    - Sqs
    - SqsLambda
    Properties:
      BatchSize: 1
      Enabled: True
      EventSourceArn: !GetAtt Sqs.Arn
      FunctionName: !Sub ${App}-sqs-${Stage}
<commit_msg>Increase batch size (#282)<commit_after>AWSTemplateFormatVersion: 2010-09-09
Description: Consumes events produced when an app receives a notification
Parameters:
  Stack:
    Description: Stack name
    Type: String
    Default: mobile-notifications
  App:
    Description: Application name
    Type: String
    Default: eventconsumer
  Stage:
    Description: Stage name
    Type: String
    AllowedValues:
    - CODE
    - PROD
    Default: CODE
  DeployBucket:
    Description: Bucket where RiffRaff uploads artifacts on deploy
    Type: String
    Default: mobile-notifications-dist
Mappings:
  StageVariables:
    CODE:
      BucketStage: code
    PROD:
      BucketStage: prod
Resources:
  Sqs:
    Type: AWS::SQS::Queue
    Properties:
      VisibilityTimeout: 300
  SqsPolicy:
    Type: AWS::SQS::QueuePolicy
    Properties:
      Queues:
      - Ref: Sqs
      PolicyDocument:
        Version: "2012-10-17"
        Id: !Sub "Sqs${Stage}Policy"
        Statement:
        - Resource: !GetAtt Sqs.Arn
          Effect: "Allow"
          Sid: "Allow-User-SendMessage"
          Action:
          - "sqs:*"
          Condition:
            ArnLike:
              aws:SourceArn:
              - !Sub
                - arn:aws:s3:::aws-mobile-event-logs-${BucketStage}
                - BucketStage: !FindInMap [StageVariables, !Ref Stage, BucketStage]
          Principal:
            AWS: "*"
  ExecutionRole:
    Type: AWS::IAM::Role
    DependsOn: Sqs
    Properties:
      AssumeRolePolicyDocument:
        Statement:
        - Effect: Allow
          Principal:
            Service:
            - lambda.amazonaws.com
          Action: sts:AssumeRole
      Path: /
      Policies:
      - PolicyName: logs
        PolicyDocument:
          Statement:
          - Effect: Allow
            Action: logs:CreateLogGroup
            Resource: !Sub "arn:aws:logs:eu-west-1:${AWS::AccountId}:*"
          - Effect: Allow
            Action:
            - logs:CreateLogStream
            - logs:PutLogEvents
            Resource:
            - !Sub "arn:aws:logs:eu-west-1:${AWS::AccountId}:log-group:/aws/lambda/eventconsumer-${Stage}:*"
            - !Sub "arn:aws:logs:eu-west-1:${AWS::AccountId}:log-group:/aws/lambda/eventconsumer-sqs-${Stage}:*"

      - PolicyName: s3
        PolicyDocument:
          Statement:
            Effect: Allow
            Action:
            - s3:*
            Resource:
            - !Sub
              - arn:aws:s3:::aws-mobile-event-logs-${BucketStage}
              - BucketStage: !FindInMap [StageVariables, !Ref Stage, BucketStage]
            - !Sub
              - arn:aws:s3:::aws-mobile-event-logs-${BucketStage}/*
              - BucketStage: !FindInMap [StageVariables, !Ref Stage, BucketStage]

      - PolicyName: Dynamo
        PolicyDocument:
          Statement:
            Effect: Allow
            Action: dynamodb:*
            Resource: !Sub "arn:aws:dynamodb:eu-west-1:${AWS::AccountId}:table/mobile-notifications-reports-${Stage}"
      - PolicyName: SQS
        PolicyDocument:
          Statement:
            Effect: Allow
            Action: sqs:*
            Resource: !GetAtt Sqs.Arn


  SqsLambda:
    Type: AWS::Lambda::Function
    Properties:
      FunctionName: !Sub ${App}-sqs-${Stage}
      Code:
        S3Bucket:
          Ref: DeployBucket
        S3Key: !Sub ${Stack}/${Stage}/${App}/${App}.jar
      Environment:
        Variables:
          Stage: !Ref Stage
          Stack: !Ref Stack
          App: !Ref App
      Description: Consumes queue events
      Handler: com.gu.notifications.events.SqsLambda::handleRequest
      MemorySize: 384
      Role: !GetAtt ExecutionRole.Arn
      Runtime: java8
      Timeout: 300
      ReservedConcurrentExecutions: 1

  S3Bucket:
    Type: AWS::S3::Bucket
    DependsOn:
    - Sqs
    - SqsPolicy
    Properties:
      AccessControl: Private
      BucketName: !Sub
      - aws-mobile-event-logs-${BucketStage}
      - BucketStage: !FindInMap [StageVariables, !Ref Stage, BucketStage]
      LifecycleConfiguration:
        Rules:
          - ExpirationInDays: 21
            Status: Disabled
      NotificationConfiguration:
        QueueConfigurations:
        - Event: s3:ObjectCreated:*
          Queue: !GetAtt Sqs.Arn

  SqsEventSourceMapping:
    Type: AWS::Lambda::EventSourceMapping
    DependsOn:
    - Sqs
    - SqsLambda
    Properties:
      BatchSize: 10
      Enabled: True
      EventSourceArn: !GetAtt Sqs.Arn
      FunctionName: !Sub ${App}-sqs-${Stage}

{'fraction_non_alphanumeric': 0.10260695187165775, 'fraction_numerical': 0.010249554367201427, 'mean_word_length': 1.9222005208333333, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '773827', 'n_tokens_mistral': 2740, 'n_tokens_neox': 2599, 'n_words': 561}