How to send Firebase Push Notifications with AWS SNS

Firebase cloud messaging (FCM) is a service which enables you to send message or notification on Android device. This session describes how to obtain the FCM prerequisites and send push notification messages to a mobile endpoint. Push notification is sort of message or notification, you can send to users even when they are not actively using your app. Read more about FCM
How push notification works:-
– For push notification, firstly we have to create an app for supported device and messaging API. After registering your app on platform notification service (wills discussion in the next step), you will end up with some sort of token or identifier that is unique to each device.
AWS SNS uses these token or identifier to send notification by creating mobile endpoint. Read about AWS SNS.
Points to cover:-

  1. How to create project in FCM
  2.  How to obtain server API key.
  3. Send notification to mobile device

 

STEPS

1. How to create a project in FCM.
2. To create FCM project, go to https://console.firebase.google.com/ and click on add project.

FCM Console

3. Enter project name and click create project. Once your project is ready click on continue.

4. How to obtain the server API key.

5. Now creating server key, go to setting->Cloud Messaging.

6. Make note of server key from project credential. If you don’t have server key then click on Add server Key.

Send notification on mobile device
For sending notification on mobile device, you first need to register an app with AWS. Registration of application is nothing but creating platform application on AWS SNS.

7. For creating application platform, go to AWS SNS console and choose Create platform application.

SNS Dashboard

8. Enter the application name in the box and choose the GCM application platform.

9. In API key box, enter appropriate credential and click on create platform application.

10.After you create platform application, your console looks like this.

11. When an app and mobile device is registered on push notification service, the notification service gives you a device token. This device token is used to create platform endpoint, once you create endpoint you can publish the message to the mobile device.

12.To create endpoint, click on create platform endpoint.

Once you created an endpoint, SNS gives us endpoint ARN. Now, this is ready to send a message to this endpoint. Make sure the device token will change when your app is reinstalled.

14. For publish message to device, click on publish to endpoint, add message and click on publish message else you can create topic, add endpoint ARN into topic and publish a message to device.

Conclusion:
In this session, we have seen how to send SNS a push notification by creating a project in FCM. You can use another notification service like ADM (Amazon Device Messaging), Baidu, etc and send a notification to mobile device.

 

Contributed by :
Akshata Nandimath
linkedin.com/in/akshata-nandimath-217b8b92