Search code examples
amazon-web-servicespush-notificationaws-amplifyaws-pinpoint

aws amplify direct push notifications for a mobile app is confusing


I'm confused on aws amplify recommendation on how to send push notifications for a mobile app. If I'm creating a chat app and I want to send a push notification whenever a message is sent whether it's apple or android, what is the recommended service to use ? My understanding based on the documentation here is that they recommend pinpoint and to set it up with both firebase and apns but it seems like pinpoint is mainly about creating audience and campaigns and not sending notifications to specific users. Any idea about the best approach here ?


Solution

  • You need AWS pinpoint to send push notifications. FCM and APNS credentials are required to send push notifications to Google or Android devices from any 3rd party provider (e.g. AWS Pinpoint).

    In relation to push notifications, there is the idea of "endpoints" which you can basically assign to a user based on their userId and a push registration token.

    In terms of setting pinpoint up, you need integration within the app and backend.

    Mobile App Purpose here is to assign an "endpoint" a userId and the push registration token that is generated by the app. Basic instructions:

    1. Set up pinpoint via an SDK (e.g. AWS amplify).
    2. Once a user logs in (e.g. with Cognito), you need to update the endpoint with the userId
    3. Once app triggers a push notification registration token, update the endpoint with this token (you may need to set in a local storage equivalent as user may not be logged in when this occurs)

    example of update endpoint https://docs.amplify.aws/lib/analytics/update-endpoint/q/platform/js/

    Backend

    You can send notifications to users via the pinpoint API, by calling sendUsersMessages by specifying a message for APNSMessage and GCMMessage

    It's quite complicated and takes a bit of time to get up and running with frontend and backend working. It has been quite unstable in the past when integrating with Amplify. For example https://github.com/aws-amplify/amplify-js/issues/7251#issuecomment-1364021359