IMD SolutionComputing LibraryShop main store

Troubleshooting

Why Node-RED MQTT payloads never set the AWS SNS email subject

Edge computing and IIoT Published 8 min read

Short answer

An MQTT payload property never sets the AWS SNS email subject: an AWS IoT rule action forwards your payload as message data, and only an SNS Publish call with its Subject parameter filled controls the subject line. Publish to SNS from Node-RED or from a server-side function the rule invokes, keep MessageStructure unset for single-audience alarms, and expect JSON mode to reject a payload keyed by subject and message.

On this page
  1. Why does the email arrive with the subject AWS Notification Message?
  2. Why does adding a subject field to the MQTT payload change nothing?
  3. Why does the email stop arriving after I switch the message to JSON?
  4. How do you get a custom subject without breaking delivery?
  5. Which hop should you check before changing anything?
  6. What limits apply once the publish path works?
  7. How do you verify the new subject without duplicate emails?
  8. Questions asked

The subject line of an AWS SNS email is set by exactly one thing: the Subject parameter of the SNS Publish operation. An MQTT payload forwarded by an AWS IoT rule never reaches that parameter, so your subject property travels as ordinary message text and the email keeps the default subject, AWS Notification Message. The fix is a publishing path that exposes the parameter: call Publish from the Node-RED host, or invoke a server-side publisher from the IoT rule and map the event onto its separate subject and message inputs. Keep the direct rule action only where the default subject is acceptable.

Why does the email arrive with the subject AWS Notification Message? #

SNS falls back to the default subject AWS Notification Message whenever a Publish call leaves its Subject parameter empty, and the AWS IoT rule action has no input that maps payload data onto that parameter — it forwards your MQTT payload as message data and nothing else.

The Publish operation documented in the SNS API reference takes three inputs that matter here: Message, an optional Subject, and an optional MessageStructure. The Subject input exists to become the subject line when delivery goes to email endpoints; left empty, it triggers the default subject. These are publish-level parameters, and nothing downstream of the publish call can add one.

The SNS rule action in AWS IoT is documented to send an MQTT message from AWS IoT as an SNS push notification. It carries message content only: no subject input, no field-to-parameter mapping. In the reported setup, Node-RED publishes a warning over MQTT, the rule forwards the payload, and SNS emails it — each of those emails is a Publish call with an empty Subject, so each one shows the default subject. No payload change can alter that.

Why does adding a subject field to the MQTT payload change nothing? #

MQTT transports the payload as opaque bytes, so a subject key is application data, not an email header; in the rule's raw message mode the entire payload becomes the SNS message body, and the subject text travels inside it like any other field.

Email headers are applied by SNS at delivery time, from the publish call's inputs. Your payload is delivered content: in raw mode the whole object is the body, so the string you wrote for the subject appears inside the email text, one field among the rest. Renaming the key, changing its case, or nesting it deeper changes nothing, because no component on the path reads payload keys as email semantics.

Treat the delivered email from the raw test as your baseline: default subject, body equal to the published payload. That baseline is already a complete working delivery path, so judge every later change against it rather than against a suspected transport fault.

Why does the email stop arriving after I switch the message to JSON? #

Switching to JSON mode sets the MessageStructure parameter to json, and SNS then reads the message as its documented protocol-keyed structure rather than as free text; a payload keyed by subject and message lacks the required fallback entry, so the publish fails before any email is generated.

The documented requirement is strict: with MessageStructure set to json, Message must be a JSON object whose entries name delivery protocols, with one fallback entry every protocol can use; per-protocol entries then override that fallback for their own transport. Your alarm object, keyed by subject and message, has no protocol entries at all, so the structure check fails and the publish is rejected. The email is not lost on the way to the mailbox — it is never generated.

The reported symptom, silence after the JSON switch, matches a rejected publish exactly. Check the rule's error diagnostics instead of the mailbox: a publish rejection shows there, while everything after a successful publish looks normal even when no email exists yet.

Note the ceiling of that structure even when it is correct: its entries carry per-protocol message text only, never a subject value, so a perfectly formed object would still leave the subject at the default. For a single email audience, leave MessageStructure unset and publish plain text; the JSON structure pays for itself only when one publish must carry different text per transport.

How do you get a custom subject without breaking delivery? #

Publish to SNS only from a step that exposes the Subject parameter — from the Node-RED host itself when it holds secure AWS credentials, or from a server-side function the rule invokes when MQTT must stay the device transport; keep the direct action only if the default subject is acceptable.

Route Path Where the subject is set Choose it when
Keep the rule action unchanged Node-RED → MQTT → AWS IoT → SNS action → email nowhere; the default subject stands the default subject is acceptable
Publish from the Node-RED host Node-RED → SNS Publish → email the Subject input beside the Message input the host runs an AWS identity scoped to publishing, and your SNS integration exposes a subject input
Server-side publisher behind the rule Node-RED → MQTT → AWS IoT → publisher function → SNS Publish → email the function maps event fields onto Subject and Message MQTT stays the device-facing transport and publish rights stay off the Node-RED host

For the alarm flow as reported, add the server-side publisher: the rule already fires, so the only change is its routing target, and SNS publish permissions never reach the Node-RED host. Publish directly from Node-RED when that host already runs a tightly scoped AWS identity and your installed SNS integration exposes a subject input; it is one hop shorter.

Keep AWS credentials out of MQTT payloads and exported flows: the publisher function should carry its publish-only permission to the one topic in its own execution identity, never as message data or a pasted flow snippet.

Which hop should you check before changing anything? #

A working raw-mode email proves every hop after the MQTT publish — rule match, SNS action, subscription, mailbox — so a subject-only fault almost never lives in cabling, broker ports or subscriptions; confirm the payload reaches AWS IoT unchanged and then change code, not infrastructure.

  1. Sensor into Node-RED: the measured value changes and crosses the configured temperature limit, so the alarm event actually fires.
  2. Node-RED into AWS IoT: the published payload arrives byte-for-byte as configured. If nothing arrives at all, that is a connection fault, not a subject fault — Fix a PLC MQTT client that never reaches your broker covers it. If the payload arrives with stray or shifted characters, fix the encoding first, as in Fixing extra characters in a PLC MQTT JSON payload.
  3. Rule to action: the rule matches, the action fires, and the error diagnostics stay clean.
  4. Action to SNS: in raw mode the publish is accepted; in JSON mode this is the hop where the rejection happens.
  5. SNS to mailbox: read the delivered email's subject and body from the message headers, not from the preview pane.

Read broker address, port and topic from the deployed configuration and keep them identical across the raw and JSON tests, so the comparison isolates message handling and nothing else.

What limits apply once the publish path works? #

The default Publish size ceiling is 256 KiB per message, so a normal alarm payload is never the constraint; what decides the email is message structure and, for the subject line, the length and character constraints documented with the Subject parameter.

Worked example, using the warning payload from the reported flow:

{"subject":"Warning message","message":"The temperature has reached 30deg"}

Counted as bytes: 1 for the opening brace, 9 for "subject" with its quotes, 1 for its colon, 17 for "Warning message" with its quotes, 1 for the comma, 9 for "message" with its quotes, 1 for its colon, 35 for the warning sentence with its quotes, and 1 for the closing brace — 1+9+1+17+1+9+1+35+1 = 75 bytes. The default ceiling is 256 KiB, and 256 × 1024 = 262,144 bytes, so the payload uses 75 ÷ 262,144 ≈ 0.0003 of it, about 0.03 percent. Size is never why the email disappears: the same 75 bytes deliver in raw mode and are rejected in JSON mode, because the object's keys are not the protocol entries the structure requires.

The Subject input carries its own documented constraints, a length ceiling and character restrictions, published alongside Message and MessageStructure on the same API reference page. Keep alarm subjects short, plain and free of formatting characters, and hold the final wording against those limits before the first production send.

How do you verify the new subject without duplicate emails? #

Verify the boundaries one at a time: an accepted MQTT publish proves the MQTT hop, an accepted Publish call proves SNS accepted the request, and only the delivered email's subject line proves the fix — disable the old direct action first so one event cannot travel both routes.

  1. Record the baseline: save the Node-RED flow, the IoT rule, and one delivered raw-mode email with its default subject.
  2. Disable the old direct-to-SNS action before enabling the new route, so a single event cannot travel both paths.
  3. Publish one controlled test event carrying the subject string and the warning text as two payload fields; confirm the rule forwards both unrenamed and unnested.
  4. Confirm the outgoing Publish call carries Subject and Message as two separate inputs, not as one combined text.
  5. Read the delivered email: the subject line equals your string and the body equals the warning text. An accepted publish response with no email arriving points at the subscription or the mailbox, not at the subject mapping.

A level-based trigger publishes on every reading above the limit, so a long warm period produces a stream of identical emails. One email per threshold crossing needs transition logic on the Node-RED side, publishing on the flip rather than on every qualifying reading.

Questions asked

Does the Publish Subject parameter affect anything besides email?

Its documented purpose is the subject line for deliveries to email endpoints. Transports without a subject concept receive the message text without it. Fill it whenever the topic serves an email subscription; where only non-email transports consume the topic, the message body alone carries everything you need.

When is the SNS JSON message structure the right choice?

MessageStructure set to json exists for one publish that must carry different text per transport protocol: each entry in the object names a delivery protocol, and a fallback entry covers every protocol without its own text. A single-audience email alarm gains nothing from it, so publish plain text instead.

How do I send one email per threshold crossing instead of one per reading?

Make the Node-RED logic edge-triggered: store the previous comparison result, for example in flow context, and publish only when it changes from below the limit to at or above it. A level-based rule publishes on every qualifying reading, so a warm period that lasts hours would send an email per scan interval.

Can the Node-RED host stay free of SNS permissions entirely?

Yes, and that is the server-side publisher route: Node-RED keeps publishing MQTT only, the IoT rule hands the event to a publisher function, and that function's execution identity is the only principal allowed to publish to the SNS topic. The Node-RED host then holds no credentials capable of sending email.

Keep reading

  • How-to

    How Sparkplug UDT definitions reach MQTT Engine

    A UDT definition is not a file you import: it is a Template metric with isDefinition true published in the NBIRTH, and each DBIRTH instance binds to it by an exact-name templateRef. Build the births in Node-RED or on the Eclipse Tahu Node.js client, then verify the definition and the instance in the MQTT Engine tag provider.

    Edge computing and IIoT

  • How-to

    Bridge ScadaBR data to MQTT through Node-RED

    In this ScadaBR 1.2 design nothing on the ScadaBR side speaks MQTT, so Node-RED bridges both directions: the HTTP Sender passes point values as GET parameters to a /nodered HTTP input, a switch on msg.parts.key publishes them to topics BIN, INT and FLOAT, and a join feeds them back as GET query parameters to the HTTP Receiver at /ScadaBR/httpds. Match the BIN, INT and FLOAT names everywhere.

    Edge computing and IIoT

  • Troubleshooting

    Fixing extra characters in a PLC MQTT JSON payload

    The extra characters come from publishing a UTF-16 WSTRING to a subscriber that reads UTF-8, and from sending SIZEOF bytes of the allocated buffer instead of the text. Convert the finished JSON with JSON.Stu.ConvertUTF16toUTF8 into a STRING(2000), then publish TO_UDINT(JSON.Stu.StrLenA(ADR(utf8JsonData))) bytes. Keep the MQTT 5 properties; they declare UTF-8 but convert nothing.

    Edge computing and IIoT