
service: dynamodb # Important: this must be unique in AWS Cloudformation!
frameworkVersion: ">=1.14.0 <2.0.0"

provider:
  name: aws
  runtime: nodejs12.x
  region: us-west-2
  stage: ${env:SLS_STAGE, self:custom.stageDefault}
  # Let's be conservative and prevent any unexpected changes
  # to the stack. See:
  # https://github.com/gladly-team/tab/issues/582
  # Example to update policy:
  #   aws cloudformation set-stack-policy --stack-name dynamodb-test --region us-west-2 --stack-policy-body \
  #   '{"Statement":[
  #     {"Effect":"Allow","Principal":"*","Action":"Update:Modify","Resource":"*"}
  #   ]}'
  stackPolicy:
    - Effect: Deny
      Principal: "*"
      Action: "Update:*"
      Resource: "*"

plugins:
  # https://github.com/sbstjn/serverless-dynamodb-autoscaling
  # https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-dynamodb-table.html#cfn-dynamodb-table-examples-application-autoscaling
  - serverless-dynamodb-autoscaling

custom:
  stageDefault: dev
  
  # Set DynamoDB scaling capacities based on stage.
  customCapacities:
    # test stage table capacities: use same as dev
    test: ${self:custom.customCapacities.dev}
    # dev stage table capacities
    dev: 
      usersTable:
        read:
          minimum: 1
          maximum: 12
          usage: 0.75
        write:
          minimum: 1
          maximum: 12
          usage: 0.60
      charitiesTable:
        read:
          minimum: 1
          maximum: 12
          usage: 0.75
        write:
          minimum: 1
          maximum: 12
          usage: 0.60
      userImpactTable:
        read:
          minimum: 1
          maximum: 12
          usage: 0.75
        write:
          minimum: 1
          maximum: 12
          usage: 0.60
      invitedUsersTable:
        read:
          minimum: 1
          maximum: 12
          usage: 0.75
        write:
          minimum: 1
          maximum: 12
          usage: 0.60
      missionsTable:
        read:
          minimum: 1
          maximum: 12
          usage: 0.75
        write:
          minimum: 1
          maximum: 12
          usage: 0.60
      userMissionsTable:
        read:
          minimum: 1
          maximum: 12
          usage: 0.75
        write:
          minimum: 1
          maximum: 12
          usage: 0.60
      widgetsTable:
        read:
          minimum: 1
          maximum: 12
          usage: 0.75
        write:
          minimum: 1
          maximum: 12
          usage: 0.60
      userLevelsTable:
        read:
          minimum: 1
          maximum: 12
          usage: 0.75
        write:
          minimum: 1
          maximum: 12
          usage: 0.60
      vcDonationLogTable:
        read:
          minimum: 1
          maximum: 12
          usage: 0.75
        write:
          minimum: 1
          maximum: 12
          usage: 0.60
      vcDonationByCharityTable:
        read:
          minimum: 1
          maximum: 12
          usage: 0.75
        write:
          minimum: 1
          maximum: 12
          usage: 0.60
      userRevenueLogTable:
        read:
          minimum: 1
          maximum: 12
          usage: 0.75
        write:
          minimum: 1
          maximum: 12
          usage: 0.60
      videoAdLogTable:
        read:
          minimum: 1
          maximum: 12
          usage: 0.75
        write:
          minimum: 1
          maximum: 12
          usage: 0.60
      userDataConsentLogTable:
        read:
          minimum: 1
          maximum: 12
          usage: 0.75
        write:
          minimum: 1
          maximum: 12
          usage: 0.60
      backgroundImagesTable:
        read:
          minimum: 1
          maximum: 12
          usage: 0.75
        write:
          minimum: 1
          maximum: 12
          usage: 0.60
      userWidgetsTable:
        read:
          minimum: 1
          maximum: 12
          usage: 0.75
        write:
          minimum: 1
          maximum: 12
          usage: 0.60
      userTabsLogTable:
        read:
          minimum: 1
          maximum: 12
          usage: 0.75
        write:
          minimum: 1
          maximum: 12
          usage: 0.60
      userSearchLogTable:
        read:
          minimum: 1
          maximum: 12
          usage: 0.75
        write:
          minimum: 1
          maximum: 12
          usage: 0.60
      referralDataLogTable:
        read:
          minimum: 1
          maximum: 12
          usage: 0.75
        write:
          minimum: 1
          maximum: 12
          usage: 0.60
      referralLinkClickLog:
        read:
          minimum: 1
          maximum: 12
          usage: 0.75
        write:
          minimum: 1
          maximum: 12
          usage: 0.60
      causeTable:
        read:
          minimum: 1
          maximum: 12
          usage: 0.75
        write:
          minimum: 1
          maximum: 12
          usage: 0.60
      userSwitchSearchPromptLogTable:
        read:
          minimum: 1
          maximum: 12
          usage: 0.75
        write:
          minimum: 1
          maximum: 12
          usage: 0.60
      userSearchSettingsLogTable:
        read:
          minimum: 1
          maximum: 12
          usage: 0.75
        write:
          minimum: 1
          maximum: 12
          usage: 0.60
      userExperimentTable:
        read:
          minimum: 1
          maximum: 12
          usage: 0.75
        write:
          minimum: 1
          maximum: 12
          usage: 0.60
      userEventLogTable:
        read:
          minimum: 1
          maximum: 12
          usage: 0.75
        write:
          minimum: 1
          maximum: 12
          usage: 0.60
      userGroupImpactMetricLogTable:
        read:
          minimum: 1
          maximum: 12
          usage: 0.75
        write:
          minimum: 1
          maximum: 12
          usage: 0.60
    # prod stage table capacities
    prod: 
      usersTable:
        read:
          minimum: 80
          maximum: 40000
          usage: 0.75
        write:
          minimum: 40
          maximum: 40000
          usage: 0.60
      charitiesTable:
        read:
          minimum: 5
          maximum: 40000
          usage: 0.75
        write:
          minimum: 1
          maximum: 40000
          usage: 0.60
      userImpactTable:
        read:
          minimum: 1
          maximum: 40000
          usage: 0.75
        write:
          minimum: 1
          maximum: 40000
          usage: 0.60
      invitedUsersTable:
        read:
          minimum: 1
          maximum: 40000
          usage: 0.75
        write:
          minimum: 1
          maximum: 40000
          usage: 0.60
      missionsTable:
        read:
          minimum: 1
          maximum: 40000
          usage: 0.75
        write:
          minimum: 1
          maximum: 40000
          usage: 0.60
      userMissionsTable:
        read:
          minimum: 1
          maximum: 40000
          usage: 0.75
        write:
          minimum: 1
          maximum: 40000
          usage: 0.60          
      widgetsTable:
        read:
          minimum: 10
          maximum: 40000
          usage: 0.75
        write:
          minimum: 1
          maximum: 40000
          usage: 0.60
      userLevelsTable:
        read:
          minimum: 5
          maximum: 40000
          usage: 0.75
        write:
          minimum: 1
          maximum: 40000
          usage: 0.60
      vcDonationLogTable:
        read:
          minimum: 1
          maximum: 40000
          usage: 0.75
        write:
          minimum: 5
          maximum: 40000
          usage: 0.60
      vcDonationByCharityTable:
        read:
          minimum: 1
          maximum: 40000
          usage: 0.75
        write:
          minimum: 5
          maximum: 40000
          usage: 0.60
      userRevenueLogTable:
        read:
          minimum: 1
          maximum: 40000
          usage: 0.75
        write:
          # Fairly high capacity needed, because it's one write per ad
          minimum: 20
          maximum: 40000
          usage: 0.60
      videoAdLogTable:
        read:
          minimum: 1
          maximum: 40000
          usage: 0.75
        write:
          minimum: 1
          maximum: 40000
          usage: 0.60
      userDataConsentLogTable:
        read:
          minimum: 1
          maximum: 40000
          usage: 0.75
        write:
          minimum: 1
          maximum: 40000
          usage: 0.60
      backgroundImagesTable:
        read:
          minimum: 5
          maximum: 40000
          usage: 0.75
        write:
          minimum: 1
          maximum: 40000
          usage: 0.60
      userWidgetsTable:
        read:
          minimum: 5
          maximum: 40000
          usage: 0.75
        write:
          minimum: 2
          maximum: 40000
          usage: 0.60
      userTabsLogTable:
        read:
          minimum: 1
          maximum: 40000
          usage: 0.75
        write:
          minimum: 20
          maximum: 40000
          usage: 0.60
      userSearchLogTable:
        read:
          minimum: 1
          maximum: 40000
          usage: 0.75
        write:
          minimum: 1
          maximum: 40000
          usage: 0.60
      referralDataLogTable:
        read:
          minimum: 1
          maximum: 40000
          usage: 0.75
        write:
          minimum: 1
          maximum: 40000
          usage: 0.60
      referralLinkClickLog:
        read:
          minimum: 1
          maximum: 40000
          usage: 0.75
        write:
          minimum: 1
          maximum: 40000
          usage: 0.60
      causeTable:
        read:
          minimum: 80
          maximum: 40000
          usage: 0.75
        write:
          minimum: 40
          maximum: 40000
          usage: 0.60
      userSwitchSearchPromptLogTable:
        read:
          minimum: 1
          maximum: 40000
          usage: 0.75
        write:
          minimum: 1
          maximum: 40000
          usage: 0.60
      userSearchSettingsLogTable:
        read:
          minimum: 1
          maximum: 40000
          usage: 0.75
        write:
          minimum: 1
          maximum: 40000
          usage: 0.60
      userExperimentTable:
        read:
          minimum: 5
          maximum: 40000
          usage: 0.75
        write:
          minimum: 5
          maximum: 40000
          usage: 0.60
      userEventLogTable:
        read:
          minimum: 1
          maximum: 40000
          usage: 0.75
        write:
          minimum: 1
          maximum: 40000
          usage: 0.60

  # https://github.com/sbstjn/serverless-dynamodb-autoscaling
  capacities:
    - table: usersTable
      index:
        - UsersByUsername
        - UsersByEmail
      read:
        minimum: ${self:custom.customCapacities.${self:provider.stage}.usersTable.read.minimum}
        maximum: ${self:custom.customCapacities.${self:provider.stage}.usersTable.read.maximum}
        usage: ${self:custom.customCapacities.${self:provider.stage}.usersTable.read.usage}
      write:
        minimum: ${self:custom.customCapacities.${self:provider.stage}.usersTable.write.minimum}
        maximum: ${self:custom.customCapacities.${self:provider.stage}.usersTable.write.maximum}
        usage: ${self:custom.customCapacities.${self:provider.stage}.usersTable.write.usage}
    - table: charitiesTable
      read:
        minimum: ${self:custom.customCapacities.${self:provider.stage}.charitiesTable.read.minimum}
        maximum: ${self:custom.customCapacities.${self:provider.stage}.charitiesTable.read.maximum}
        usage: ${self:custom.customCapacities.${self:provider.stage}.charitiesTable.read.usage}
      write:
        minimum: ${self:custom.customCapacities.${self:provider.stage}.charitiesTable.write.minimum}
        maximum: ${self:custom.customCapacities.${self:provider.stage}.charitiesTable.write.maximum}
        usage: ${self:custom.customCapacities.${self:provider.stage}.charitiesTable.write.usage}
    - table: userImpactTable
      read:
        minimum: ${self:custom.customCapacities.${self:provider.stage}.userImpactTable.read.minimum}
        maximum: ${self:custom.customCapacities.${self:provider.stage}.userImpactTable.read.maximum}
        usage: ${self:custom.customCapacities.${self:provider.stage}.userImpactTable.read.usage}
      write:
        minimum: ${self:custom.customCapacities.${self:provider.stage}.userImpactTable.write.minimum}
        maximum: ${self:custom.customCapacities.${self:provider.stage}.userImpactTable.write.maximum}
        usage: ${self:custom.customCapacities.${self:provider.stage}.userImpactTable.write.usage}
    - table: invitedUsersTable
      index:
          - InvitesByInviter
          - InvitesByInvitedEmail
      read:
        minimum: ${self:custom.customCapacities.${self:provider.stage}.invitedUsersTable.read.minimum}
        maximum: ${self:custom.customCapacities.${self:provider.stage}.invitedUsersTable.read.maximum}
        usage: ${self:custom.customCapacities.${self:provider.stage}.invitedUsersTable.read.usage}
      write:
        minimum: ${self:custom.customCapacities.${self:provider.stage}.invitedUsersTable.write.minimum}
        maximum: ${self:custom.customCapacities.${self:provider.stage}.invitedUsersTable.write.maximum}
        usage: ${self:custom.customCapacities.${self:provider.stage}.invitedUsersTable.write.usage}
    - table: missionsTable
      read:
        minimum: ${self:custom.customCapacities.${self:provider.stage}.missionsTable.read.minimum}
        maximum: ${self:custom.customCapacities.${self:provider.stage}.missionsTable.read.maximum}
        usage: ${self:custom.customCapacities.${self:provider.stage}.missionsTable.read.usage}
      write:
        minimum: ${self:custom.customCapacities.${self:provider.stage}.missionsTable.write.minimum}
        maximum: ${self:custom.customCapacities.${self:provider.stage}.missionsTable.write.maximum}
        usage: ${self:custom.customCapacities.${self:provider.stage}.missionsTable.write.usage}
    - table: userMissionsTable
      index:
        - userMissionsByDate
      read:
        minimum: ${self:custom.customCapacities.${self:provider.stage}.userMissionsTable.read.minimum}
        maximum: ${self:custom.customCapacities.${self:provider.stage}.userMissionsTable.read.maximum}
        usage: ${self:custom.customCapacities.${self:provider.stage}.userMissionsTable.read.usage}
      write:
        minimum: ${self:custom.customCapacities.${self:provider.stage}.userMissionsTable.write.minimum}
        maximum: ${self:custom.customCapacities.${self:provider.stage}.userMissionsTable.write.maximum}
        usage: ${self:custom.customCapacities.${self:provider.stage}.userMissionsTable.write.usage}
    - table: widgetsTable
      read:
        minimum: ${self:custom.customCapacities.${self:provider.stage}.widgetsTable.read.minimum}
        maximum: ${self:custom.customCapacities.${self:provider.stage}.widgetsTable.read.maximum}
        usage: ${self:custom.customCapacities.${self:provider.stage}.widgetsTable.read.usage}
      write:
        minimum: ${self:custom.customCapacities.${self:provider.stage}.widgetsTable.write.minimum}
        maximum: ${self:custom.customCapacities.${self:provider.stage}.widgetsTable.write.maximum}
        usage: ${self:custom.customCapacities.${self:provider.stage}.widgetsTable.write.usage}
    - table: userLevelsTable
      read:
        minimum: ${self:custom.customCapacities.${self:provider.stage}.userLevelsTable.read.minimum}
        maximum: ${self:custom.customCapacities.${self:provider.stage}.userLevelsTable.read.maximum}
        usage: ${self:custom.customCapacities.${self:provider.stage}.userLevelsTable.read.usage}
      write:
        minimum: ${self:custom.customCapacities.${self:provider.stage}.userLevelsTable.write.minimum}
        maximum: ${self:custom.customCapacities.${self:provider.stage}.userLevelsTable.write.maximum}
        usage: ${self:custom.customCapacities.${self:provider.stage}.userLevelsTable.write.usage}
    - table: vcDonationLogTable
      read:
        minimum: ${self:custom.customCapacities.${self:provider.stage}.vcDonationLogTable.read.minimum}
        maximum: ${self:custom.customCapacities.${self:provider.stage}.vcDonationLogTable.read.maximum}
        usage: ${self:custom.customCapacities.${self:provider.stage}.vcDonationLogTable.read.usage}
      write:
        minimum: ${self:custom.customCapacities.${self:provider.stage}.vcDonationLogTable.write.minimum}
        maximum: ${self:custom.customCapacities.${self:provider.stage}.vcDonationLogTable.write.maximum}
        usage: ${self:custom.customCapacities.${self:provider.stage}.vcDonationLogTable.write.usage}
    - table: vcDonationByCharityTable
      read:
        minimum: ${self:custom.customCapacities.${self:provider.stage}.vcDonationByCharityTable.read.minimum}
        maximum: ${self:custom.customCapacities.${self:provider.stage}.vcDonationByCharityTable.read.maximum}
        usage: ${self:custom.customCapacities.${self:provider.stage}.vcDonationByCharityTable.read.usage}
      write:
        minimum: ${self:custom.customCapacities.${self:provider.stage}.vcDonationByCharityTable.write.minimum}
        maximum: ${self:custom.customCapacities.${self:provider.stage}.vcDonationByCharityTable.write.maximum}
        usage: ${self:custom.customCapacities.${self:provider.stage}.vcDonationByCharityTable.write.usage}
    - table: userRevenueLogTable
      read:
        minimum: ${self:custom.customCapacities.${self:provider.stage}.userRevenueLogTable.read.minimum}
        maximum: ${self:custom.customCapacities.${self:provider.stage}.userRevenueLogTable.read.maximum}
        usage: ${self:custom.customCapacities.${self:provider.stage}.userRevenueLogTable.read.usage}
      write:
        minimum: ${self:custom.customCapacities.${self:provider.stage}.userRevenueLogTable.write.minimum}
        maximum: ${self:custom.customCapacities.${self:provider.stage}.userRevenueLogTable.write.maximum}
        usage: ${self:custom.customCapacities.${self:provider.stage}.userRevenueLogTable.write.usage}
    - table: videoAdLogTable
      index:
            - VideoAdLogsByUniqueId
            - VideoAdLogsByEngagementId
      read:
        minimum: ${self:custom.customCapacities.${self:provider.stage}.videoAdLogTable.read.minimum}
        maximum: ${self:custom.customCapacities.${self:provider.stage}.videoAdLogTable.read.maximum}
        usage: ${self:custom.customCapacities.${self:provider.stage}.videoAdLogTable.read.usage}
      write:
        minimum: ${self:custom.customCapacities.${self:provider.stage}.videoAdLogTable.write.minimum}
        maximum: ${self:custom.customCapacities.${self:provider.stage}.videoAdLogTable.write.maximum}
        usage: ${self:custom.customCapacities.${self:provider.stage}.videoAdLogTable.write.usage}
    - table: userDataConsentLogTable
      read:
        minimum: ${self:custom.customCapacities.${self:provider.stage}.userDataConsentLogTable.read.minimum}
        maximum: ${self:custom.customCapacities.${self:provider.stage}.userDataConsentLogTable.read.maximum}
        usage: ${self:custom.customCapacities.${self:provider.stage}.userDataConsentLogTable.read.usage}
      write:
        minimum: ${self:custom.customCapacities.${self:provider.stage}.userDataConsentLogTable.write.minimum}
        maximum: ${self:custom.customCapacities.${self:provider.stage}.userDataConsentLogTable.write.maximum}
        usage: ${self:custom.customCapacities.${self:provider.stage}.userDataConsentLogTable.write.usage}
    - table: backgroundImagesTable
      index:
          - ImagesByCategory
      read:
        minimum: ${self:custom.customCapacities.${self:provider.stage}.backgroundImagesTable.read.minimum}
        maximum: ${self:custom.customCapacities.${self:provider.stage}.backgroundImagesTable.read.maximum}
        usage: ${self:custom.customCapacities.${self:provider.stage}.backgroundImagesTable.read.usage}
      write:
        minimum: ${self:custom.customCapacities.${self:provider.stage}.backgroundImagesTable.write.minimum}
        maximum: ${self:custom.customCapacities.${self:provider.stage}.backgroundImagesTable.write.maximum}
        usage: ${self:custom.customCapacities.${self:provider.stage}.backgroundImagesTable.write.usage}
    - table: userWidgetsTable
      index:
        - Widgets
      read:
        minimum: ${self:custom.customCapacities.${self:provider.stage}.userWidgetsTable.read.minimum}
        maximum: ${self:custom.customCapacities.${self:provider.stage}.userWidgetsTable.read.maximum}
        usage: ${self:custom.customCapacities.${self:provider.stage}.userWidgetsTable.read.usage}
      write:
        minimum: ${self:custom.customCapacities.${self:provider.stage}.userWidgetsTable.write.minimum}
        maximum: ${self:custom.customCapacities.${self:provider.stage}.userWidgetsTable.write.maximum}
        usage: ${self:custom.customCapacities.${self:provider.stage}.userWidgetsTable.write.usage}
    - table: userTabsLogTable
      read:
        minimum: ${self:custom.customCapacities.${self:provider.stage}.userTabsLogTable.read.minimum}
        maximum: ${self:custom.customCapacities.${self:provider.stage}.userTabsLogTable.read.maximum}
        usage: ${self:custom.customCapacities.${self:provider.stage}.userTabsLogTable.read.usage}
      write:
        minimum: ${self:custom.customCapacities.${self:provider.stage}.userTabsLogTable.write.minimum}
        maximum: ${self:custom.customCapacities.${self:provider.stage}.userTabsLogTable.write.maximum}
        usage: ${self:custom.customCapacities.${self:provider.stage}.userTabsLogTable.write.usage}
    - table: userSearchLogTable
      read:
        minimum: ${self:custom.customCapacities.${self:provider.stage}.userSearchLogTable.read.minimum}
        maximum: ${self:custom.customCapacities.${self:provider.stage}.userSearchLogTable.read.maximum}
        usage: ${self:custom.customCapacities.${self:provider.stage}.userSearchLogTable.read.usage}
      write:
        minimum: ${self:custom.customCapacities.${self:provider.stage}.userSearchLogTable.write.minimum}
        maximum: ${self:custom.customCapacities.${self:provider.stage}.userSearchLogTable.write.maximum}
        usage: ${self:custom.customCapacities.${self:provider.stage}.userSearchLogTable.write.usage}
    - table: referralDataLogTable
      index:
        - ReferralsByReferrer
      read:
        minimum: ${self:custom.customCapacities.${self:provider.stage}.referralDataLogTable.read.minimum}
        maximum: ${self:custom.customCapacities.${self:provider.stage}.referralDataLogTable.read.maximum}
        usage: ${self:custom.customCapacities.${self:provider.stage}.referralDataLogTable.read.usage}
      write:
        minimum: ${self:custom.customCapacities.${self:provider.stage}.referralDataLogTable.write.minimum}
        maximum: ${self:custom.customCapacities.${self:provider.stage}.referralDataLogTable.write.maximum}
        usage: ${self:custom.customCapacities.${self:provider.stage}.referralDataLogTable.write.usage}
    - table: referralLinkClickLog
      read:
        minimum: ${self:custom.customCapacities.${self:provider.stage}.referralLinkClickLog.read.minimum}
        maximum: ${self:custom.customCapacities.${self:provider.stage}.referralLinkClickLog.read.maximum}
        usage: ${self:custom.customCapacities.${self:provider.stage}.referralLinkClickLog.read.usage}
      write:
        minimum: ${self:custom.customCapacities.${self:provider.stage}.referralLinkClickLog.write.minimum}
        maximum: ${self:custom.customCapacities.${self:provider.stage}.referralLinkClickLog.write.maximum}
        usage: ${self:custom.customCapacities.${self:provider.stage}.referralLinkClickLog.write.usage}
    - table: causeTable
      read:
        minimum: ${self:custom.customCapacities.${self:provider.stage}.causeTable.read.minimum}
        maximum: ${self:custom.customCapacities.${self:provider.stage}.causeTable.read.maximum}
        usage: ${self:custom.customCapacities.${self:provider.stage}.causeTable.read.usage}
      write:
        minimum: ${self:custom.customCapacities.${self:provider.stage}.causeTable.write.minimum}
        maximum: ${self:custom.customCapacities.${self:provider.stage}.causeTable.write.maximum}
        usage: ${self:custom.customCapacities.${self:provider.stage}.causeTable.write.usage}
    - table: userSwitchSearchPromptLogTable
      read:
        minimum: ${self:custom.customCapacities.${self:provider.stage}.userSwitchSearchPromptLogTable.read.minimum}
        maximum: ${self:custom.customCapacities.${self:provider.stage}.userSwitchSearchPromptLogTable.read.maximum}
        usage: ${self:custom.customCapacities.${self:provider.stage}.userSwitchSearchPromptLogTable.read.usage}
      write:
        minimum: ${self:custom.customCapacities.${self:provider.stage}.userSwitchSearchPromptLogTable.write.minimum}
        maximum: ${self:custom.customCapacities.${self:provider.stage}.userSwitchSearchPromptLogTable.write.maximum}
        usage: ${self:custom.customCapacities.${self:provider.stage}.userSwitchSearchPromptLogTable.write.usage}
    - table: userSearchSettingsLogTable
      read:
        minimum: ${self:custom.customCapacities.${self:provider.stage}.userSearchSettingsLogTable.read.minimum}
        maximum: ${self:custom.customCapacities.${self:provider.stage}.userSearchSettingsLogTable.read.maximum}
        usage: ${self:custom.customCapacities.${self:provider.stage}.userSearchSettingsLogTable.read.usage}
      write:
        minimum: ${self:custom.customCapacities.${self:provider.stage}.userSearchSettingsLogTable.write.minimum}
        maximum: ${self:custom.customCapacities.${self:provider.stage}.userSearchSettingsLogTable.write.maximum}
        usage: ${self:custom.customCapacities.${self:provider.stage}.userSearchSettingsLogTable.write.usage}
    - table: userExperimentTable
      read:
        minimum: ${self:custom.customCapacities.${self:provider.stage}.userExperimentTable.read.minimum}
        maximum: ${self:custom.customCapacities.${self:provider.stage}.userExperimentTable.read.maximum}
        usage: ${self:custom.customCapacities.${self:provider.stage}.userExperimentTable.read.usage}
      write:
        minimum: ${self:custom.customCapacities.${self:provider.stage}.userExperimentTable.write.minimum}
        maximum: ${self:custom.customCapacities.${self:provider.stage}.userExperimentTable.write.maximum}
        usage: ${self:custom.customCapacities.${self:provider.stage}.userExperimentTable.write.usage}
    - table: userEventLogTable
      read:
        minimum: ${self:custom.customCapacities.${self:provider.stage}.userEventLogTable.read.minimum}
        maximum: ${self:custom.customCapacities.${self:provider.stage}.userEventLogTable.read.maximum}
        usage: ${self:custom.customCapacities.${self:provider.stage}.userEventLogTable.read.usage}
      write:
        minimum: ${self:custom.customCapacities.${self:provider.stage}.userEventLogTable.write.minimum}
        maximum: ${self:custom.customCapacities.${self:provider.stage}.userEventLogTable.write.maximum}
        usage: ${self:custom.customCapacities.${self:provider.stage}.userEventLogTable.write.usage}
    - table: userGroupImpactMetricLogTable
      index:
        - UserGroupImpactMetricLogByUser
      read:
        minimum: ${self:custom.customCapacities.${self:provider.stage}.userGroupImpactMetricLogTable.read.minimum}
        maximum: ${self:custom.customCapacities.${self:provider.stage}.userGroupImpactMetricLogTable.read.maximum}
        usage: ${self:custom.customCapacities.${self:provider.stage}.userGroupImpactMetricLogTable.read.usage}
      write:
        minimum: ${self:custom.customCapacities.${self:provider.stage}.userGroupImpactMetricLogTable.write.minimum}
        maximum: ${self:custom.customCapacities.${self:provider.stage}.userGroupImpactMetricLogTable.write.maximum}
        usage: ${self:custom.customCapacities.${self:provider.stage}.userGroupImpactMetricLogTable.write.usage}
    
resources:
  Resources:

    usersTable:  
      Type: AWS::DynamoDB::Table
      DeletionPolicy: Retain
      UpdateReplacePolicy: Retain
      Properties:  
        TableName: Users-${self:provider.stage}
        KeySchema:
          - AttributeName: id
            KeyType: HASH
        AttributeDefinitions:
          - AttributeName: id
            AttributeType: S
          - AttributeName: username
            AttributeType: S
          - AttributeName: email
            AttributeType: S
        GlobalSecondaryIndexes:
          - IndexName: UsersByUsername
            KeySchema:
              - AttributeName: username
                KeyType: HASH
            Projection:
              ProjectionType: ALL
            ProvisionedThroughput:
              ReadCapacityUnits: 1
              WriteCapacityUnits: 1
          - IndexName: UsersByEmail
            KeySchema:
              - AttributeName: email
                KeyType: HASH
            Projection:
              ProjectionType: KEYS_ONLY
            ProvisionedThroughput:
              ReadCapacityUnits: 1
              WriteCapacityUnits: 1
        ProvisionedThroughput:
          ReadCapacityUnits: 1
          WriteCapacityUnits: 1
        ### Manually set in AWS Console. 
        # StreamSpecification:
        #   StreamViewType: NEW_AND_OLD_IMAGES

    charitiesTable:  
      Type: AWS::DynamoDB::Table
      DeletionPolicy: Retain
      UpdateReplacePolicy: Retain
      Properties:  
        TableName: Charities-${self:provider.stage}
        KeySchema:
          - AttributeName: id
            KeyType: HASH
        AttributeDefinitions:
          - AttributeName: id
            AttributeType: S
        ProvisionedThroughput:
          ReadCapacityUnits: 1
          WriteCapacityUnits: 1
        StreamSpecification:
          StreamViewType: NEW_AND_OLD_IMAGES

    userImpactTable:  
      Type: AWS::DynamoDB::Table
      DeletionPolicy: Retain
      UpdateReplacePolicy: Retain
      Properties:  
        TableName: UserImpact-${self:provider.stage}
        KeySchema:
          - AttributeName: userId
            KeyType: HASH
          - AttributeName: charityId
            KeyType: RANGE
        AttributeDefinitions:
          - AttributeName: userId
            AttributeType: S
          - AttributeName: charityId
            AttributeType: S
        ProvisionedThroughput:
          ReadCapacityUnits: 1
          WriteCapacityUnits: 1
        ### Manually set in AWS Console. 
        # StreamSpecification:
        #   StreamViewType: NEW_AND_OLD_IMAGES

    invitedUsersTable:  
      Type: AWS::DynamoDB::Table
      DeletionPolicy: Retain
      UpdateReplacePolicy: Retain
      Properties:  
        TableName: InvitedUsers-${self:provider.stage}
        KeySchema:
          - AttributeName: inviterId
            KeyType: HASH
          - AttributeName: invitedEmail
            KeyType: RANGE
        AttributeDefinitions:
          - AttributeName: inviterId
            AttributeType: S
          - AttributeName: invitedEmail
            AttributeType: S
          - AttributeName: created
            AttributeType: S
        GlobalSecondaryIndexes:
          - IndexName: InvitesByInviter
            KeySchema:
              - AttributeName: inviterId
                KeyType: HASH
              - AttributeName: created
                KeyType: RANGE
            Projection:
              ProjectionType: ALL
            ProvisionedThroughput:
              ReadCapacityUnits: 1
              WriteCapacityUnits: 1
          - IndexName: InvitesByInvitedEmail
            KeySchema:
              - AttributeName: invitedEmail
                KeyType: HASH
              - AttributeName: created
                KeyType: RANGE
            Projection:
              ProjectionType: KEYS_ONLY
            ProvisionedThroughput:
              ReadCapacityUnits: 1
              WriteCapacityUnits: 1
        ProvisionedThroughput:
          ReadCapacityUnits: 1
          WriteCapacityUnits: 1
        StreamSpecification:
          StreamViewType: NEW_AND_OLD_IMAGES

    missionsTable:  
      Type: AWS::DynamoDB::Table
      DeletionPolicy: Retain
      UpdateReplacePolicy: Retain
      Properties:  
        TableName: Missions-${self:provider.stage}
        KeySchema:
          - AttributeName: id
            KeyType: HASH
        AttributeDefinitions:
          - AttributeName: id
            AttributeType: S
        ProvisionedThroughput:
          ReadCapacityUnits: 1
          WriteCapacityUnits: 1
        StreamSpecification:
          StreamViewType: NEW_AND_OLD_IMAGES

    userMissionsTable:  
      Type: AWS::DynamoDB::Table
      DeletionPolicy: Retain
      UpdateReplacePolicy: Retain
      Properties:  
        TableName: UserMissions-${self:provider.stage}
        KeySchema:
          - AttributeName: missionId
            KeyType: HASH
          - AttributeName: userId
            KeyType: RANGE
        AttributeDefinitions:
          - AttributeName: userId
            AttributeType: S
          - AttributeName: missionId
            AttributeType: S
          - AttributeName: created
            AttributeType: S
        GlobalSecondaryIndexes:
          - IndexName: userMissionsByDate
            KeySchema:
              - AttributeName: userId
                KeyType: HASH
              - AttributeName: created
                KeyType: RANGE
            Projection:
              ProjectionType: ALL
            ProvisionedThroughput:
              ReadCapacityUnits: 1
              WriteCapacityUnits: 1
        ProvisionedThroughput:
          ReadCapacityUnits: 1
          WriteCapacityUnits: 1
        StreamSpecification:
          StreamViewType: NEW_AND_OLD_IMAGES

    widgetsTable:  
      Type: AWS::DynamoDB::Table
      DeletionPolicy: Retain
      UpdateReplacePolicy: Retain
      Properties:  
        TableName: Widgets-${self:provider.stage}
        KeySchema:
          - AttributeName: id
            KeyType: HASH
        AttributeDefinitions:
          - AttributeName: id
            AttributeType: S
        ProvisionedThroughput:
          ReadCapacityUnits: 1
          WriteCapacityUnits: 1
        StreamSpecification:
          StreamViewType: NEW_AND_OLD_IMAGES

    userLevelsTable:  
      Type: AWS::DynamoDB::Table
      DeletionPolicy: Retain
      UpdateReplacePolicy: Retain
      Properties:  
        TableName: UserLevels-${self:provider.stage}
        KeySchema:
          - AttributeName: id
            KeyType: HASH
        AttributeDefinitions:
          - AttributeName: id
            AttributeType: N
        ProvisionedThroughput:
          ReadCapacityUnits: 1
          WriteCapacityUnits: 1
        StreamSpecification:
          StreamViewType: NEW_AND_OLD_IMAGES

    vcDonationLogTable:  
      Type: AWS::DynamoDB::Table
      DeletionPolicy: Retain
      UpdateReplacePolicy: Retain
      Properties:  
        TableName: VcDonationLog-${self:provider.stage}
        KeySchema:
          - AttributeName: userId
            KeyType: HASH
          - AttributeName: timestamp
            KeyType: RANGE
        AttributeDefinitions:
          - AttributeName: userId
            AttributeType: S
          - AttributeName: timestamp
            AttributeType: S
        ProvisionedThroughput:
          ReadCapacityUnits: 1
          WriteCapacityUnits: 1
        ### Manually set in AWS Console. 
        # StreamSpecification:
        #   StreamViewType: NEW_AND_OLD_IMAGES

    vcDonationByCharityTable:  
      Type: AWS::DynamoDB::Table
      DeletionPolicy: Retain
      UpdateReplacePolicy: Retain
      Properties:  
        TableName: VcDonationByCharity-${self:provider.stage}
        KeySchema:
          - AttributeName: charityId
            KeyType: HASH
          - AttributeName: timestamp
            KeyType: RANGE
        AttributeDefinitions:
          - AttributeName: charityId
            AttributeType: S
          - AttributeName: timestamp
            AttributeType: S
        ProvisionedThroughput:
          ReadCapacityUnits: 1
          WriteCapacityUnits: 1
        StreamSpecification:
          StreamViewType: NEW_AND_OLD_IMAGES

    userRevenueLogTable:  
      Type: AWS::DynamoDB::Table
      DeletionPolicy: Retain
      UpdateReplacePolicy: Retain
      Properties:  
        TableName: UserRevenueLog-${self:provider.stage}
        KeySchema:
          - AttributeName: userId
            KeyType: HASH
          - AttributeName: timestamp
            KeyType: RANGE
        AttributeDefinitions:
          - AttributeName: userId
            AttributeType: S
          - AttributeName: timestamp
            AttributeType: S
        ProvisionedThroughput:
          ReadCapacityUnits: 1
          WriteCapacityUnits: 1
        ### Manually set in AWS Console. 
        # StreamSpecification:
        #   StreamViewType: NEW_AND_OLD_IMAGES

    videoAdLogTable:  
      Type: AWS::DynamoDB::Table
      DeletionPolicy: Retain
      UpdateReplacePolicy: Retain
      Properties:  
        TableName: VideoAdLog-${self:provider.stage}
        KeySchema:
          - AttributeName: userId
            KeyType: HASH
          - AttributeName: timestamp
            KeyType: RANGE
        AttributeDefinitions:
          - AttributeName: userId
            AttributeType: S
          - AttributeName: timestamp
            AttributeType: S
          - AttributeName: id
            AttributeType: S
          - AttributeName: truexEngagementId
            AttributeType: S
        ProvisionedThroughput:
          ReadCapacityUnits: 1
          WriteCapacityUnits: 1
        ### Manually set in AWS Console. 
        # StreamSpecification:
        #   StreamViewType: NEW_AND_OLD_IMAGES
        GlobalSecondaryIndexes:
          - IndexName: VideoAdLogsByUniqueId
            KeySchema:
              - AttributeName: id
                KeyType: HASH
            Projection:
              ProjectionType: ALL
            ProvisionedThroughput:
              ReadCapacityUnits: 1
              WriteCapacityUnits: 1
          - IndexName: VideoAdLogsByEngagementId
            KeySchema:
              - AttributeName: truexEngagementId
                KeyType: HASH
            Projection:
              ProjectionType: ALL
            ProvisionedThroughput:
              ReadCapacityUnits: 1
              WriteCapacityUnits: 1
  
    userDataConsentLogTable:  
      Type: AWS::DynamoDB::Table
      DeletionPolicy: Retain
      UpdateReplacePolicy: Retain
      Properties:  
        TableName: UserDataConsentLog-${self:provider.stage}
        KeySchema:
          - AttributeName: userId
            KeyType: HASH
          - AttributeName: timestamp
            KeyType: RANGE
        AttributeDefinitions:
          - AttributeName: userId
            AttributeType: S
          - AttributeName: timestamp
            AttributeType: S
        ProvisionedThroughput:
          ReadCapacityUnits: 1
          WriteCapacityUnits: 1
        StreamSpecification:
          StreamViewType: NEW_AND_OLD_IMAGES

    backgroundImagesTable:  
      Type: AWS::DynamoDB::Table
      DeletionPolicy: Retain
      UpdateReplacePolicy: Retain
      Properties:  
        TableName: BackgroundImages-${self:provider.stage}
        KeySchema:
          - AttributeName: id
            KeyType: HASH
        AttributeDefinitions:
          - AttributeName: id
            AttributeType: S
          - AttributeName: category
            AttributeType: S
        ProvisionedThroughput:
          ReadCapacityUnits: 1
          WriteCapacityUnits: 1
        StreamSpecification:
          StreamViewType: NEW_AND_OLD_IMAGES
        GlobalSecondaryIndexes:
          - IndexName: ImagesByCategory
            KeySchema:
              - AttributeName: category
                KeyType: HASH
            Projection:
              ProjectionType: ALL
            ProvisionedThroughput:
              ReadCapacityUnits: 1
              WriteCapacityUnits: 1

    userWidgetsTable:  
      Type: AWS::DynamoDB::Table
      DeletionPolicy: Retain
      UpdateReplacePolicy: Retain
      Properties:  
        TableName: UserWidgets-${self:provider.stage}
        KeySchema:
          - AttributeName: userId
            KeyType: HASH
          - AttributeName: widgetId
            KeyType: RANGE
        AttributeDefinitions:
          - AttributeName: userId
            AttributeType: S
          - AttributeName: widgetId
            AttributeType: S
        GlobalSecondaryIndexes:
          - IndexName: Widgets
            KeySchema:
              - AttributeName: userId
                KeyType: HASH
            Projection:
              ProjectionType: ALL
            ProvisionedThroughput:
              ReadCapacityUnits: 1
              WriteCapacityUnits: 1
        ProvisionedThroughput:
          ReadCapacityUnits: 1
          WriteCapacityUnits: 1
        StreamSpecification:
          StreamViewType: NEW_AND_OLD_IMAGES

    userTabsLogTable:  
      Type: AWS::DynamoDB::Table
      DeletionPolicy: Retain
      UpdateReplacePolicy: Retain
      Properties:  
        TableName: UserTabsLog-${self:provider.stage}
        KeySchema:
          - AttributeName: userId
            KeyType: HASH
          - AttributeName: timestamp
            KeyType: RANGE
        AttributeDefinitions:
          - AttributeName: userId
            AttributeType: S
          - AttributeName: timestamp
            AttributeType: S
        ProvisionedThroughput:
          ReadCapacityUnits: 1
          WriteCapacityUnits: 1
        ### Manually set in AWS Console. 
        # StreamSpecification:
        #   StreamViewType: NEW_AND_OLD_IMAGES

    userSearchLogTable:  
      Type: AWS::DynamoDB::Table
      DeletionPolicy: Retain
      UpdateReplacePolicy: Retain
      Properties:  
        TableName: UserSearchLog-${self:provider.stage}
        KeySchema:
          - AttributeName: userId
            KeyType: HASH
          - AttributeName: timestamp
            KeyType: RANGE
        AttributeDefinitions:
          - AttributeName: userId
            AttributeType: S
          - AttributeName: timestamp
            AttributeType: S
        ProvisionedThroughput:
          ReadCapacityUnits: 1
          WriteCapacityUnits: 1
        ### Manually set in AWS Console. 
        # StreamSpecification:
        #   StreamViewType: NEW_AND_OLD_IMAGES

    referralDataLogTable:  
      Type: AWS::DynamoDB::Table
      DeletionPolicy: Retain
      UpdateReplacePolicy: Retain
      Properties:  
        TableName: ReferralDataLog-${self:provider.stage}
        KeySchema:
          - AttributeName: userId
            KeyType: HASH
        AttributeDefinitions:
          - AttributeName: userId
            AttributeType: S
          - AttributeName: referringUser
            AttributeType: S
          - AttributeName: created
            AttributeType: S
        GlobalSecondaryIndexes:
          - IndexName: ReferralsByReferrer
            KeySchema:
              - AttributeName: referringUser
                KeyType: HASH
              - AttributeName: created
                KeyType: RANGE
            Projection:
              ProjectionType: ALL
            ProvisionedThroughput:
              ReadCapacityUnits: 1
              WriteCapacityUnits: 1
        ProvisionedThroughput:
          ReadCapacityUnits: 1
          WriteCapacityUnits: 1
        ### Manually set in AWS Console. 
        # StreamSpecification:
        #   StreamViewType: NEW_AND_OLD_IMAGES

    referralLinkClickLog:  
      Type: AWS::DynamoDB::Table
      DeletionPolicy: Retain
      UpdateReplacePolicy: Retain
      Properties:  
        TableName: ReferralLinkClickLog-${self:provider.stage}
        KeySchema:
          - AttributeName: userId
            KeyType: HASH
          - AttributeName: timestamp
            KeyType: RANGE
        AttributeDefinitions:
          - AttributeName: userId
            AttributeType: S
          - AttributeName: timestamp
            AttributeType: S
        ProvisionedThroughput:
          ReadCapacityUnits: 1
          WriteCapacityUnits: 1
        StreamSpecification:
          StreamViewType: NEW_AND_OLD_IMAGES

    # TODO: remove and delete tables
    causeTable:  
      Type: AWS::DynamoDB::Table
      DeletionPolicy: Retain
      UpdateReplacePolicy: Retain
      Properties:  
        TableName: Causes-${self:provider.stage}
        KeySchema:
          - AttributeName: id
            KeyType: HASH
        AttributeDefinitions:
          - AttributeName: id
            AttributeType: S
        ProvisionedThroughput:
          ReadCapacityUnits: 1
          WriteCapacityUnits: 1
        StreamSpecification:
          StreamViewType: NEW_AND_OLD_IMAGES

    userSwitchSearchPromptLogTable:
      Type: AWS::DynamoDB::Table
      DeletionPolicy: Retain
      UpdateReplacePolicy: Retain
      Properties:    
        TableName: UserSwitchSearchPromptLog-${self:provider.stage}
        KeySchema:
          - AttributeName: userId
            KeyType: HASH
          - AttributeName: timestamp
            KeyType: RANGE
        AttributeDefinitions:
          - AttributeName: userId
            AttributeType: S
          - AttributeName: timestamp
            AttributeType: S
        ProvisionedThroughput:
          ReadCapacityUnits: 1
          WriteCapacityUnits: 1
        StreamSpecification:
          StreamViewType: NEW_AND_OLD_IMAGES
    
    userSearchSettingsLogTable:  
      Type: AWS::DynamoDB::Table
      DeletionPolicy: Retain
      UpdateReplacePolicy: Retain
      Properties:  
        TableName: UserSearchSettingsLog-${self:provider.stage}
        KeySchema:
          - AttributeName: userId
            KeyType: HASH
          - AttributeName: timestamp
            KeyType: RANGE
        AttributeDefinitions:
          - AttributeName: userId
            AttributeType: S
          - AttributeName: timestamp
            AttributeType: S
        ProvisionedThroughput:
          ReadCapacityUnits: 1
          WriteCapacityUnits: 1
        StreamSpecification:
          StreamViewType: NEW_AND_OLD_IMAGES

    userExperimentTable:  
      Type: AWS::DynamoDB::Table
      DeletionPolicy: Retain
      UpdateReplacePolicy: Retain
      Properties:  
        TableName: UserExperiment-${self:provider.stage}
        KeySchema:
          - AttributeName: userId
            KeyType: HASH
          - AttributeName: experimentId
            KeyType: RANGE
        AttributeDefinitions:
          - AttributeName: userId
            AttributeType: S
          - AttributeName: experimentId
            AttributeType: S
        ProvisionedThroughput:
          ReadCapacityUnits: 1
          WriteCapacityUnits: 1
        StreamSpecification:
          StreamViewType: NEW_AND_OLD_IMAGES
    
    userEventLogTable:  
      Type: AWS::DynamoDB::Table
      DeletionPolicy: Retain
      UpdateReplacePolicy: Retain
      Properties:  
        TableName: UserEventLog-${self:provider.stage}
        KeySchema:
          - AttributeName: id
            KeyType: HASH
        AttributeDefinitions:
          - AttributeName: id
            AttributeType: S
        ProvisionedThroughput:
          ReadCapacityUnits: 1
          WriteCapacityUnits: 1
        StreamSpecification:
          StreamViewType: NEW_AND_OLD_IMAGES

    userGroupImpactMetricLogTable:  
      Type: AWS::DynamoDB::Table
      DeletionPolicy: Retain
      UpdateReplacePolicy: Retain
      Properties:  
        TableName: UserGroupImpactMetricLog-${self:provider.stage}
        KeySchema:
          - AttributeName: userId
            KeyType: HASH
        AttributeDefinitions:
          - AttributeName: userId
            AttributeType: S
          - AttributeName: dateStarted
            AttributeType: S
        GlobalSecondaryIndexes:
          - IndexName: UserGroupImpactMetricLogByUser
            KeySchema:
              - AttributeName: userId
                KeyType: HASH
              - AttributeName: dateStarted
                KeyType: RANGE
            Projection:
              ProjectionType: ALL
            ProvisionedThroughput:
              ReadCapacityUnits: 1
              WriteCapacityUnits: 1
        ProvisionedThroughput:
          ReadCapacityUnits: 1
          WriteCapacityUnits: 1
        StreamSpecification:
          StreamViewType: NEW_AND_OLD_IMAGES