cloudformationTemplates/asyncCustomerChatUX/cloudformation.yaml [90:249]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  InitiateChatLambda:
    Type: "AWS::Lambda::Function"
    Properties:
      Description:  AWS Lambda Function to initiate the chat with the end user
      Handler: "startChatContact.handler"
      Role: !GetAtt InitiateChatLambdaExecutionRole.Arn
      Runtime: "nodejs10.x"
      MemorySize: 128
      Timeout: 30
      Layers:
        - !Ref ChatSDKLayer
      Environment:
        Variables:
          INSTANCE_ID: !Ref instanceId
          CONTACT_FLOW_ID: !Ref contactFlowId
          CF_DISTRIBUTION: !GetAtt CloudFrontDistribution.DomainName
          SOLUTION_ID: !FindInMap [FunctionMap, Configuration, SolutionID]
          CHAT_DATA_TABLE: !Ref chatContactDataTable
      Code:
        S3Bucket:
          !Join
            - '.'
            - - !Ref 'AWS::Region'
              - !FindInMap [FunctionMap, Configuration, S3Bucket]
        S3Key: !Join ["", [!FindInMap [FunctionMap, Configuration, S3Key], 'start-chat-contact.zip']]

  InitiateChatLambdaExecutionRole:
    Type: "AWS::IAM::Role"
    Properties:
      AssumeRolePolicyDocument:
        Version: "2012-10-17"
        Statement:
          - Effect: "Allow"
            Principal:
              Service:
                - "lambda.amazonaws.com"
            Action:
              - "sts:AssumeRole"
      Path: "/"
      Policies:
        - PolicyName: initiate-chat-execution-policy
          PolicyDocument:
            Version: "2012-10-17"
            Statement:
              - Effect: "Allow"
                Action:
                  - 'logs:CreateLogGroup'
                  - 'logs:CreateLogStream'
                  - 'logs:PutLogEvents'
                Resource:
                  - !Sub "arn:${AWS::Partition}:logs:${AWS::Region}:${AWS::AccountId}:log-group:/aws/lambda/*"
              - Effect: "Allow"
                Action:
                  - "connect:StartChatContact"
                Resource:
                  - !Sub "arn:${AWS::Partition}:connect:${AWS::Region}:${AWS::AccountId}:instance/${instanceId}"
                  - !Sub "arn:${AWS::Partition}:connect:${AWS::Region}:${AWS::AccountId}:instance/${instanceId}/*"
              - Effect: "Allow"
                Action:
                  - 'dynamodb:Query'
                  - 'dynamodb:UpdateItem'
                  - 'dynamodb:PutItem'
                Resource:
                  - !GetAtt chatContactDataTable.Arn
                  - !Sub "${chatContactDataTable.Arn}/index/*"

  UpdateDdbWithS3LocationLambda:
    Type: "AWS::Lambda::Function"
    Properties:
      Description:  AWS Lambda Function to update the DDB with the S3 location of the chat transcript
      Handler: "updateChatDdbWithS3Key.handler"
      Role: !GetAtt UpdateDdbWithS3LocationLambdaExecutionRole.Arn
      Runtime: "nodejs10.x"
      MemorySize: 128
      Timeout: 30
      Environment:
        Variables:
          S3_BUCKET_NAME: !Ref AmazonConnectS3BucketName
          CHAT_DATA_TABLE: !Ref chatContactDataTable
      Code:
        S3Bucket:
          !Join
            - '.'
            - - !Ref 'AWS::Region'
              - !FindInMap [FunctionMap, Configuration, S3Bucket]
        S3Key: !Join ["", [!FindInMap [FunctionMap, Configuration, S3Key], 'update-chat-ddb.zip']]

  UpdateDdbWithS3LocationLambdaExecutionRole:
    Type: "AWS::IAM::Role"
    Properties:
      AssumeRolePolicyDocument:
        Version: "2012-10-17"
        Statement:
          - Effect: "Allow"
            Principal:
              Service:
                - "lambda.amazonaws.com"
            Action:
              - "sts:AssumeRole"
      Path: "/"
      Policies:
        - PolicyName: get-previous-chat-policy
          PolicyDocument:
            Version: "2012-10-17"
            Statement:
              - Effect: "Allow"
                Action:
                  - 'dynamodb:UpdateItem'
                Resource:
                  - !GetAtt chatContactDataTable.Arn
              - Effect: "Allow"
                Action:
                  - 'logs:CreateLogGroup'
                  - 'logs:CreateLogStream'
                  - 'logs:PutLogEvents'
                Resource:
                  - !Sub "arn:${AWS::Partition}:logs:${AWS::Region}:${AWS::AccountId}:log-group:/aws/lambda/*"

  #### S3 Lambda Trigger ####
  ExistingBucketConfiguration:
    Type: Custom::LoadLambda
    DependsOn:
      - BucketPermission
    Properties:
      customAction: "configureNotification"
      ServiceToken: !GetAtt S3BucketConfigurationLambda.Arn
      Bucket: !Ref AmazonConnectS3BucketName
      Prefix: !Ref transcriptPath
      LambdaFunctionArn: !GetAtt UpdateDdbWithS3LocationLambda.Arn

  S3BucketConfigurationLambda:
    Type: AWS::Lambda::Function
    Properties:
      Description: S3 Object Custom Resource
      Handler: S3NotificationConfiguration.handler
      Role: !GetAtt S3BucketConfigurationLambdaExecutionRole.Arn
      Code:
        S3Bucket:
          !Join
            - '.'
            - - !Ref 'AWS::Region'
              - !FindInMap [FunctionMap, Configuration, S3Bucket]
        S3Key: !Join ["", [!FindInMap [FunctionMap, Configuration, S3Key], 's3-notification-lambda.zip']]
      Timeout: 30
      Runtime: "nodejs10.x"

  S3BucketConfigurationLambdaExecutionRole:
    Type: "AWS::IAM::Role"
    Properties:
      AssumeRolePolicyDocument:
        Version: "2012-10-17"
        Statement:
          - Effect: "Allow"
            Principal:
              Service:
                - "lambda.amazonaws.com"
            Action:
              - "sts:AssumeRole"
      Path: "/"
      Policies:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



cloudformationTemplates/urlPreviewForAsyncChat/cloudformation.yaml [217:376]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  InitiateChatLambda:
    Type: "AWS::Lambda::Function"
    Properties:
      Description:  AWS Lambda Function to initiate the chat with the end user
      Handler: "startChatContact.handler"
      Role: !GetAtt InitiateChatLambdaExecutionRole.Arn
      Runtime: "nodejs10.x"
      MemorySize: 128
      Timeout: 30
      Layers:
        - !Ref ChatSDKLayer
      Environment:
        Variables:
          INSTANCE_ID: !Ref instanceId
          CONTACT_FLOW_ID: !Ref contactFlowId
          CF_DISTRIBUTION: !GetAtt CloudFrontDistribution.DomainName
          SOLUTION_ID: !FindInMap [FunctionMap, Configuration, SolutionID]
          CHAT_DATA_TABLE: !Ref chatContactDataTable
      Code:
        S3Bucket:
          !Join
            - '.'
            - - !Ref 'AWS::Region'
              - !FindInMap [FunctionMap, Configuration, S3Bucket]
        S3Key: !Join ["", [!FindInMap [FunctionMap, Configuration, S3Key], 'start-chat-contact.zip']]

  InitiateChatLambdaExecutionRole:
    Type: "AWS::IAM::Role"
    Properties:
      AssumeRolePolicyDocument:
        Version: "2012-10-17"
        Statement:
          - Effect: "Allow"
            Principal:
              Service:
                - "lambda.amazonaws.com"
            Action:
              - "sts:AssumeRole"
      Path: "/"
      Policies:
        - PolicyName: initiate-chat-execution-policy
          PolicyDocument:
            Version: "2012-10-17"
            Statement:
              - Effect: "Allow"
                Action:
                  - 'logs:CreateLogGroup'
                  - 'logs:CreateLogStream'
                  - 'logs:PutLogEvents'
                Resource:
                  - !Sub "arn:${AWS::Partition}:logs:${AWS::Region}:${AWS::AccountId}:log-group:/aws/lambda/*"
              - Effect: "Allow"
                Action:
                  - "connect:StartChatContact"
                Resource:
                  - !Sub "arn:${AWS::Partition}:connect:${AWS::Region}:${AWS::AccountId}:instance/${instanceId}"
                  - !Sub "arn:${AWS::Partition}:connect:${AWS::Region}:${AWS::AccountId}:instance/${instanceId}/*"
              - Effect: "Allow"
                Action:
                  - 'dynamodb:Query'
                  - 'dynamodb:UpdateItem'
                  - 'dynamodb:PutItem'
                Resource:
                  - !GetAtt chatContactDataTable.Arn
                  - !Sub "${chatContactDataTable.Arn}/index/*"

  UpdateDdbWithS3LocationLambda:
    Type: "AWS::Lambda::Function"
    Properties:
      Description:  AWS Lambda Function to update the DDB with the S3 location of the chat transcript
      Handler: "updateChatDdbWithS3Key.handler"
      Role: !GetAtt UpdateDdbWithS3LocationLambdaExecutionRole.Arn
      Runtime: "nodejs10.x"
      MemorySize: 128
      Timeout: 30
      Environment:
        Variables:
          S3_BUCKET_NAME: !Ref AmazonConnectS3BucketName
          CHAT_DATA_TABLE: !Ref chatContactDataTable
      Code:
        S3Bucket:
          !Join
            - '.'
            - - !Ref 'AWS::Region'
              - !FindInMap [FunctionMap, Configuration, S3Bucket]
        S3Key: !Join ["", [!FindInMap [FunctionMap, Configuration, S3Key], 'update-chat-ddb.zip']]

  UpdateDdbWithS3LocationLambdaExecutionRole:
    Type: "AWS::IAM::Role"
    Properties:
      AssumeRolePolicyDocument:
        Version: "2012-10-17"
        Statement:
          - Effect: "Allow"
            Principal:
              Service:
                - "lambda.amazonaws.com"
            Action:
              - "sts:AssumeRole"
      Path: "/"
      Policies:
        - PolicyName: get-previous-chat-policy
          PolicyDocument:
            Version: "2012-10-17"
            Statement:
              - Effect: "Allow"
                Action:
                  - 'dynamodb:UpdateItem'
                Resource:
                  - !GetAtt chatContactDataTable.Arn
              - Effect: "Allow"
                Action:
                  - 'logs:CreateLogGroup'
                  - 'logs:CreateLogStream'
                  - 'logs:PutLogEvents'
                Resource:
                  - !Sub "arn:${AWS::Partition}:logs:${AWS::Region}:${AWS::AccountId}:log-group:/aws/lambda/*"

  #### S3 Lambda Trigger ####
  ExistingBucketConfiguration:
    Type: Custom::LoadLambda
    DependsOn:
      - BucketPermission
    Properties:
      customAction: "configureNotification"
      ServiceToken: !GetAtt S3BucketConfigurationLambda.Arn
      Bucket: !Ref AmazonConnectS3BucketName
      Prefix: !Ref transcriptPath
      LambdaFunctionArn: !GetAtt UpdateDdbWithS3LocationLambda.Arn

  S3BucketConfigurationLambda:
    Type: AWS::Lambda::Function
    Properties:
      Description: S3 Object Custom Resource
      Handler: S3NotificationConfiguration.handler
      Role: !GetAtt S3BucketConfigurationLambdaExecutionRole.Arn
      Code:
        S3Bucket:
          !Join
            - '.'
            - - !Ref 'AWS::Region'
              - !FindInMap [FunctionMap, Configuration, S3Bucket]
        S3Key: !Join ["", [!FindInMap [FunctionMap, Configuration, S3Key], 's3-notification-lambda.zip']]
      Timeout: 30
      Runtime: "nodejs10.x"

  S3BucketConfigurationLambdaExecutionRole:
    Type: "AWS::IAM::Role"
    Properties:
      AssumeRolePolicyDocument:
        Version: "2012-10-17"
        Statement:
          - Effect: "Allow"
            Principal:
              Service:
                - "lambda.amazonaws.com"
            Action:
              - "sts:AssumeRole"
      Path: "/"
      Policies:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



