By using AWS re:Post, you agree to the AWS re:Post Terms of Use

How do I create an Android platform application in Amazon SNS for push notifications?

3 minute read
0

I want to create a platform application in Amazon Simple Notification Service (Amazon SNS) to send push notifications to Android devices.

Resolution

Amazon SNS push notifications aren't available in all AWS Regions. For more information, see Supported Regions for mobile applications.

Prerequisites: You must have a Firebase project and a valid Android app registered with Firebase. For instructions, see Step 1: Create a Firebase project and register your app on the Firebase website. You must also have valid credentials from Firebase Cloud Messaging (FCM), including an FCM project token credential.

Retrieve your FCM project's token credentials

Complete the following steps:

  1. Open the Firebase console, and then choose your project.
  2. In the navigation pane, choose the gear icon, and then choose Project settings.
  3. Choose the Service accounts tab.
  4. Choose Generate new private key to download the JSON-formatted private key file to create an Android platform application that has token-based authentication.

Create the Android platform application

When you create a new platform application, choose token-based authentication to allow Amazon SNS to use the Google FCM HTTP v1 API. If you have a platform application that uses the deprecated legacy FCM API, then upgrade your application to use token-based authentication. For more information, see Migrate from legacy FCM APIs to HTTP v1 on the Firebase website.

You can use the Amazon SNS console, AWS Command Line Interface (AWS CLI), or Amazon SNS API to create the platform application.

Use the Amazon SNS console

To use the Amazon SNS console, see Creating a platform application.

For Push notification platform, choose Firebase Cloud Messaging (FCM). For Authentication method, choose Token. Then, choose Choose file to upload the JSON-formatted private key file.

Use the AWS CLI

Note: If you receive errors when you run AWS CLI commands, then see Troubleshooting errors for the AWS CLI. Also, make sure that you're using the most recent AWS CLI version.

Complete the following steps:

  1. Your file must be in string format and you can't use special characters. To format the file, run the following command from the same directory where your JSON-formatted private key file is located:

    SERVICE_JSON=`jq @json <<< cat "private_key_JSON_file"`

    Note: Replace private_key_JSON_file with your private key file name.

  2. Run the create-platform-application command from the same directory that your key file is in:

    aws sns create-platform-application --name Your_Application_Name --platform GCM --attributes PlatformCredential=$SERVICE_JSON

    Note: Replace Your_Application_Name with your own application name.
    Your platform application's ARN appears in the command's output.
    Example:

    {    
        "PlatformApplicationArn": "arn:aws:sns:us-east-1:XXXXXXXXXXXX:app/GCM/Your_Application_Name"    
    }
  3. As a best practice, set up event notifications and delivery status logging.

Use an Amazon SNS API

Use the CreatePlatformApplication API operation.

Send push notifications

To use the Android platform application to send push notifications, see Mobile push notifications.

Related information

How do I create an APNs platform application for sending push notifications in Amazon SNS using the AWS CLI?

Adding device tokens or registration IDs

Publishing to a mobile device

Publishing to a topic

Platform response codes

AWS OFFICIAL
AWS OFFICIALUpdated 2 months ago
2 Comments

Hello, is there a timeframe for the Amazon SNS update to support FCM API (v1)?

replied a year ago

Thank you for your comment. We'll review and update the Knowledge Center article as needed.

profile pictureAWS
MODERATOR
replied a year ago