service: ohLief-app-api

# Create an optimized package for our functions
package:
  individually: true

plugins:
  - serverless-bundle # Package our functions with Webpack
  - serverless-offline
  - serverless-dotenv-plugin # Load .env as environment variables

custom:
  # Our stage is based on what is passed in when running serverless
  # commands. Or fallsback to what we have set in the provider section.
  stage: ${opt:stage, self:provider.stage}
  # Set the table name here so we can use it while testing locally
  tableName: ${self:custom.stage}-ohlief


provider:
  name: aws
  runtime: nodejs10.x
  stage: prod
  region: eu-west-1
  profile: ohlief #profile setup

  environment:
    tableName: order
    stripeSecretKey: ${env:STRIPE_SECRET_KEY}

  iamRoleStatements:
    - Effect: Allow
      Action:
        - dynamodb:DescribeTable
        - dynamodb:Query
        - dynamodb:Scan
        - dynamodb:GetItem
        - dynamodb:PutItem
        - dynamodb:UpdateItem
        - dynamodb:DeleteItem
      Resource: "arn:aws:dynamodb:eu-west-1:*:*"

functions:
  create:
    handler: create.main
    events:
      - http:
          path: ohlief
          method: post
          cors: true
          authorizer: aws_iam
  createProduct:
    handler: createProduct.main
    events:
      - http:
          path: createProduct
          method: post
          cors: true
          authorizer: aws_iam
  get:
    handler: get.main
    events:
      - http:
          path: ohlief/{id}
          method: get
          cors: true
          authorizer: aws_iam
  getproduct:
    handler: getproduct.main
    events:
      - http:
          path: getproduct/{id}
          method: get
          cors: true
          authorizer: aws_iam        
  list:
    handler: list.main
    events:
      - http:
          path: ohlief
          method: get
          cors: true
          authorizer: aws_iam
  listinvoices:
    handler: listinvoices.main
    events:
      - http:
          path: listinvoices
          method: get
          cors: true
          authorizer: aws_iam
  listProducts:
    handler: listProducts.main
    events:
      - http:
          path: listProducts
          method: get
          cors: true
          authorizer: aws_iam
  listOrders:
    handler: listOrders.main
    events:
      - http:
          path: listOrders
          method: get
          cors: true
          authorizer: aws_iam
  invoiceupdate:
    handler: invoiceupdate.main
    events:
      - http:
          path: invoiceupdate/{id}
          method: get
          cors: true
          authorizer: aws_iam
  invoicetoftp:
    handler: invoicetoftp.main
    events:
      #- schedule:
      #   rate: rate(1 minute)
      - http:
          path: invoicetoftp/{id}
          method: get
          cors: true
          #authorizer: aws_iam
  update:
    handler: update.main
    events:
      - http:
          path: ohlief/{id}
          method: put
          cors: true
          authorizer: aws_iam
  updateProduct:
    handler: updateProduct.main
    events:
      - http:
          path: updateProduct/{id}
          method: put
          cors: true
          authorizer: aws_iam        
  delete:
    handler: delete.main
    events:
      - http:
          path: ohlief/{id}
          method: delete
          cors: true
          authorizer: aws_iam
  billing:
    handler: billing.main
    events:
      - http:
          path: billing
          method: post
          cors: true
          authorizer: aws_iam
  ftptos3:
    handler: ftptos3.main
    #memorySize: 512 # optional, in MB, default is 1024
    #timeout: 10 # optional, in seconds, default is 6
    events:
      #- schedule:
      #   rate: rate(1 minute)
      - http:
          path: ftptos3
          method: get
          cors: true
          #authorizer: aws_iam
# Create our resources with separate CloudFormation templates
resources:
  # API Gateway Errors
  - ${file(resources/api-gateway-errors.yml)}
 # DynamoDB
  - ${file(resources/dynamodb-table.yml)}
  # S3
  - ${file(resources/s3-bucket.yml)}
  # Cognito
  - ${file(resources/cognito-user-pool.yml)}
  - ${file(resources/cognito-identity-pool.yml)}