Resources:
  streamingLambdaFunction:
    Type: AWS::Lambda::Function
    Properties:
      Code:
        S3Bucket: [S3BUCKET_CFN]
        S3Key: repLambdaFunction.zip
      Handler: lambda_function.lambda_handler
      Role: [ARN_ROLE_CFN]
      Runtime: python3.7
      Description: "AWS Lambda used to replicate change events from Amazon DocumentDB to Amazon Elasticsearch service"
      Environment:
        Variables:
          DOCUMENTDB_SECRET: [DOCDB_SECRETSMAN_NAME_CFN]
          DOCUMENTDB_URI: [DOCDB_URI_CFN]:27017
          Documents_per_run: 1000
          SNS_TOPIC_ARN_ALERT: [SNS_TOPIC_ARN_ALERT_CNF]
          STATE_COLLECTION: statecol
          STATE_DB: statedb
          Iterations_per_sync: 15
          WATCHED_DB_NAME: sampledb
          ELASTICSEARCH_URI: https://[ELASTICSEARCH_URI_CFN]
      FunctionName: docdb-elasticsearch-replicator
      MemorySize: 256
      Timeout: 60
      VpcConfig:
        SecurityGroupIds:
          - [DOCDB_SG_CFN]
          - [ELASTICSEARCH_SG_CFN]
        SubnetIds:
          - [SUBNET_ONE_CFN]
          - [SUBNET_TWO_CFN]
          - [SUBNET_THREE_CFN]
  streamingAllowInvokeSns:
    Type: AWS::Lambda::Permission
    Properties:
      Action: lambda:InvokeFunction
      FunctionName:
        Fn::GetAtt:
          - streamingLambdaFunction
          - Arn
      Principal: sns.amazonaws.com
      SourceArn: [SNS_TOPIC_ARN_TRIGGER_CNF]
  streamingSNSSubscription:
    Type: AWS::SNS::Subscription
    Properties:
      Protocol: lambda
      TopicArn: [SNS_TOPIC_ARN_TRIGGER_CNF]
      Endpoint:
        Fn::GetAtt:
          - streamingLambdaFunction
          - Arn
      Region: !Ref "AWS::Region"