Search code examples
javafirebase-cloud-messagingapple-push-notificationsaws-sdkamazon-sns

Is storing ARNs the correct way to register and send to AWS SNS?


I'm trying to implement push notifications via AWS SNS using FCM/APNS. I've successfully done it manually via the SNS console and now I'm trying to implement the whole process via Java.

The tutorials are short-stopped at demoing the manual method and the AWS SDKs are not that explicit. The things I want to implement via SDK are

  1. Create Platform Application ARNs (FCM/APN)
  2. Create Endpoint ARN (Device Token)
  3. Send Message to Endpoint ARN

Now each step is dependent on the previous step ARN, is it correct that the way to get these ARNs is storing and retrieving them on our database?

For example, to register an Endpoint ARN, I get Platform Application ARN from the DB (with the user's device token), register it on SNS and then save the endpoint ARN response to the DB? Now if I want to send a message to that user then I just get his endpoint ARN from the DB and publish a message?

If you know of any guide that is useful for using SNS in code, either JS or Java you can put it in as an answer as well.


Solution

  • The recommendation is indeed that you store the ARN in your database for retrieval when you want to send a notification to that user. Most applications have an internal mapping, e.g. from user ID -> device ARN that SNS does not know about. This makes it difficult to target specific users unless you have this stored somewhere.

    There is pseudo code available here which goes over best practices for creating and managing platform application endpoints. Keep in mind that this would all be running on your server.