Migrating Amazon SNS from Legacy FCM API to HTTP V1 API
Tags: aws, sns, firebase, google
Published: 2024-01-23 09:50:04

## Introduction

On a work project, we use Amazon SNS to send push notifications to a mobile app registered with Google's Firebase Cloud Messaging (FCM). Although Google was deprecating the Legacy FCM API at that time, SNS did not yet support the new HTTP V1 API. Last weekend, I received an email from AWS that [SNS now supports the new API](https://aws.amazon.com/about-aws/whats-new/2024/01/amazon-sns-fcm-http-v1-api-mobile-notifications/) (yay!). 

![Screenshot of the email](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/llzvzgvifjqbccmew3tp.png)

## Procedures

This tutorial is written based on the steps I took to migrate to the V1 API. Please adjust accordingly.

1. **Getting the Service JSON**

    1. Log in to the [Firebase console](https://console.firebase.google.com/).

    2. Select the project that receives API calls from SNS.

    3. At the top left corner, click on the gear icon, and select **Project Settings**.
         ![Project Settings](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/b5lrhq6g9gj01qfh61bz.png)

    4. At the top navigation under Project Settings, pick **Service accounts**.
         ![Service accounts](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1f1imu7tmnclrqnlbv95.png)

    5. Click **Generate new private key**. A popup shows up reminding you to secure the key. Click **Generate key*.

    6. The key should be downloaded.


2. **Uploading the Service JSON**

    1. Log in to the [Amazon SNS console](https://console.aws.amazon.com/sns).

    2. Select **Push notifications** (under *Mobile*) from the left side menu. Pick the appropriate platform application.
        ![Push notifications](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/s2hf06gk5cjb2x08q9oc.png)

    3. Edit the platform application. At the authentication method, pick **Token (recommended)**. It will ask you to upload a service.json file. Pick the key downloaded previously from the Firebase console.
        ![Token authentication method](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/alnv9zv1eheqlzodb26o.png)

    4. Save changes.

3. **Testing**

    1. At the Platform application page, click on the link of an endpoint from the list below. At the top right-hand corner, click **Publish message**.

    2. At the **Message body** section, pick Custom payload and input the GCM message payload according to your platform (mine is Android).
        ![Message body and custom payload](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9jxpt0xvt6felgbmafh6.png)

    3. Check the app for notifications.
        ![Push notification received](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9was9s4xq73vd8vetuan.png)

    4. To verify that it is using the new API, go back to the Firebase console **Service accounts** tab (refer to step 1.4). Click **Manage service account permissions** at the top-right-hand corner.

    5. At the Service accounts management page, locate the account associated with Firebase Admin SDK. Click the dots menu under **Action** on the right, and pick **View metrics**.
        ![View metrics](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1j38ws7gosf1g2mwjlwz.png)

    6. Verify there were actions when the message was being sent.
       ![Metrics](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9sxrptowjrthmibz1wqm.png)

## Congratulations!

The migration is now complete. You may have to [update the message payload](https://firebase.google.com/docs/cloud-messaging/migrate-v1?hl=en&authuser=0#update-the-payload-of-send-requests) to the new message format. Start exploring the multiplatform messaging capability now!

---

## Extended reading

 -  [What service account permissions are required for firebase cloud messaging on app engine?](https://stackoverflow.com/questions/56659260/what-service-account-permissions-are-required-for-firebase-cloud-messaging-on-ap)
 -  [Migrate from legacy FCM APIs to HTTP v1](https://firebase.google.com/docs/cloud-messaging/migrate-v1?hl=en&authuser=0)