AWS Mobile Push Notification by Example
S

1

7

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?

Stegman answered 21/2, 2018 at 14:48 Comment(0)
S
9

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.
Stegman answered 2/3, 2018 at 3:26 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.