service: users

frameworkVersion: ^3

useDotenv: true

plugins:
  - serverless-plugin-typescript
  - serverless-plugin-reducer
  - serverless-offline-sqs
  - serverless-offline
  - serverless-deployment-bucket

package:
  individually: true

custom:
  serverless-offline:
    useSeparateProcesses: true
  serverless-offline-sqs:
    autoCreate: true
    apiVersion: '2012-11-05'
    endpoint: http://0.0.0.0:${env:ELASTICMQ_PORT1, 9324}
    region: eu-west-1
    accessKeyId: root
    secretAccessKey: root
    skipCacheInvalidation: false
  serverlessPluginTypescript:
    tsConfigFileLocation: ./tsconfig.build.json
  reducer:
    ignoreMissing: true
  deploymentBucket:
    accelerate: true
    blockPublicAccess: true
  vpc:
    dev:
      subnetIds:
        - 'subnet-00000000000'
      securityGroupIds:
        - 'sg-00000000000'
    stag:
      securityGroupIds:
        - 'sg-07d31f2373171b934'
      subnetIds:
        - 'subnet-032db4bf3fa9ab23e'
        - 'subnet-04439c6de67711ecc'
    prod:
      securityGroupIds:
        - 'sg-00a0dad2894f0a02b'
      subnetIds:
        - 'subnet-090a5d5c84bdd0245'
        - 'subnet-0f27623377e412768'
        - 'subnet-0b6652e22ce5ac1a1'
        - 'subnet-0d0937775080e7907'

provider:
  name: aws
  runtime: nodejs14.x
  stage: ${opt:stage, 'dev'}
  memorySize: 512
  versionFunctions: false
  deploymentBucket:
    name: users-${self:provider.stage}-serverlessdeploymentbucket
  iam:
    role:
      statements:
        - Effect: 'Allow'
          Resource: '*'
          Action:
            - 'sns:publish'
            - 'sns:write'
            - 'sqs:SendMessage'
            - 'secretsmanager:GetSecretValue'
        - Effect: 'Allow'
          Action:
            - 'logs:CreateLogGroup'
            - 'logs:CreateLogStream'
            - 'logs:PutLogEvents'
            - 'logs:DescribeLogGroups'
            - 'logs:DescribeLogStreams'
          Resource: '*'
  apiGateway:
    minimumCompressionSize: 1024
  vpc: '${self:custom.vpc.${self:provider.stage}}'
  environment:
    STAGE: ${self:provider.stage}
    SECRET_ID: my_nutri/${self:provider.stage}
    NOTIFICATIONS_SQS_URL:
      Ref: NotificationsQueue

functions:
  patients:
    handler: src/apps/patients/app.handler
    maximumRetryAttempts: 0
    timeout: 60
    events:
      - http:
          method: any
          path: /patients/{any+}

  patients-notifications:
    handler: src/apps/patients/app.handler
    maximumRetryAttempts: 0
    events:
      - http:
          method: any
          path: /notifications/{any+}

  menus:
    handler: src/apps/menus/app.handler
    maximumRetryAttempts: 0
    events:
      - http:
          method: any
          path: /menus/{any+}

  bioimpedances:
    handler: src/apps/bioimpedances/app.handler
    maximumRetryAttempts: 0
    timeout: 120
    events:
      - http:
          method: any
          path: /bioimpedances/{any+}

  subscriptions:
    handler: src/apps/subscriptions/app.handler
    maximumRetryAttempts: 0
    timeout: 30
    events:
      - http:
          method: any
          path: /subscriptions/{any+}

  plans:
    handler: src/apps/subscriptions/app.handler
    maximumRetryAttempts: 0
    events:
      - http:
          method: any
          path: /plans/{any+}

  teleconsultation-credits:
    handler: src/apps/subscriptions/app.handler
    maximumRetryAttempts: 0
    events:
      - http:
          method: any
          path: /teleconsultation-credits/{any+}

  bookings:
    handler: src/apps/bookings/app.handler
    maximumRetryAttempts: 0
    timeout: 300
    events:
      - http:
          method: any
          path: /bookings/{any+}

  nutritionists:
    handler: src/apps/nutritionists/app.handler
    maximumRetryAttempts: 0
    timeout: 30
    events:
      - http:
          method: any
          path: /nutritionists/{any+}

  remote-config:
    handler: src/apps/remote-config/app.handler
    maximumRetryAttempts: 0
    events:
      - http:
          method: any
          path: /remote-config/{any+}

  notification-sqs:
    handler: src/apps/notification/app.handler
    maximumRetryAttempts: 0
    reservedConcurrency: 1
    events:
      - sqs:
          arn:
            Fn::GetAtt:
              - NotificationsQueue
              - Arn
          batchSize: 10

  notification:
    handler: src/apps/notification/app.handler
    maximumRetryAttempts: 0
    timeout: 30
    memorySize: 1536
    package:
      patterns:
        - node_modules/chrome-aws-lambda
    events:
      - http:
          method: any
          path: /notification/{any+}

  measurement-totem:
    handler: src/apps/measurement-totem/app.handler
    maximumRetryAttempts: 0
    events:
      - http:
          method: any
          cors: true
          path: /measurement-totem/{any+}

  api:
    handler: src/apps/api/app.handler
    maximumRetryAttempts: 0
    vpc: ~
    events:
      - http:
          method: any
          path: /api/{any+}

  video-library:
    handler: src/apps/video-library/app.handler
    maximumRetryAttempts: 0
    timeout: 30
    events:
      - http:
          method: any
          path: /video-library/{any+}

  concilliation:
    handler: src/apps/subscriptions/app.handler
    maximumRetryAttempts: 0
    timeout: 900
    events:
      - http:
          method: any
          path: /concilliation/{any+}

  in-app:
    handler: src/apps/subscriptions/app.handler
    maximumRetryAttempts: 0
    events:
      - http:
          method: any
          path: /in-app/{any+}

  converter-page:
    handler: src/apps/converter-page/app.handler
    maximumRetryAttempts: 0
    events:
      - http:
          method: any
          path: /converter-page/{any+}

  ranking:
    handler: src/apps/ranking/app.handler
    maximumRetryAttempts: 0
    events:
      - http:
          method: any
          path: /ranking/{any+}

  challenge:
    handler: src/apps/challenge/app.handler
    maximumRetryAttempts: 0
    events:
      - http:
          method: any
          path: /challenge/{any+}

  api-payment:
    handler: src/apps/api-payment/app.handler
    maximumRetryAttempts: 0
    timeout: 30
    events:
      - http:
          method: any
          path: /api-payment/{any+}

  contract:
    handler: src/apps/subscriptions/app.handler
    maximumRetryAttempts: 0
    timeout: 900
    events:
      - http:
          method: any
          path: /contract/{any+}

resources:
  Resources:
    NotificationsQueue:
      Type: 'AWS::SQS::Queue'
      Properties:
        QueueName: 'NotificationsQueue-${self:provider.stage}'
