0.2.0 • Published 5 years ago

@serverless/pubsub v0.2.0

Weekly downloads
2
License
Apache
Repository
-
Last release
5 years ago

PubSub

Easily add cross-provider PubSub mappings to your serverless functions using Serverless Components.

Table of Contents

  1. Install
  2. Create
  3. Configure
  4. Deploy

1. Install

$ npm install -g @serverless/components

2. Create

Just create the following simple boilerplate:

$ touch serverless.yml # more info in the "Configure" section below
$ touch index.js       # your lambda code
$ touch .env           # your development AWS api keys
$ touch .env.prod      # your production AWS api keys

the index.js file should look something like this:

module.exports.sendNotification = async (e) => {
  return {
    statusCode: 200,
    body: 'Notification Sent'
  }
}

the .env files are not required if you have the aws keys set globally and you want to use a single stage, but they should look like this.

AWS_ACCESS_KEY_ID=XXX
AWS_SECRET_ACCESS_KEY=XXX

Keep reading for info on how to set up the serverless.yml file.

3. Configure

# serverless.yml

name: subscriptions

createUser:
  component: "@serverless/function"
  inputs:
    name: ${name}-send-notification
    code: ./code
    handler: index.sendNotification

subscriptions:
  component: "@serverless/pubsub"
  inputs:
    - source: userCreated # topic name
      function: ${comp:sendNotification}
   

4. Deploy

pubsub (master)$ components

 

New to Components?

Checkout the Serverless Components repo for more information.