service: theear-resources
# Create an optimized package for our functions
useDotenv: true
package:
  individually: true

plugins:
  - serverless-bundle # Package our functions with Webpack
  - serverless-offline
  - serverless-dotenv-plugin # Load .env as environment variables
custom:
    bucket: the-ear-prod-resources

provider:
  name: aws
  runtime: nodejs12.x
  stage: production
  region: af-south-1
  profile: theear_prod
  vpc:
   securityGroupIds:
     - ${env:SECURITYGROUPIDS}
   subnetIds:
     - ${env:SUBNETIDS1}
     - ${env:SUBNETIDS2}
  memorySize: 512

  # These environment variables are made available to our functions
  # under process.env.
  environment:
    tableName: loging
    databaseHost: ${env:DBHOST}
    databaseUser: ${env:DBUSERNAME}
    databasePass: ${env:DBPASSWORD}
    databaseName: ${env:DBNAME}

  # 'iamRoleStatements' defines the permission policy for the Lambda function.
  # In this case Lambda functions are granted with permissions to access DynamoDB.
  iamRoleStatements:
    - Effect: Allow
      Action:
        - s3:GetObject
        - s3:PutObject
      Resource: arn:aws:s3:::*
    - Effect: Allow
      Action:
        - elastictranscoder:Read*
        - elastictranscoder:List*
        - elastictranscoder:*Job
        - elastictranscoder:*Preset
        - s3:List*
        - iam:List*
        - sns:List*
      Resource: "*"
    - 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: create
          method: post
          cors: true
          authorizer: aws_iam
  sort_files:
    handler: sort_files.main
    events:
      - http:
          path: sort_files
          method: get
          cors: false      
  transcode:  #input
    handler: transcode.main
    timeout: 60
    events:
      - s3:
          bucket: ${self:custom.bucket}
          event: s3:ObjectCreated:*
          existing: true
  # transcode_process:  #input
  #   handler: transcode_process.main
  #   timeout: 60
  #   events:
  #     - s3:
  #         bucket: the-ear-staging-transcode
  #         event: s3:ObjectCreated:*
  #         existing: true        
resources:
  # API Gateway Errors
  - ${file(resources/api-gateway-errors.yml)}