2

We need to send the high priority push notification to android mobile using Amazon SNS service.

We are able to send the normal priority messages, but we could not include the priority attribute in the message.

Thank you

Kavin
  • 112
  • 11

1 Answers1

2

It is poorly documented but here is how it worked out.

Make sure several things are in place:

  1. You SNS client publishes message with MessageStructure='json' attribute
  2. You have "default" version of the message in the SNS payload
  3. You serialize into string anything in the custom payload keys.

Python example would look like this

sns: SNSClient = boto3.client('sns', region_name='us-east-1')
message = json.dumps(
    {
        "default": json.dumps(
            {
                "priority": "high",
                "data": {"my": "custom", "payload": "here"},
                "notification": {
                    "title": "Ukraine is awesome",
                    "body": "Ukraine is awesome",
                },
            }
        ),
        "GCM": json.dumps(
            {
                "priority": "high",
                "data": {"my": "custom", "payload": "here"},
                "notification": {
                    "title": "Ukraine is awesome",
                    "body": "Ukraine is awesome",
                },
            }
        ),
    }
)

response = sns.publish(
    TopicArn=SNS_TOPIC,
    Message=message,
    MessageStructure='json',
)
Anton
  • 321
  • 2
  • 7