[Serverless application] — Send Push Notifications to Huawei Devices from Amazon SNS

Taha HICHRI
Huawei Developers
Published in
3 min readApr 14, 2021
Push notification sent from SNS displayed on a Huawei device

Prelude

We will deploy AWS serverless application for sending push notifications to Huawei devices without Google Play Services using AWS Lambda and Amazon Simple Notification Service .

The application can be included in your existing projects with minimal code change and has no impact on your current architecture

The deployed application diagram:

How it works

The application creates an SNS topic and a lambda function that handles the authentication and the message sending to Huawei push service.

It allows you to send push messages by simply publishing an SNS message to that topic and including the push payload in the Message Parameter.

Prerequisites

1- Huawei AppGallery Connect account
The Huawei Push Service requires an OAuth 2.0 access token for authentication The lambda will manage that for you, but you need to set your App Credentials. Here is how to get those credentials

2- AWS account
The account on which the lambda and SNS topic will be created

3- Basic Understanding on Amazon SNS and AWS Lambda.

Getting Started

1. Deploy the application

Go to the serverless application’s page on AWS Serverless Applications Repo.

You can deploy the application by simply clicking the “Deploy” button.

2. Set Lambda Environment variables

The Huawei Push Service requires an OAuth 2.0 access token for authentication The lambda will manage that for you, but you need to set your App Credentials. Here is how to get those credentials

Once you have the credentials, add them as environment variables of the deployed lambda.

You can find the function name by searching for the lambda in your lambda’s page. The name should look like this:

serverlessrepo-sns-push-hms-snspushhms-1PJ111R3S6D59

Here is an example:

Note the app id can be the same as the client id.

3. Publish Test Push Message

To send push messages, simply publish a message to the SNS topic, set the payload in the “Message” parameter.

Example Payload template: Check the project repo

  • deviceTokensArray: Array of device tokens
  • title: Title of the push
  • bodyText: Body of the push

More details: on the ref page

Example SNS topic message publishing (nodeJS):

--

--