template/master-fullstack-with-lambda-warmers.yaml [1259:1718]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  UpdateSearchCluster:
    Type: 'AWS::Lambda::Function'
    DependsOn:
      - ESSearchRole
      - ElasticsearchDomain
      - TBooks
    Properties:
      FunctionName: !Sub '${ProjectName}-UpdateSearchCluster'
      Description: 'Update Elasticsearch cluster as books are added'
      Handler: index.handler
      Role: !GetAtt 
        - ESSearchRole
        - Arn
      Runtime: python2.7
      Timeout: '60'
      VpcConfig:
        SecurityGroupIds:
          - Fn::GetAtt: [bookstoreVPC, DefaultSecurityGroup]
        SubnetIds:
          - Ref: bookstoreSubnet1
      Code:
        S3Bucket: !FindInMap 
          - S3Buckets
          - !Ref 'AWS::Region'
          - Bucket
        S3Key: !FindInMap 
          - Constants
          - S3Keys
          - UpdateSearchCode
      Environment:
        Variables:
          ESENDPOINT: !GetAtt 
            - ElasticsearchDomain
            - DomainEndpoint
          REGION: !Ref 'AWS::Region'
  FunctionUpdateBestSellers:
    Type: 'AWS::Lambda::Function'
    DependsOn:
      - RedisRole
      - ElastiCacheCluster
      - TOrders
    Properties:
      FunctionName: !Sub '${ProjectName}-UpdateBestSellers'
      Description: 'Updates BestSellers as orders are placed'
      Handler: index.handler
      Role: !GetAtt 
        - RedisRole
        - Arn
      Runtime: nodejs8.10
      Timeout: '60'
      VpcConfig:
        SecurityGroupIds:
          - Ref: redisLambdaSecurityGroup
        SubnetIds: 
          - Ref: bookstoreSubnet1
      Code:
        S3Bucket: !FindInMap 
          - S3Buckets
          - !Ref 'AWS::Region'
          - Bucket
        S3Key: !FindInMap 
          - Constants
          - S3Keys
          - UpdateBestSellersCode
      Environment:
        Variables:
          URL: !GetAtt 
            - ElastiCacheCluster
            - RedisEndpoint.Address 

 # ----------  STREAMING TRIGGERS ---------                     
  DataTableStream:
    DependsOn: TBooks
    Type: 'AWS::Lambda::EventSourceMapping'
    Properties:
      BatchSize: 1
      Enabled: true
      EventSourceArn: !GetAtt 
        - TBooks
        - StreamArn
      FunctionName: !GetAtt 
        - UpdateSearchCluster
        - Arn
      StartingPosition: TRIM_HORIZON
  OrderTableStream:
    DependsOn: TOrders
    Type: 'AWS::Lambda::EventSourceMapping'
    Properties:
      BatchSize: 1
      Enabled: true
      EventSourceArn: !GetAtt 
        - TOrders
        - StreamArn
      FunctionName: !GetAtt 
        - FunctionUpdateBestSellers
        - Arn
      StartingPosition: TRIM_HORIZON   

# ---------- LAMBDA for DYNAMODB FUNCTIONS ---------         
  FunctionListOrders:
    Type: 'AWS::Lambda::Function'
    Properties:
      FunctionName: !Sub '${ProjectName}-ListOrders'
      Description: Get list of books ordered by customerId
      Handler: index.handler
      MemorySize: 256
      Runtime: nodejs8.10
      Role: !GetAtt 
        - DynamoDbRole
        - Arn
      Timeout: 120
      Environment:
        Variables:
          TABLE_NAME: !Sub '${ProjectName}-Orders'
      Code:
        S3Bucket: !FindInMap 
          - S3Buckets
          - !Ref 'AWS::Region'
          - Bucket
        S3Key: !FindInMap 
          - Constants
          - S3Keys
          - ListOrdersCode
    Metadata:
      'AWS::CloudFormation::Designer':
        id: f873825f-3037-47b0-90b4-fca6924fb4e9
  FunctionGetBook:
    Type: 'AWS::Lambda::Function'
    Properties:
      FunctionName: !Sub '${ProjectName}-GetBook'
      Description: Get book by id
      Handler: index.handler
      MemorySize: 256
      Runtime: nodejs8.10
      Role: !GetAtt 
        - DynamoDbRole
        - Arn
      Timeout: 120
      Environment:
        Variables:
          TABLE_NAME: !Sub '${ProjectName}-Books'
      Code:
        S3Bucket: !FindInMap 
          - S3Buckets
          - !Ref 'AWS::Region'
          - Bucket
        S3Key: !FindInMap 
          - Constants
          - S3Keys
          - GetBookCode
    Metadata:
      'AWS::CloudFormation::Designer':
        id: 1ae22cac-5803-4077-a6fe-1a3ca1aedfc2
  FunctionListBooks:
    Type: 'AWS::Lambda::Function'
    Properties:
      FunctionName: !Sub '${ProjectName}-ListBooks'
      Description: Get list of books by category
      Handler: index.handler
      MemorySize: 256
      Runtime: nodejs8.10
      Role: !GetAtt 
        - DynamoDbRole
        - Arn
      Timeout: 120
      Environment:
        Variables:
          TABLE_NAME: !Sub '${ProjectName}-Books'
      Code:
        S3Bucket: !FindInMap 
          - S3Buckets
          - !Ref 'AWS::Region'
          - Bucket
        S3Key: !FindInMap 
          - Constants
          - S3Keys
          - ListBooksCode
    Metadata:
      'AWS::CloudFormation::Designer':
        id: 8e306d11-6d48-49e0-8f69-760139c83447
  FunctionUpdateCart:
    Type: 'AWS::Lambda::Function'
    Properties:
      FunctionName: !Sub '${ProjectName}-UpdateCart'
      Description: Update Customer's cart
      Handler: index.handler
      MemorySize: 256
      Runtime: nodejs8.10
      Role: !GetAtt 
        - DynamoDbRole
        - Arn
      Timeout: 120
      Environment:
        Variables:
          TABLE_NAME: !Sub '${ProjectName}-Cart'
      Code:
        S3Bucket: !FindInMap 
          - S3Buckets
          - !Ref 'AWS::Region'
          - Bucket
        S3Key: !FindInMap 
          - Constants
          - S3Keys
          - UpdateCartCode
    Metadata:
      'AWS::CloudFormation::Designer':
        id: 92605ac3-2103-491b-8593-c1ed98181425
  FunctionGetCartItem:
    Type: 'AWS::Lambda::Function'
    Properties:
      FunctionName: !Sub '${ProjectName}-GetCartItem'
      Description: Get item in cart by customer and book id
      Handler: index.handler
      MemorySize: 256
      Runtime: nodejs8.10
      Role: !GetAtt 
        - DynamoDbRole
        - Arn
      Timeout: 120
      Environment:
        Variables:
          TABLE_NAME: !Sub '${ProjectName}-Cart'
      Code:
        S3Bucket: !FindInMap 
          - S3Buckets
          - !Ref 'AWS::Region'
          - Bucket
        S3Key: !FindInMap 
          - Constants
          - S3Keys
          - GetCartItemCode
    Metadata:
      'AWS::CloudFormation::Designer':
        id: e64608f0-5134-4c91-8f3c-4d03408c8236
  FunctionListItemsInCart:
    Type: 'AWS::Lambda::Function'
    Properties:
      FunctionName: !Sub '${ProjectName}-ListOrdersInCart'
      Description: Get list of items in cart
      Handler: index.handler
      MemorySize: 256
      Runtime: nodejs8.10
      Role: !GetAtt 
        - DynamoDbRole
        - Arn
      Timeout: 120
      Environment:
        Variables:
          TABLE_NAME: !Sub '${ProjectName}-Cart'
      Code:
        S3Bucket: !FindInMap 
          - S3Buckets
          - !Ref 'AWS::Region'
          - Bucket
        S3Key: !FindInMap 
          - Constants
          - S3Keys
          - ListItemsInCartCode
    Metadata:
      'AWS::CloudFormation::Designer':
        id: e64608f0-5134-4c91-8f3c-4d03408c8236
  FunctionAddToCart:
    Type: 'AWS::Lambda::Function'
    Properties:
      FunctionName: !Sub '${ProjectName}-AddToCart'
      Description: Add a book to cart
      Handler: index.handler
      MemorySize: 256
      Runtime: nodejs8.10
      Role: !GetAtt 
        - DynamoDbRole
        - Arn
      Timeout: 120
      Environment:
        Variables:
          TABLE_NAME: !Sub '${ProjectName}-Cart'
      Code:
        S3Bucket: !FindInMap 
          - S3Buckets
          - !Ref 'AWS::Region'
          - Bucket
        S3Key: !FindInMap 
          - Constants
          - S3Keys
          - AddToCartCode
    Metadata:
      'AWS::CloudFormation::Designer':
        id: e64608f0-5134-4c91-8f3c-4d03408c8236
  FunctionRemoveFromCart:
    Type: 'AWS::Lambda::Function'
    Properties:
      FunctionName: !Sub '${ProjectName}-RemoveFromCart'
      Description: Remove a book from cart
      Handler: index.handler
      MemorySize: 256
      Runtime: nodejs8.10
      Role: !GetAtt 
        - DynamoDbRole
        - Arn
      Timeout: 120
      Environment:
        Variables:
          TABLE_NAME: !Sub '${ProjectName}-Cart'
      Code:
        S3Bucket: !FindInMap 
          - S3Buckets
          - !Ref 'AWS::Region'
          - Bucket
        S3Key: !FindInMap 
          - Constants
          - S3Keys
          - RemoveFromCartCode
    Metadata:
      'AWS::CloudFormation::Designer':
        id: e64608f0-5134-4c91-8f3c-4d03408c8236
  FunctionCheckout:
    Type: 'AWS::Lambda::Function'
    Properties:
      FunctionName: !Sub '${ProjectName}-Checkout'
      Description: Get list of books ordered by customerId
      Handler: index.handler
      MemorySize: 256
      Runtime: nodejs8.10
      Role: !GetAtt 
        - DynamoDbRole
        - Arn
      Timeout: 120
      Environment:
        Variables:
          ORDERS_TABLE: !Sub '${ProjectName}-Orders'
          CART_TABLE: !Sub '${ProjectName}-Cart'
      Code:
        S3Bucket: !FindInMap 
          - S3Buckets
          - !Ref 'AWS::Region'
          - Bucket
        S3Key: !FindInMap 
          - Constants
          - S3Keys
          - CheckoutCode
    Metadata:
      'AWS::CloudFormation::Designer':
        id: 9c3f4191-a370-4344-a5b1-626228919c45
  FunctionUploadBooks:
    DependsOn: DataTableStream
    Type: 'AWS::Lambda::Function'
    Properties:
      FunctionName: !Sub '${ProjectName}-UploadBooks'
      Description: Upload sample data for books
      Handler: index.handler
      Runtime: nodejs8.10
      Role: !GetAtt 
        - DynamoDbRole
        - Arn
      Timeout: 120
      Environment:
        Variables:
          TABLE_NAME: !Sub '${ProjectName}-Books'
          S3_BUCKET: !FindInMap 
                    - S3Buckets
                    - !Ref 'AWS::Region'
                    - Bucket
          FILE_NAME: !FindInMap 
                    - Constants
                    - S3Keys
                    - booksData
      Code:
        S3Bucket: !FindInMap 
          - S3Buckets
          - !Ref 'AWS::Region'
          - Bucket
        S3Key: !FindInMap 
          - Constants
          - S3Keys
          - UploadBooksCode
    Metadata:
      'AWS::CloudFormation::Designer':
        id: 9c3f4191-a370-4344-a5b1-626228919c47

# ---------- LAMBDA FUNCTIONS for NEPTUNE ---------  

  FunctionGetRecommendations:
    Type: 'AWS::Lambda::Function'
    Properties:
      FunctionName: !Sub '${ProjectName}-GetRecommendations'
      Code:
        S3Bucket: !FindInMap 
          - S3Buckets
          - !Ref 'AWS::Region'
          - Bucket
        S3Key: !FindInMap 
          - Constants
          - S3Keys
          - GetRecommendationsCode
      Description: Get the top 5 product recommendations from Neptune
      Environment:
        Variables:
          neptunedb: !GetAtt bookstoreNeptuneCluster.Endpoint
      Handler: index.handler
      MemorySize: 256
      Role:
        'Fn::GetAtt':
          - RecommendationsLambdaRole
          - Arn
      Runtime: python3.6
      Timeout: 30
      VpcConfig:
        SecurityGroupIds:
          - Ref: bookstoreNeptuneSecurityGroup
        SubnetIds:
          - Ref: bookstoreSubnet1
          - Ref: bookstoreSubnet2

  FunctionGetRecommendationsByBook:
    Type: 'AWS::Lambda::Function'
    Properties:
      FunctionName: !Sub '${ProjectName}-GetRecommendationsByBook'
      Code:
        S3Bucket: !FindInMap 
          - S3Buckets
          - !Ref 'AWS::Region'
          - Bucket
        S3Key: !FindInMap 
          - Constants
          - S3Keys
          - GetRecommendationsByBookCode
      Description: Get friends who purchased this book
      Environment:
        Variables:
          neptunedb: !GetAtt bookstoreNeptuneCluster.Endpoint 
      Handler: index.handler
      MemorySize: 256
      Role:
        'Fn::GetAtt':
          - RecommendationsLambdaRole
          - Arn
      Runtime: python3.6
      Timeout: 30
      VpcConfig:
        SecurityGroupIds:
          - Ref: bookstoreNeptuneSecurityGroup
        SubnetIds:
          - Ref: bookstoreSubnet1
          - Ref: bookstoreSubnet2
        
# ---------- LAMBDA FUNCTIONS for ELASTICSEARCH and ELASTICACHE  ---------          
  FunctionSearch:
    Type: 'AWS::Lambda::Function'
    DependsOn:
      - ESSearchRole
      - ElasticsearchDomain
      - TBooks
    Properties:
      FunctionName: !Sub '${ProjectName}-Search'
      Description: Search for books across book names, authors, and categories
      Handler: index.handler
      MemorySize: 256
      Role: !GetAtt 
        - ESSearchRole
        - Arn
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



template/master-fullstack.yaml [790:1249]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  UpdateSearchCluster:
    Type: 'AWS::Lambda::Function'
    DependsOn:
      - ESSearchRole
      - ElasticsearchDomain
      - TBooks
    Properties:
      FunctionName: !Sub '${ProjectName}-UpdateSearchCluster'
      Description: 'Update Elasticsearch cluster as books are added'
      Handler: index.handler
      Role: !GetAtt 
        - ESSearchRole
        - Arn
      Runtime: python2.7
      Timeout: '60'
      VpcConfig:
        SecurityGroupIds:
          - Fn::GetAtt: [bookstoreVPC, DefaultSecurityGroup]
        SubnetIds:
          - Ref: bookstoreSubnet1
      Code:
        S3Bucket: !FindInMap 
          - S3Buckets
          - !Ref 'AWS::Region'
          - Bucket
        S3Key: !FindInMap 
          - Constants
          - S3Keys
          - UpdateSearchCode
      Environment:
        Variables:
          ESENDPOINT: !GetAtt 
            - ElasticsearchDomain
            - DomainEndpoint
          REGION: !Ref 'AWS::Region'
  FunctionUpdateBestSellers:
    Type: 'AWS::Lambda::Function'
    DependsOn:
      - RedisRole
      - ElastiCacheCluster
      - TOrders
    Properties:
      FunctionName: !Sub '${ProjectName}-UpdateBestSellers'
      Description: 'Updates BestSellers as orders are placed'
      Handler: index.handler
      Role: !GetAtt 
        - RedisRole
        - Arn
      Runtime: nodejs8.10
      Timeout: '60'
      VpcConfig:
        SecurityGroupIds:
          - Ref: redisLambdaSecurityGroup
        SubnetIds: 
          - Ref: bookstoreSubnet1
      Code:
        S3Bucket: !FindInMap 
          - S3Buckets
          - !Ref 'AWS::Region'
          - Bucket
        S3Key: !FindInMap 
          - Constants
          - S3Keys
          - UpdateBestSellersCode
      Environment:
        Variables:
          URL: !GetAtt 
            - ElastiCacheCluster
            - RedisEndpoint.Address 

 # ----------  STREAMING TRIGGERS ---------                     
  DataTableStream:
    DependsOn: TBooks
    Type: 'AWS::Lambda::EventSourceMapping'
    Properties:
      BatchSize: 1
      Enabled: true
      EventSourceArn: !GetAtt 
        - TBooks
        - StreamArn
      FunctionName: !GetAtt 
        - UpdateSearchCluster
        - Arn
      StartingPosition: TRIM_HORIZON
  OrderTableStream:
    DependsOn: TOrders
    Type: 'AWS::Lambda::EventSourceMapping'
    Properties:
      BatchSize: 1
      Enabled: true
      EventSourceArn: !GetAtt 
        - TOrders
        - StreamArn
      FunctionName: !GetAtt 
        - FunctionUpdateBestSellers
        - Arn
      StartingPosition: TRIM_HORIZON   

# ---------- LAMBDA for DYNAMODB FUNCTIONS ---------         
  FunctionListOrders:
    Type: 'AWS::Lambda::Function'
    Properties:
      FunctionName: !Sub '${ProjectName}-ListOrders'
      Description: Get list of books ordered by customerId
      Handler: index.handler
      MemorySize: 256
      Runtime: nodejs8.10
      Role: !GetAtt 
        - DynamoDbRole
        - Arn
      Timeout: 120
      Environment:
        Variables:
          TABLE_NAME: !Sub '${ProjectName}-Orders'
      Code:
        S3Bucket: !FindInMap 
          - S3Buckets
          - !Ref 'AWS::Region'
          - Bucket
        S3Key: !FindInMap 
          - Constants
          - S3Keys
          - ListOrdersCode
    Metadata:
      'AWS::CloudFormation::Designer':
        id: f873825f-3037-47b0-90b4-fca6924fb4e9
  FunctionGetBook:
    Type: 'AWS::Lambda::Function'
    Properties:
      FunctionName: !Sub '${ProjectName}-GetBook'
      Description: Get book by id
      Handler: index.handler
      MemorySize: 256
      Runtime: nodejs8.10
      Role: !GetAtt 
        - DynamoDbRole
        - Arn
      Timeout: 120
      Environment:
        Variables:
          TABLE_NAME: !Sub '${ProjectName}-Books'
      Code:
        S3Bucket: !FindInMap 
          - S3Buckets
          - !Ref 'AWS::Region'
          - Bucket
        S3Key: !FindInMap 
          - Constants
          - S3Keys
          - GetBookCode
    Metadata:
      'AWS::CloudFormation::Designer':
        id: 1ae22cac-5803-4077-a6fe-1a3ca1aedfc2
  FunctionListBooks:
    Type: 'AWS::Lambda::Function'
    Properties:
      FunctionName: !Sub '${ProjectName}-ListBooks'
      Description: Get list of books by category
      Handler: index.handler
      MemorySize: 256
      Runtime: nodejs8.10
      Role: !GetAtt 
        - DynamoDbRole
        - Arn
      Timeout: 120
      Environment:
        Variables:
          TABLE_NAME: !Sub '${ProjectName}-Books'
      Code:
        S3Bucket: !FindInMap 
          - S3Buckets
          - !Ref 'AWS::Region'
          - Bucket
        S3Key: !FindInMap 
          - Constants
          - S3Keys
          - ListBooksCode
    Metadata:
      'AWS::CloudFormation::Designer':
        id: 8e306d11-6d48-49e0-8f69-760139c83447
  FunctionUpdateCart:
    Type: 'AWS::Lambda::Function'
    Properties:
      FunctionName: !Sub '${ProjectName}-UpdateCart'
      Description: Update Customer's cart
      Handler: index.handler
      MemorySize: 256
      Runtime: nodejs8.10
      Role: !GetAtt 
        - DynamoDbRole
        - Arn
      Timeout: 120
      Environment:
        Variables:
          TABLE_NAME: !Sub '${ProjectName}-Cart'
      Code:
        S3Bucket: !FindInMap 
          - S3Buckets
          - !Ref 'AWS::Region'
          - Bucket
        S3Key: !FindInMap 
          - Constants
          - S3Keys
          - UpdateCartCode
    Metadata:
      'AWS::CloudFormation::Designer':
        id: 92605ac3-2103-491b-8593-c1ed98181425
  FunctionGetCartItem:
    Type: 'AWS::Lambda::Function'
    Properties:
      FunctionName: !Sub '${ProjectName}-GetCartItem'
      Description: Get item in cart by customer and book id
      Handler: index.handler
      MemorySize: 256
      Runtime: nodejs8.10
      Role: !GetAtt 
        - DynamoDbRole
        - Arn
      Timeout: 120
      Environment:
        Variables:
          TABLE_NAME: !Sub '${ProjectName}-Cart'
      Code:
        S3Bucket: !FindInMap 
          - S3Buckets
          - !Ref 'AWS::Region'
          - Bucket
        S3Key: !FindInMap 
          - Constants
          - S3Keys
          - GetCartItemCode
    Metadata:
      'AWS::CloudFormation::Designer':
        id: e64608f0-5134-4c91-8f3c-4d03408c8236
  FunctionListItemsInCart:
    Type: 'AWS::Lambda::Function'
    Properties:
      FunctionName: !Sub '${ProjectName}-ListOrdersInCart'
      Description: Get list of items in cart
      Handler: index.handler
      MemorySize: 256
      Runtime: nodejs8.10
      Role: !GetAtt 
        - DynamoDbRole
        - Arn
      Timeout: 120
      Environment:
        Variables:
          TABLE_NAME: !Sub '${ProjectName}-Cart'
      Code:
        S3Bucket: !FindInMap 
          - S3Buckets
          - !Ref 'AWS::Region'
          - Bucket
        S3Key: !FindInMap 
          - Constants
          - S3Keys
          - ListItemsInCartCode
    Metadata:
      'AWS::CloudFormation::Designer':
        id: e64608f0-5134-4c91-8f3c-4d03408c8236
  FunctionAddToCart:
    Type: 'AWS::Lambda::Function'
    Properties:
      FunctionName: !Sub '${ProjectName}-AddToCart'
      Description: Add a book to cart
      Handler: index.handler
      MemorySize: 256
      Runtime: nodejs8.10
      Role: !GetAtt 
        - DynamoDbRole
        - Arn
      Timeout: 120
      Environment:
        Variables:
          TABLE_NAME: !Sub '${ProjectName}-Cart'
      Code:
        S3Bucket: !FindInMap 
          - S3Buckets
          - !Ref 'AWS::Region'
          - Bucket
        S3Key: !FindInMap 
          - Constants
          - S3Keys
          - AddToCartCode
    Metadata:
      'AWS::CloudFormation::Designer':
        id: e64608f0-5134-4c91-8f3c-4d03408c8236
  FunctionRemoveFromCart:
    Type: 'AWS::Lambda::Function'
    Properties:
      FunctionName: !Sub '${ProjectName}-RemoveFromCart'
      Description: Remove a book from cart
      Handler: index.handler
      MemorySize: 256
      Runtime: nodejs8.10
      Role: !GetAtt 
        - DynamoDbRole
        - Arn
      Timeout: 120
      Environment:
        Variables:
          TABLE_NAME: !Sub '${ProjectName}-Cart'
      Code:
        S3Bucket: !FindInMap 
          - S3Buckets
          - !Ref 'AWS::Region'
          - Bucket
        S3Key: !FindInMap 
          - Constants
          - S3Keys
          - RemoveFromCartCode
    Metadata:
      'AWS::CloudFormation::Designer':
        id: e64608f0-5134-4c91-8f3c-4d03408c8236
  FunctionCheckout:
    Type: 'AWS::Lambda::Function'
    Properties:
      FunctionName: !Sub '${ProjectName}-Checkout'
      Description: Get list of books ordered by customerId
      Handler: index.handler
      MemorySize: 256
      Runtime: nodejs8.10
      Role: !GetAtt 
        - DynamoDbRole
        - Arn
      Timeout: 120
      Environment:
        Variables:
          ORDERS_TABLE: !Sub '${ProjectName}-Orders'
          CART_TABLE: !Sub '${ProjectName}-Cart'
      Code:
        S3Bucket: !FindInMap 
          - S3Buckets
          - !Ref 'AWS::Region'
          - Bucket
        S3Key: !FindInMap 
          - Constants
          - S3Keys
          - CheckoutCode
    Metadata:
      'AWS::CloudFormation::Designer':
        id: 9c3f4191-a370-4344-a5b1-626228919c45
  FunctionUploadBooks:
    DependsOn: DataTableStream
    Type: 'AWS::Lambda::Function'
    Properties:
      FunctionName: !Sub '${ProjectName}-UploadBooks'
      Description: Upload sample data for books
      Handler: index.handler
      Runtime: nodejs8.10
      Role: !GetAtt 
        - DynamoDbRole
        - Arn
      Timeout: 120
      Environment:
        Variables:
          TABLE_NAME: !Sub '${ProjectName}-Books'
          S3_BUCKET: !FindInMap 
                    - S3Buckets
                    - !Ref 'AWS::Region'
                    - Bucket
          FILE_NAME: !FindInMap 
                    - Constants
                    - S3Keys
                    - booksData
      Code:
        S3Bucket: !FindInMap 
          - S3Buckets
          - !Ref 'AWS::Region'
          - Bucket
        S3Key: !FindInMap 
          - Constants
          - S3Keys
          - UploadBooksCode
    Metadata:
      'AWS::CloudFormation::Designer':
        id: 9c3f4191-a370-4344-a5b1-626228919c47

# ---------- LAMBDA FUNCTIONS for NEPTUNE ---------  

  FunctionGetRecommendations:
    Type: 'AWS::Lambda::Function'
    Properties:
      FunctionName: !Sub '${ProjectName}-GetRecommendations'
      Code:
        S3Bucket: !FindInMap 
          - S3Buckets
          - !Ref 'AWS::Region'
          - Bucket
        S3Key: !FindInMap 
          - Constants
          - S3Keys
          - GetRecommendationsCode
      Description: Get the top 5 product recommendations from Neptune
      Environment:
        Variables:
          neptunedb: !GetAtt bookstoreNeptuneCluster.Endpoint
      Handler: index.handler
      MemorySize: 256
      Role:
        'Fn::GetAtt':
          - RecommendationsLambdaRole
          - Arn
      Runtime: python3.6
      Timeout: 30
      VpcConfig:
        SecurityGroupIds:
          - Ref: bookstoreNeptuneSecurityGroup
        SubnetIds:
          - Ref: bookstoreSubnet1
          - Ref: bookstoreSubnet2

  FunctionGetRecommendationsByBook:
    Type: 'AWS::Lambda::Function'
    Properties:
      FunctionName: !Sub '${ProjectName}-GetRecommendationsByBook'
      Code:
        S3Bucket: !FindInMap 
          - S3Buckets
          - !Ref 'AWS::Region'
          - Bucket
        S3Key: !FindInMap 
          - Constants
          - S3Keys
          - GetRecommendationsByBookCode
      Description: Get friends who purchased this book
      Environment:
        Variables:
          neptunedb: !GetAtt bookstoreNeptuneCluster.Endpoint 
      Handler: index.handler
      MemorySize: 256
      Role:
        'Fn::GetAtt':
          - RecommendationsLambdaRole
          - Arn
      Runtime: python3.6
      Timeout: 30
      VpcConfig:
        SecurityGroupIds:
          - Ref: bookstoreNeptuneSecurityGroup
        SubnetIds:
          - Ref: bookstoreSubnet1
          - Ref: bookstoreSubnet2
        
# ---------- LAMBDA FUNCTIONS for ELASTICSEARCH and ELASTICACHE  ---------          
  FunctionSearch:
    Type: 'AWS::Lambda::Function'
    DependsOn:
      - ESSearchRole
      - ElasticsearchDomain
      - TBooks
    Properties:
      FunctionName: !Sub '${ProjectName}-Search'
      Description: Search for books across book names, authors, and categories
      Handler: index.handler
      MemorySize: 256
      Role: !GetAtt 
        - ESSearchRole
        - Arn
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



