Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWS Mobile Push Notification by Example

I'm trying to wrap my head around how AWS Mobile Push Notification works. Specifically I'm building out a web service that will be capable of sending notifications to my mobile app running on my users' devices. After reading all of their docs, it sounds like the high level flow is:

  • Configuration
    • I need to go into my respective Push Notification Services (GCM for Android and APNS for iOS) and configure them to get credentials that I configure my backend service to use for connecting to them at runtime
    • I need to log in to the AWS SNS console and generated a platform application ARN (PlatformApplicationARN) that I also configure my backend to use
  • Code Flow (Runtime)
    1. When a new user signs up for the first time, or anytime an existing user signs in on a new device, I have the app send my service their device info. One critical piece of this device info is their device token (also referred to as a "registration ID" in the AWS docs). This token is generated by their OS and uniquely identifies their device within their respective Push Notification Services (again either GCM or APNS for me)
    2. When my service receives this new device info, I save it, and I also use the device token to hit the AWS SNS API (along with my configured PlatformApplicationARN) to generate a unique EndpointARN for that particular device
    3. Now, whenever my backend decides it needs to send a notification to that user, I can look up all the devices associated with that user (that I previously stored in my DB), and fetch each device's EndpointARN. Then its just a matter of hitting the AWS SNS API to send my notification message to that EndpointARN, and it sounds like AWS SNS will take care of everything else (and delivering the actual message to the device)

So before I go any further, I'm just looking for someone to help sanity check my understanding and provide any course correction if I've misunderstood anything or am missing any important pieces of the config/flow! Assuming I'm more or less on track...

I'm still not seeing how SNS will be able to connect to GCM and APNS once I send a notification message to an EndpointARN. Do they maintain their own integration/connection with these services? Or do I somehow inject my own GCM/APNS credentials into the AWS SNS API call somehow?

Also, I know push notifications can be fairly configurable, allowing you to do things like:

  • Determine what sound the device should play when it receives a notification
  • Determine what color LED to blink on/off when it receives a notification (on my Android phone, different apps cause green, blue even purple LEDs to blink!)
  • Determine whether the notification is received by the Android/iOS OS itself (in which case if I come back to my phone after being away from it for a few minutes, I can press any button and see a high-level listed summary of any new notifications I've received); or whether the notification is purely an "in-app" notification in which case I'll only see that I received it if I actually open up my app.

I'm wondering where all this configuration takes place? Any ideas?

like image 820
smeeb Avatar asked Feb 21 '18 14:02

smeeb


People also ask

What is an example of a push notification?

In this example, YouTube app notifies app users about new uploads from channels they are subscribed to. The push action buttons allow users to control when they want to watch these videos by adding options such as 'Watch Later' and 'Others'.

How do phones receive push notifications?

Unlike iOS users, Android users are automatically opted in to receive push notifications, this leads to new Android users being more likely to be opted-in to notifications.

How do I enable push notifications on Amazon?

Open the Amazon Pinpoint console at https://console.aws.amazon.com/pinpoint/ . On the All projects page, choose the project that you want to update push notification settings for. In the navigation pane, under Settings, choose Push notifications. Next to Push notifications, choose Edit.


1 Answers

I can confirm that the high level flow is:

  1. Log into AWS SNS and create 2 different Platform Applications, 1 for Android (FCM -- Firebase Cloud Messaging) and the other for iOS (APNS -- Apple Push Notification Services)
  2. For each Platform Application you'll get a PlatformApplicationArn and you will be asked for credentials so that SNS can connect to your respective FCM/APNS accounts
    • For FCM you will just need your Server API Key (this can be obtained from Firebase Cloud Manager)
    • For APNS you will need to go through a really labor-intensive process of creating certificates through the Key Chain Access tool on your Mac, this was not fun...
  3. Add these 2 PlaformApplicationArns to your code's config
  4. When a user registers a new device with your app, they will send you a device token (provisioned by FCM or APNS) that uniquely identifies them to FCM/APNS
  5. Take this device token, combined with your PlatformApplicationArn for FCM or APNS and use the AWS SNS SDK to create an EndpointArn for the device. Store this EndpointArn however you like.
  6. Now you can use the AWS SNS SDK to push messages to your EndpointArn (specific device) anytime you want to.
like image 171
smeeb Avatar answered Oct 03 '22 04:10

smeeb