# serverless.yml

service: serverlesssubscriptionplatform

custom:
  entitlementsTableName: 'entitlements-table-${self:provider.stage}'

provider:
  name: aws
  runtime: nodejs12.x
  stage: dev
  region: us-east-1
  iamRoleStatements:
    - Effect: Allow
      Action:
        - dynamodb:Query
        - dynamodb:Scan
        - dynamodb:GetItem
        - dynamodb:PutItem
        - dynamodb:UpdateItem
      Resource:
        - { "Fn::GetAtt": ["EntitlementsDynamoDBTable", "Arn" ] }
  environment:
    ENTITLEMENTS_TABLE: ${self:custom.entitlementsTableName}

functions:
  app:
    handler: index.handler
    events:
      - http: ANY /
      - http: 'ANY {proxy+}'
  login:
    handler: login.handler
    events:
      - http: 'POST /api/login'
  entitlements:
    handler: entitlements.handler
    events:
      - http: 'GET /api/entitlements'
      - http: 'POST /api/entitlements'
      - http: 'GET /api/entitlements/{proxy+}'
      - http: 'PUT /api/entitlements/{proxy+}'
      - http: 'DELETE /api/entitlements/{proxy+}'
  # paywall:
  #   handler: paywall.handler

resources:
  Resources:
    EntitlementsDynamoDBTable:
      Type: 'AWS::DynamoDB::Table'
      Properties:
        AttributeDefinitions:
          -
            AttributeName: userId
            AttributeType: S
        KeySchema:
          -
            AttributeName: userId
            KeyType: HASH
        ProvisionedThroughput:
          ReadCapacityUnits: '5'
          WriteCapacityUnits: '10'
        TableName: ${self:custom.entitlementsTableName}
package:
  exclude:
    - Screenshots/**
   

  # ## Specifying the CloudFront Distribution to server your Web Application
  #   WebAppCloudFrontDistribution:
  #     Type: AWS::CloudFront::Distribution
  #     Properties:
  #       DistributionConfig:
  #         Origins:
  #           - DomainName: www.httpbin.org
  #             ## An identifier for the origin which must be unique within the distribution
  #             Id: WebApp
  #             CustomOriginConfig:
  #               HTTPPort: 80
  #               HTTPSPort: 443
  #               OriginProtocolPolicy: https-only
  #             ## In case you want to restrict the bucket access use S3OriginConfig and remove CustomOriginConfig
  #             # S3OriginConfig:
  #             #   OriginAccessIdentity: origin-access-identity/cloudfront/E127EXAMPLE51Z
  #         Enabled: 'true'
  #         ## Uncomment the following section in case you are using a custom domain
  #         # Aliases:
  #         # - mysite.example.com
  #         DefaultRootObject: index.html
  #         ## Since the Single Page App is taking care of the routing we need to make sure ever path is served with index.html
  #         ## The only exception are files that actually exist e.h. app.js, reset.css
  #         CustomErrorResponses:
  #           - ErrorCode: 404
  #             ResponseCode: 200
  #             ResponsePagePath: /index.html
  #         DefaultCacheBehavior:
  #           AllowedMethods:
  #             - DELETE
  #             - GET
  #             # - HEAD
  #             # - OPTIONS
  #             # - PATCH
  #             - POST
  #             - PUT
  #           ## The origin id defined above
  #           TargetOriginId: WebApp
  #           ## Defining if and how the QueryString and Cookies are forwarded to the origin which in this case is S3
  #           ForwardedValues:
  #             QueryString: 'false'
  #             Cookies:
  #               Forward: none
  #               # Forward: none
  #           ## The protocol that users can use to access the files in the origin. To allow HTTP use `allow-all`
  #           ViewerProtocolPolicy: redirect-to-https
  #         ## The certificate to use when viewers use HTTPS to request objects.
  #         ViewerCertificate:
  #           CloudFrontDefaultCertificate: 'true'
  #         ## Uncomment the following section in case you want to enable logging for CloudFront requests
  #         # Logging:
  #         #   IncludeCookies: 'false'
  #         #   Bucket: mylogs.s3.amazonaws.com
  #         #   Prefix: myprefix

  # ## In order to print out the hosted domain via `serverless info` we need to define the DomainName output for CloudFormation
  # Outputs:
  #   WebAppCloudFrontDistributionOutput:
  #     Value:
  #       'Fn::GetAtt': [ WebAppCloudFrontDistribution, DomainName ]