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.
The adapter always makes a network call to Amazon's service to exchange a device token for an Amazon Resource Number (ARN).
Amazon will disable devices that have device tokens that are considered invalid by the push notifications. There is currently no check in place to see if the ARN used to send is enabled.
SNS does not appear to have batching sends with GCM.
The steps basically entail:
Adding Platform endpoints to AWS console
Apple requires you loading the prod/development certificates.
.certSigningRequest
file.You can also verify the cert can be used to connect to Apple's push service:
openssl x509 -in myapnsappcert.cer -inform DER -out myapnscert.pem
.p12
format
openssl pkcs12 -in myapnsappprivatekey.p12 -out myapnsappprivatekey.pem -nodes -clcerts
openssl s_client -connect gateway.sandbox.push.apple.com:2195 -cert myapnsappcert.pem -key myapnsappprivatekey.pem
openssl s_client -connect gateway.push.apple.com:2195 -cert myapnsappcert.pem -key myapnsappprivatekey.pem
Setup an IAM role for platform endpoints.
Generate AWS access key and secret with this authorized IAM role.
Enable CloudSearch logs for debugging.
Configure Parse server
SNS
Service.Create Platform Application
.
Apple Production
and Apple Development
depending on the cert generated.
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.Policies
tab and click on the Create Policy
button.Create Your Own Policy
and fill out a Policy Name
.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": "*"
}
]
}
Validate the Policy
and click Create Policy
.Users
tab and select the user you created earlier.Attach Policy
and find the policy we just created to attach it.Security Credentials
and click on Create Access Key
.SNS_ACCESS_KEY
and SNS_SECRET_ACCESS_KEY
respectively.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
});
Inside the Amazon SNS Console, click on the Applications
tab, select an endpoint and choose the
Actions
dropdown to select Delivery status
. Click on Create IAM roles
which will enable SNS to write to CloudWatch. You can then go to the CloudWatch console, click on the Logs
, and view the results of any pushes that may have been issued.
Make sure that you use the right Apple certificate for production/development purposes. Your Parse push configuration needs to have the production
flag set to be true
or false
, and you must configure your Amazon endpoints. Also verify the bundleId
corresponds to the app that can receive these push notifications.
If you wish to test this adapter locally and assuming you have a Parse open source server setup locally, make sure to install node-inspector
:
npm install node-inspector
Assuming you've hard-coded your configuration inside index.js
, run your Parse server with the following line:
node --debug index.js
Run node-inspector
in a separate window:
bash
node_modules/.bin/node-inspector
Open up http://127.0.0.1:8080/?port=5858 locally. You can use the Chrome debugging tools to set breakpoints in the JavaScript code.
Set VERBOSE=1
or VERBOSE_PARSE_SERVER_SNS_ADAPTER=1
as an environment variable to see all logging.