trycourier / aws-node-notifications

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Serverless AWS Node Notifications

Powered by Courier

This template demonstrates how to make a simple HTTP API Endpoint with Node.js running on AWS Lambda and API Gateway using the Serverless Framework to send notifications.

Usage

Configuration

  1. Sign up for Courier account.
  2. Install and configure one of the many supported providers:
  3. Grab your Courier API Key from settings.
  4. Set the API Key value in the COURIER_AUTH_TOKEN environment variable.
    • In this example app it's done by storing it in AWS SSM Parameter Store

CORS is enabled by default to allow requests from any origin, so that you can test the application by making requests from any client-side app. You should limit the allowed origins to your own domain when using this on production.

Deployment

$ serverless deploy

After deploying, you should see output similar to:

Deploying aws-node-notifications to stage dev (us-east-1)

✔ Service deployed to stack aws-node-notifications-dev (152s)

endpoint: POST
 - https://xxxxxxxxxx.execute-api.us-east-1.amazonaws.com/
functions:
  notify: aws-node-notifications-dev-notify (1.9 kB)

Invocation

After successful deployment, you can call the created application via HTTP:

curl --request POST \
     --url https://xxxxxxx.execute-api.us-east-1.amazonaws.com/ \
     --data '
{
  "message": {
    "to": {
      "email": "email@example.com",
    },
    "content": {
      "title": "Hello",
      "body": "World"
    }
  }
}
'

See the Courier Send API docs for the supported request body formats.

Local development

You can invoke your function locally by using the following command:

serverless invoke local --function notify

About


Languages

Language:JavaScript 100.0%