FCM with AWS SNS

I am using AWS resources for my Android project, I plan to add a push notification service for my project using AWS SNS . There are a few questions that bother me very much. I did not find any questions in them, except for one or two, but with unclear explanations.

1. Support AWS FCM ? SNS works with GCM . But Google recommends using FCM instead of GCM . I did not find AWS FCM support.

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

3. I tried to put the APM FCM key in the SNS application platform, it shows incorrect parameters, why?

+88
android amazon-web-services amazon-sns firebase-cloud-messaging google-cloud-messaging
Jul 11 '16 at 6:30
source share
8 answers

FCM is backward compatible with GCM. The steps to configure FCM on AWS are identical to the GCM setup procedure and (at least for now). FCM transparently works with GCM and SNS with respect to server-side configuration.

However, if you send useful files to the data Android device, they will not be processed unless you run the client service , which extends the FirebaseMessagingService . The default JSON message generator in the AWS console sends data messages that will be ignored by your application if the above service is not implemented. To get around this for initial testing, you can provide a custom notification payload that will be received by your device (until your application is in the foreground).

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

The steps you must follow to test GCM / FCM in your application using SNS:

  • Create the Platform application in SNS by selecting Google Cloud Messaging (GCM) as the Push Notification Platform and providing the server API key in the API field.
  • Select the platform application and click the Create platform endpoint button.
  • Provide the InstanceID generated by your application. You must extend the FirebaseInstanceIDService and override the onTokenRefresh method to see this in your Android application. After you have done this , uninstall and reinstall the application, and your token should be printed on the Debug console in Android Studio at the first boot.
  • Click the Add Endpoint button.
  • Click the ARN link for your platform application.
  • Select the newly created endpoint for your device and click the Publish to endpoint button.
  • Select JSON Message Format and click the JSON Message Generator button.
  • Enter a test message and click Create JSON
  • Now comes the "piece received."

The message generated by SNS will look like:

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

As mentioned earlier, the data payload 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 modify the JSON message to read:

 { "GCM": "{ \"notification\": { \"text\": \"test message\" } }" } 

Once you do this, make sure your application is not running on the device and click the Post message button. You should now see a notification that appears 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 the payload that matches your use case.

+175
Jul 28 '16 at 2:58
source share

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

You will see an outdated server key, which is the GCM API key, and you will have the opportunity to generate new server keys that are versions of FCM

SNS will accept both versions, but their menu item still belongs to the GCM category

Here is the image for your reference:

enter image description here

Please note that you can β€œaccidentally” delete server keys, but an outdated server key cannot be deleted. In addition, if you click the add server key button, you will get a new server key below the first, WITHOUT WARNING! ... Google works great;)

+13
May 22 '17 at 16:57
source share

I tried to use a solution with useful notification data instead of data, but I did not receive push notifications on my mobile device. I found this tutorial https://youtu.be/iBTFLu30dSg with English subtitles on how to use FCM with AWS SNS step by step, and an example of how to send push notifications from the AWS console and implement it on php using aws php sdk. It helped me a lot.

+5
Feb 12 '18 at 12:06
source share

One additional point for Nathan Dunn: excellent answer. How to send notification data from SNS to Firebase.

We need to add data to Json (inside the notification):

 { "default": "any value", "GCM": "{ \"notification\": { \"body\": \"message body\", \"title\": \"message title \", \"sound\":\"default\" } , \"data\" : {\"key\" : \"value\", \"key2\" : \"value\" } }" } 

In your implementation of FirebaseMessagingService (Xamarin example)

 public override void OnMessageReceived(RemoteMessage message) { try { var body = message?.GetNotification()?.Body; var title = message?.GetNotification()?.Title; var tag = message?.GetNotification()?.Tag; var sound = message?.GetNotification()?.Sound; var data = message?.Data foreach (string key in data.Keys) { // get your data values here } } catch (Exception e) { } } 
+5
Mar 07 '18 at 10:07
source share

Another note to Nathan Dunn. Answer: to add sound, use the following JSON message.

 { "GCM": "{ \"notification\": { \"text\": \"test message\",\"sound\":\"default\" } }" } 
+2
Mar 08 '17 at 3:45
source share

It took me a while to figure out how to send a notification with the correct payload (posting in a thread). So I will put it here.

 private void PublishToTopic(string topicArn) { AmazonSimpleNotificationServiceClient snsClient = new AmazonSimpleNotificationServiceClient(Amazon.RegionEndpoint.EUWest1); PublishRequest publishRequest = new PublishRequest(); publishRequest.TopicArn = topicArn; publishRequest.MessageStructure = "json"; string payload = "\\\"data\\\":{\\\"text\\\":\\\"Test \\\"}"; publishRequest.Message = "{\"default\": \"default\",\"GCM\":\"{" + payload + "}\"}"; PublishResponse publishResult = snsClient.Publish(publishRequest); } 
0
Aug 20 '18 at 7:41
source share

To answer the questions:

  1. AWS SNS supports FCM.
  2. No AWS saves messages after sending push notifications.

For a detailed guide on configuring FCM with SNS, see this article.

0
Jan 20 '19 at 13:46
source share

Amazon supports FCM since all previous code has been ported from GCM to FCM. The following article explains in detail.

Article posted by Amazon

0
Jan 30 '19 at 7:48
source share



All Articles