zotoio/github-task-manager

View on GitHub
serverless.yml

Summary

Maintainability
Test Coverage
service: gtmGithubHook
plugins:
  - serverless-webpack
  - serverless-kms-secrets
  - serverless-offline

provider:
  name: aws
  runtime: nodejs8.10
  memorySize: 2048 # optional, in MB, default is 1024
  timeout: 60 # optional, in seconds, default is 6

  stage: ${env:GTM_AWS_STAGE, 'dev'}
  region: ${env:GTM_AWS_REGION}

  environment: ${file(./serverless-aws-environment.yml):environment}

  iamRoleStatements:
    - Effect: Allow
      Action:
        - sqs:SendMessage
      Resource:
        Fn::GetAtt: [ PendingQueue, Arn ]

    - Effect: Allow
      Action:
        - sqs:ReceiveMessage
        - sqs:DeleteMessage
      Resource:
        Fn::GetAtt: [ ResultsQueue, Arn ]

    - Effect: Allow
      Action:
        - dynamodb:UpdateItem
      Resource:
        Fn::GetAtt: [ EventsTable, Arn ]

    - Effect: Allow
      Action:
        - dynamodb:UpdateItem
      Resource:
        Fn::GetAtt: [ AgentsTable, Arn ]


package:
  individually: true
  exclude:
    - ".*/**"

functions:
  gtmGithubHook:
    handler: dist/src/serverless/gtmGithubHook/gtmGithubHook.listener
    environment:
      SQS_PENDING_QUEUE_URL:
        Ref: PendingQueue

    package:
      include:
        - dist/src/serverless/gtmGithubHook/**

    events:
      - http:
          path: gtm-github-hook
          method: post
          cors: true

  gtmGithubResults:
    handler: dist/src/serverless/gtmGithubResults/gtmGithubResults.handle
    environment:
      SQS_RESULTS_QUEUE_URL:
        Ref: ResultsQueue

    package:
      include:
        - dist/src/serverless/gtmGithubResults/**

    events:
      - sns: ${env:GTM_SNS_RESULTS_TOPIC}

  gtmGithubMetricCapture:
    handler: dist/src/serverless/gtmGithubMetricCapture/gtmGithubMetricCapture.handler
    environment:
      DYNAMO_DB_TABLE_EVENTS:
        Ref: EventsTable
      DYNAMO_DB_TABLE_AGENTS:
        Ref: AgentsTable

    package:
      include:
        - dist/src/serverless/gtmGithubMetricCapture/**

    events:
      - cloudwatchLog:
          logGroup: 'gtmAgent'
          filter: '{$.resultType != ""}'

resources:
  Resources:
    PendingQueue:
      Type: AWS::SQS::Queue
      Properties:
        QueueName: ${env:GTM_SQS_PENDING_QUEUE}
        MessageRetentionPeriod: 1209600
        VisibilityTimeout: 7200

    ResultsQueue:
      Type: AWS::SQS::Queue
      Properties:
        QueueName: ${env:GTM_SQS_RESULTS_QUEUE}
        MessageRetentionPeriod: 1209600
        VisibilityTimeout: 7200

    EventsTable:
      Type: AWS::DynamoDB::Table
      Properties:
        TableName: ${env:GTM_DYNAMO_TABLE_EVENTS}
        AttributeDefinitions:
          - AttributeName: ghEventId
            AttributeType: S
        KeySchema:
          - AttributeName: ghEventId
            KeyType: HASH
        ProvisionedThroughput:
          ReadCapacityUnits: 5
          WriteCapacityUnits: 5
        StreamSpecification:
          StreamViewType: NEW_IMAGE

    AgentsTable:
      Type: AWS::DynamoDB::Table
      Properties:
        TableName: ${env:GTM_DYNAMO_TABLE_AGENTS}
        AttributeDefinitions:
          - AttributeName: agentId
            AttributeType: S
        KeySchema:
          - AttributeName: agentId
            KeyType: HASH
        ProvisionedThroughput:
          ReadCapacityUnits: 5
          WriteCapacityUnits: 5
        StreamSpecification:
          StreamViewType: NEW_IMAGE

    GtmS3Bucket:
      Type: AWS::S3::Bucket
      Properties:
        BucketName: ${env:GTM_S3_DEPENDENCY_BUCKET}
            # add additional custom bucket configuration here

#    DynamoVpcEndpoint:
#      Type: AWS::EC2::VPCEndpoint
#      Properties:
#        ServiceName: com.amazonaws.${env:GTM_AWS_REGION}.dynamodb
#        VpcId: ${env:GTM_AWS_VPC_ID}

custom:
  kmsSecrets: ${file(kms-secrets.${opt:stage, self:provider.stage}.${opt:region, self:provider.region}.yml)}