Loading....

Navigating the Notification Setup A Detailed Walkthrough of AWS SNS and Google FCM Configuration

In today’s digital landscape, effective communication is paramount, and platforms like Amazon Simple Notification Service (SNS) and Google Firebase Cloud Messaging (FCM) play pivotal roles in ensuring seamless delivery of notifications to users. 

In this blog post, we’ll investigate the procedures for setting up push notifications using Google Firebase’s FCM and AWS SNS. By the conclusion of our demonstration, we’ll have established a notification service capable of transmitting push notifications directly from AWS to clients.

First, let’s take a look at Firebase Cloud Messaging (FCM) and Amazon Simple Notification Service (SNS) to understand their roles.

Firebase Cloud Messaging (FCM)

Firebase Cloud Messaging (FCM), previously known as Google Cloud Messaging (GCM), is a no-cost cloud service provided by Google, allowing app developers to dispatch notifications and messages to users across various platforms, including Android, iOS, and web applications. 

FCM empowers software developers to transmit push notifications to end users through an application programming interface (API). Push notifications are favored on mobile devices as they are power-efficient, unlike pull notifications, which constantly request information from the developer’s server and can drain the device’s battery.

Amazon Simple Notification Service (SNS)

Amazon Simple Notification Service (SNS) is a fully managed messaging service provided by Amazon Web Services (AWS). It enables you to send notifications from the cloud to various endpoints such as HTTP/S, email, SMS, and more. SNS follows a publish-subscribe (pub/sub) messaging paradigm, allowing you to decouple message producers from message consumers.

With SNS, you can create topics to which messages or notifications are published. Subscribers interested in receiving messages from a particular topic can subscribe to it. When a message is published to a topic, SNS delivers that message to all subscribed endpoints asynchronously.

SNS offers features such as message filtering, message attributes, message encryption, message delivery retry, and dead-letter queues, providing flexibility and reliability in message delivery.

Developers commonly use SNS for sending notifications, distributing event notifications, and building distributed systems where various components need to communicate asynchronously.

Now that we have these two services defined, lets now begin our configuration

Prerequisites

Before you begin you need:

  • An AWS account with full administrative privileges
  • Gmail Account for accessing the Firebase console

Step 1: Setting up a Firebase project

Firebase project is the top-level entity for Firebase. In a project, you can register your Apple, Android, or web apps. After you register your apps with Firebase, you can add the Firebase SDKs for any number of Firebase products, like Analytics, Cloud Firestore, Performance Monitoring, or Remote Config.

You can set up a Firebase project and register apps in the Firebase console. When you set up a project and register apps, you need to make some organizational decisions and add Firebase-specific configuration information to your local projects.

Procedures for setting up a Firebase project

  1. Go to Firebase console
  2. Click the “Go to console” button which is located at the top right of the webpage.
  3. Click “Add Project” button
  4. Follow the required steps, provide what’s required and create a new project

Step 2: Register your app with Firebase

To integrate Firebase into your application, whether it’s for web or mobile, you must register your app with your Firebase project. This process, commonly referred to as “adding” your app to the project, varies depending on the type of app you’re developing – whether it’s for Apple, Android, web, or Flutter platforms. For detailed instructions tailored to your specific app type, please refer to the Firebase documentation.

Step 3: Retrieve server key from your firebase project

For AWS to communicate with Firebase Cloud Messaging (FCM) and deliver notifications through it, it needs authorization from Firebase. Here’s how you can authorize requests sent to FCM from AWS SNS:

  1. Using FCM HTTP v1 API
  • This API authorizes requests with a short-lived OAuth 2.0 access token.
  • You can manually obtain the required credentials from a JSON private key file generated for a service account in Firebase.
  1. Using Deprecated Legacy Protocols
  • Deprecated legacy protocols can only use long-lived API keys obtained from the Firebase console. These API keys are typically used with older versions of Firebase Cloud Messaging and are not recommended for new projects.

Since the second method is already depreciated and is not recommended for use, we will use the first method to authorize our AWS SNS service.

Procedures for generating JSON private key file

  1. Open your Firebase console and go to your Firebase project.
  2. Go to project settings
  3. Navigate to the “Cloud Messaging” section, located within the “Firebase Cloud Messaging API (V1)” category. From there, select “Manage Service Accounts” to proceed to the Google Cloud IAM and Admin Center.

Google Cloud IAM and Admin Center

  1. Click the Actions dropdown and from the menu select the “Manage Keys” option. This will take you to the key management page of the selected service account
  1. Navigate to the ‘New Key’ dropdown menu and select ‘Create new key.’ A modal will appear asking you to choose the key type; opt for ‘JSON’ and proceed by clicking the ‘Create’ button. This action will initiate the download of the private key file to your device. Ensure to store this file securely, as it will be utilized later for SNS setup.

Private key generation step

Step 4: Amazon SNS: Create a platform application

For Amazon SNS to send notification messages to mobile endpoints, whether directly or via subscriptions to a topic, you must first create a platform application. After registering the app with AWS, the next step is to create an endpoint for the app and mobile device. Amazon SNS then uses the endpoint for sending notification messages to the app and device.

To create a platform application

  1. Sign in to the Amazon SNS console.
  2. In the navigation pane, choose Mobile, and then choose Push notifications.
  3. In the Platform applications section, choose Create platform application.
  1. For Application name, enter a name to represent your app.
  • App names must be made up of only uppercase and lowercase ASCII letters, numbers, underscores, hyphens, and periods. Names must also be 1–256 characters long.
  1. From the push notification platform options select “Firebase Cloud Messaging (FCM)” option.
  2. Below the dropdown menu for selecting the push notification platform, you’ll find a new section labeled “Firebase Cloud Messaging Credentials.” Opt for the “Token Authentication” method, then click on the button to select a file. Choose the private key file you downloaded previously and proceed by clicking the “Create platform application” button.

Amazon SNS: Registering platform application

Step 5 : Amazon SNS : Create a platform application

When an app and mobile device register with a push notification service, the push notification service returns a device token. Amazon SNS uses the device token to create a mobile endpoint, to which it can send direct push notification messages.

To push notifications to an app with Amazon SNS, that app’s device token must first be registered with Amazon SNS by calling the create platform endpoint action. This action takes the Amazon Resource Name (ARN) of the platform application and the device token as parameters and returns the ARN of the created platform endpoint. 

For more detailed instructions on how you can get the app’s device token on FCM, please consult the Firebase Cloud Messaging documentation.

Steps to add a device registration ID

  1. Sign in to the Amazon SNS console.
  2. Choose Mobile, and then choose Push Notifications.
  3. In the Platform applications section, select your application and then choose Edit. 
  4. Choose Add Endpoints.
  5. In the Endpoint Token box, enter either the registration ID.
  6. (Optional) In the User Data box, enter arbitrary information to associate with the endpoint. Amazon SNS does not use this data. The data must be in UTF-8 format and less than 2KB.
  7. Finally, choose Add Endpoints.

Now with the endpoint created, you can either send messages directly to a mobile device or send messages to mobile devices that are subscribed to a topic.

Conclusion

This blog post explores the importance of effective communication in today’s digital landscape, highlighting the roles of Amazon Simple Notification Service (SNS) and Google Firebase Cloud Messaging (FCM) in delivering seamless notifications to users. It delves into the setup procedures for push notifications using FCM and AWS SNS, culminating in establishing a notification service capable of transmitting messages directly from AWS to clients through broadcasting on specific SNS topics.

Firebase Cloud Messaging (FCM), previously known as Google Cloud Messaging (GCM), is a free cloud service facilitating the dispatch of notifications and messages to users across platforms like Android, iOS, and web applications. FCM offers an API for developers to send push notifications efficiently, targeting individual devices, device groups, or devices subscribed to specific topics. It integrates with Firebase Analytics for tracking user engagement and conversion.

Amazon Simple Notification Service (SNS), provided by Amazon Web Services (AWS), is a fully managed messaging service enabling notifications to various endpoints such as HTTP/S, email, and SMS. SNS operates on a publish-subscribe model, allowing decoupling of message producers from consumers. SNS offers features like message filtering, encryption, delivery retry, and dead-letter queues, enhancing message delivery flexibility and reliability. Developers commonly use SNS for notifications, event distribution, and building asynchronous communication systems.

Leave a Reply

Your email address will not be published.