Skip to content

Instantly share code, notes, and snippets.

@brianneisler
Last active December 18, 2018 20:41
Show Gist options
  • Save brianneisler/ba0c96cfdbedf858acc0a10bca4b049f to your computer and use it in GitHub Desktop.
Save brianneisler/ba0c96cfdbedf858acc0a10bca4b049f to your computer and use it in GitHub Desktop.

Single service that processes an image when added to a bucket

name: ImageProcessor
extends: Service

providers:
  aws:
    type: AWSProvider
    inputs:
      credentials:
        accessKey: ...
        secretAccessKey: ...

compute:
  lambda:
    type: AWSLambdaCompute
    inputs:
      runtime: node@8.11
      provider: ${this.providers.aws}

functions:
  resizeImage:
    compute: ${this.compute.lambda}
    handler: index.resizeImage
    code: ./resizer
    events:
      - source: ${this.components.bucket}
        config:
          event: s3:ObjectCreated:*

components:
  bucket:
    type: AwsS3Bucket
    inputs:
      name: my-images-{$this.instanceId}

Single service that connects to a RestApi

name: UsersService
extends: Service

providers:
  aws:
    type: AWSProvider
    inputs:
      credentials:
        accessKey: ...
        secretAccessKey: ...

compute:
  type: AWSLambdaCompute
  inputs:
    runtime: node@8.11
    provider: ${this.providers.aws}

functions:
  createUser:
    compute: ${this.compute.lambda}
    handler: index.createUser
    code: ./crud
    events:
      - source: ${this.components.restApi}
        config:
          path: users/create
          method: post
          cors: true
  getUser:
    compute: ${this.compute.lambda}
    handler: index.getUser
    code: ./crud
    events:
      - source: ${this.components.restApi}
        config:
          path: users/{id}
          method: get
          cors: true
  updateUser:
    compute: ${this.compute.lambda}
    handler: index.updateUser
    code: ./crud
    events:
      - source: ${this.components.restApi}
        config:
          path: users/{id}
          method: put
          cors: true
  deleteUser:
    compute: ${this.compute.lambda}
    handler: index.deleteUser
    code: ./crud
    events:
      - source: ${this.components.restApi}
        config:
          path: users/{id}
          method: post
          cors: true

components:
  restApi:
    type: RestApi
    inputs:
      provider: ${this.providers.aws}
      apiName: users-api-${this.instanceId}

Single service that runs a task on cron

name: ScheduledLogCleanup
extends: Service

providers:
  aws:
    type: AWSProvider
    inputs:
      credentials:
        accessKey: ...
        secretAccessKey: ...

compute:
  type: AWSLambdaCompute
  inputs:
    runtime: node@8.11
    provider: ${this.providers.aws}

functions:
  cleanupLogs:
    compute: ${this.compute.lambda}
    handler: index.cleanupLogs
    code: ./cleanup
    events:
      - source: ${this.components.cron}
        config:
          schedule: rate(1 minute)

components:
  cron:
    type: Cron
    inputs:
      provider: ${this.providers.aws}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment