parse-server-modules / parse-server-sns-adapter

Parse Server SNS Adapter
18 stars 14 forks source link

Parse Amazon SNS Push Adapter

Build
Status codecov.io NPM Version

This adapter can be used with Parse open source to leverage the Amazon Simple Notification Service (SNS), which attempts to abstract away the complexities of different push notification systems. Currently, there is only support for iOS (Apple Push Notification Service) and Android (Google Cloud Messaging) devices.

To add other push types, you simply need to know what kind of payload format to be sent and this adapter will need to be modified to send it. This adapter leverages code from the parse-server-push-adapter repo. See the Amazon documentation if you wish to add other types. Make sure to add test coverage for any additional ones inside the spec folder.

Known limitations

Setup

The steps basically entail:

Configurating Platform Endpoints

  1. Sign into the Amazon Web Services (AWS) Console.
  2. Select the SNS Service.
  3. Select Create Platform Application.
    • For GCM setup, you must provide an API key. See the instructions about how to generate this key.
    • For APNS setup, you must generate an SSL certificate that can connect to Apple's servers. See step #1 of this tutorial. You will need to choose between Apple Production and Apple Development depending on the cert generated.
      • If you do not use a passpharse with the certificate, you can click on the Load Credentials File and the Private Key section should be auto filled out. Otherwise, you will need to enter the correct passphrase in order to load.
  4. Record the Amazon Resource Number (ARN) associated with this new endpoint.

Setting up IAM Role

  1. Go to the Amazon IAM console.
  2. Create a user that will be granted access to SNS.
  3. Select the Policies tab and click on the Create Policy button.
  4. Select Create Your Own Policy and fill out a Policy Name.
  5. Copy this Policy document that will grant blanket access to SNS services. You can add more restrictions later.

       {
          "Version": "2012-10-17",
          "Statement": [
          {
            "Action": [
              "sns:*"
            ],
            "Effect": "Allow",
            "Resource": "*"
          }
         ]
       }
  6. Make sure to Validate the Policy and click Create Policy.
  7. Go back to the Users tab and select the user you created earlier.
  8. In Permissions, select Attach Policy and find the policy we just created to attach it.
  9. Click on Security Credentials and click on Create Access Key.
  10. Record the credentials, which will be used to configure the Parse server. You will need to set the access and secret key as the environment variables SNS_ACCESS_KEY and SNS_SECRET_ACCESS_KEY respectively.

Configuring Parse Server

You will need add this NPM package to the package.json used in conjunction with the Parse open source package:

"dependencies": {
  "parse-server-sns-adapter": "~0.0.7"
}

Type npm install and make sure this module got added to your node_modules dir.

Here is a sample config setup. You can specify the SNS_ACCESS_KEY and SNS_SECRET_ACCESS_KEY as environment variables, or you can hard-code them here.

For iOS certificates, make sure to set the production and bundleId according to the type of certificate generated.

var pushConfig =  { pushTypes : { android: {ARN : 'arn:aws:sns:us-west-2:12345678:app/GCM/Android'},
                                  ios: {ARN:'arn:aws:sns:us-west-2:12345678:app/APNS_SANDBOX/ParseAppleTest', production: false, bundleId: "beta.parseplatform.yourappname"}
                                 },
                   accessKey: process.env.SNS_ACCESS_KEY,
                   secretKey: process.env.SNS_SECRET_ACCESS_KEY,
                   region: "us-west-2"
                 };

var SNSPushAdapter = require('parse-server-sns-adapter');
var snsPushAdapter = new SNSPushAdapter(pushConfig);
pushConfig['adapter'] = snsPushAdapter;

You then need to instantiate the ParseServer info with the following:

var api = new ParseServer({

  push: pushConfig
});

Troubleshooting