AWS Greengrass通过SNS Connector推送Android通知失败求助
I’ve seen this exact scenario a few times before—your hunch is spot on: the SNS Connector is likely treating your message as a raw payload instead of recognizing it as a valid FCM (formerly GCM) notification, even though the content structure looks correct. Here’s how to resolve this:
1. Verify SNS Connector Target Configuration
First, double-check that your SNS Connector is pointing to the FCM platform endpoint ARN (not the generic SNS topic ARN). Since you can receive notifications when manually inputting the payload via the SNS Console, this is probably already set up right, but it’s worth confirming to rule out any misconfiguration here.
2. Add Message Attributes to Explicitly Define FCM Format
The key fix is adding a message_attributes field to your MQTT payload to tell SNS exactly what type of message this is. This overrides the default raw handling. Here’s your updated message structure:
{ "request": { "subject": "greengrassToSns", "message": "{ \"notification\": { \"body\": \"Body of the message.\", \"title\": \"Title\" } }", "message_attributes": { "AWS.SNS.MOBILE.GCM.MESSAGE_TYPE": { "data_type": "String", "string_value": "notification" } } }, "message_structure": "json", "id": "TestId" }
The AWS.SNS.MOBILE.GCM.MESSAGE_TYPE attribute signals to SNS that this is an FCM notification payload, not raw data.
3. Validate JSON Escaping
Make sure the nested message string is properly escaped. A single missing backslash can cause SNS to fail parsing the FCM payload, even if the structure looks right. You can use a local JSON validator to check that the escaped string is valid JSON.
4. Check CloudWatch Logs for Detailed Errors
Beyond subscribing to sns/message/status, head to AWS CloudWatch and look for SNS delivery logs filtered by your message ID (TestId). These logs will show specific errors like "invalid payload" or formatting issues that might not show up in the status topic.
5. Test with a Simplified Payload
To isolate the issue, try sending a minimal FCM payload first, removing any unnecessary fields like subject (FCM notifications don’t require this, and it can sometimes interfere with parsing):
{ "request": { "message": "{ \"notification\": { \"title\": \"Test\", \"body\": \"Hello from Greengrass\" } }", "message_attributes": { "AWS.SNS.MOBILE.GCM.MESSAGE_TYPE": { "data_type": "String", "string_value": "notification" } } }, "message_structure": "json", "id": "SimpleTestId" }
After making these adjustments, the SNS Connector should correctly recognize your payload as an FCM notification and deliver it to your Android app.
内容的提问来源于stack exchange,提问作者David Bonilla

