简体   繁体   中英

How to publish to android via AWS Step Functions and AWS SNS

I am trying to push to Android phones via AWS Step Functions and AWS SNS.

I am able to see the notification in the debug console, but it does not appear. How do i have to format the message correctly? I tried several combinations, but none worked.

"Publish notification": {
      "Type": "Task",
      "Resource": "arn:aws:states:::sns:publish",
      "Parameters": {
        "Message": {
          "default": "TestTestTest",
          "GCM": {
            "data": {
              "message": "Sample message for Android endpoints"
            }
          },
          "Input": "Hello from Step Functions!"
        },
        "MessageStructure": "json",
        "TargetArn": "arn:aws:sns:eu-central-1:xxxxxxxxx:endpoint/GCM/android/xxxxxxxxxxxxx"
      },
      "Next": "next state"
    }

The notification appears correctly on the phone if a send directly via SNS:

"GCM": "{ \"data\": { \"message\": \"Sample message for Android endpoints\" } }"

I also tried the Code Sample from the Step Functions Editor:

"Message": {
  "Input": "Hello from Step Functions!"
}

When it comes to FCM Push Notifications, there are two types of message types that are supported ie “data” or ”notification”.

Looking at your message payload, I see you are using message of type "data" . This means that:

“data" messages are not automatically handled by the FCM SDKs and will not be delivered to the notification center automatically therefore the clients' need to handle this type of messages.

Resolution:

You will need use message payload of type notification since you want the push notification to appear on the end-user device. See sample state machine definition I authored:

{
"StartAt": "Publish to SNS",
"States": {
  "Publish to SNS": {
    "Type": "Task",
    "Resource": "arn:aws:states:::sns:publish",
    "Parameters": {
      "TargetArn": "arn:aws:sns:us-east-1:xxxxxxx:endpoint/GCM/AWSNS-Android/xxxxx-xxxxxxx-xxxxxxx",
      "MessageStructure": "json",
      "Message": {"GCM": "{ \"notification\": { \"body\": \"sample test push\" } }"}
    },
    "End": true
    }
  }
}

Hope this helps!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM