service: theear-transcode
useDotenv: true
# 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

provider:
  name: aws
  runtime: nodejs12.x
  stage: dev
  region: eu-west-1
  profile: unity
  #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:
        - logs:CreateLogGroup
        - logs:CreateLogStream
        - logs:PutLogEvents
      Resource: "*"
    - Effect: Allow
      Action:
        - s3:ListBucket
      Resource:
        - arn:aws:s3:::the-ear-transcode-video
    - Effect: "Allow"
      Action:
        - s3:PutObject
      Resource:
        - arn:aws:s3:::the-ear-transcode-video/*
    - 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:
  transcode:
    handler: transcode.main
    timeout: 60
    events:
      - s3:
          bucket: the-ear-transcode-video
          event: s3:ObjectCreated:*
          existing: true

# Create our resources with separate CloudFormation templates
#resources:
  # API Gateway Errors
 # - ${file(resources/api-gateway-errors.yml)}