Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FCM with AWS SNS

I am using AWS resources for my android project, I am planning to add push notification service for my project with AWS SNS.there are few questions bothering me much. I did not find any questions regarding these, except one or two but with unclear explanations.

1.Does AWS support FCM? SNS work with GCM. But Google recommends to use FCM instead of GCM. I did not find AWS supporting FCM.

2.Do AWS store messages (or data) into their databases even after sending push notifications?

3.I tried putting FCM api key in SNS application platform, it is showing invalid parameters why?

like image 232
Naroju Avatar asked Jul 11 '16 06:07

Naroju


People also ask

Is AWS SNS push notification?

Amazon SNS supports SMS text messaging to over 200 countries, mobile push notifications to Amazon, Android, Apple, Baidu, and Microsoft devices, and also email notifications.

Is FCM push notification free?

Firebase Cloud Messaging (FCM) provides a reliable and battery-efficient connection between your server and devices that allows you to deliver and receive messages and notifications on iOS, Android, and the web at no cost.


2 Answers

FCM is backwards compatible with GCM. The steps for setting up FCM on AWS are identical to the GCM set up procedure and (at least for the moment) FCM works transparently with GCM and SNS with respect to server-side configuration.

However, if you are sending data payloads to the Android device they will not be processed unless you implement a client side service that extends FirebaseMessagingService. The default JSON message generator in the AWS console sends data messages, which will be ignored by your app unless the aforementioned service is implemented. To get around this for initial testing you can provide a custom notification payload which will be received by your device (as long as your app is not in the foreground)

There are GCM-FCM migration instructions provided by Google however the changes you need to make are predominantly on the App side.

The steps you need to follow to test GCM/FCM on your app with SNS are:

  1. Create a Platform Application in SNS, selecting Google Cloud Messaging (GCM) as the Push Notification Platform, and providing your Server API key in the API key field.
  2. Select the Platform Application and click the Create platform endpoint button.
  3. Provide the InstanceID (Device Token) generated by your app. You must extend the FirebaseInstanceIDService and override the onTokenRefresh method to see this within your Android App. Once you have done this, uninstall and reinstall your app and your token should be printed to the Debug console in Android Studio on first boot.
  4. Click the Add endpoint button.
  5. Click on the ARN link for your platform application.
  6. Select the newly created Endpoint for your device and click the Publish to endpoint button.
  7. Select the JSON Message Format, and click the JSON message generator button.
  8. Enter a test message and click the Generate JSON button
  9. Now comes the "gotcha part".

The message that is generated by SNS will be of the form:

{ "GCM": "{ \"data\": { \"message\": \"test message\" } }" } 

As we mentioned earlier, data payloads will be ignored if no service to receive them has been implemented. We would like to test without writing too much code, so instead we should send a notification payload. To do this, simply change the JSON message to read:

{ "GCM": "{ \"notification\": { \"title\": \"test title\", \"body\": \"test body\" } }" } 

(For more information about the JSON format of an FCM message, see the FCM documentation.)

Once you have done this, make sure your app is not running on the device, and hit the Publish Message button. You should now see a notification pop up on your device.

You can of course do all this programmatically through the Amazon SNS API, however all the examples seem to use the data payload so you need to keep that in mind and generate a payload appropriate to your use case.

like image 92
Nathan Dunn Avatar answered Sep 20 '22 10:09

Nathan Dunn


Now you can go to your firebase console (https://console.firebase.google.com/) select your project, click the gear icon and choose project settings, then click on the cloud messaging tab...

You'll see the legacy Server Key which is the GCM API Key and you'll have the option to generate new Server Keys which are the FCM versions

SNS will accept both versions but their menu option is still categorizing it under GCM

Here is picture for your reference:

enter image description here

Note that you can "accidentally" remove your Server Keys but the Legacy server key is not deletable. Also, if you click the add server key button, you'll get a new server key BELOW the first one, WITH NO WARNING! ...Nice job Google ;)

like image 29
Reza Avatar answered Sep 22 '22 10:09

Reza