Přeskočit na hlavní obsah

Node-RED + AWS SNS: Setting TopicArn for the Publish Node via a Change Node

·3 min

I wanted to publish a message to an AWS SNS topic from a Node-RED flow using node-red-contrib-aws. The SNS Publish node itself has no field anywhere in its editor to pick or type a topic — no “Topic ARN” box, nothing. I spent a while looking for it before realizing the node simply doesn’t have one, and the value has to arrive on the message instead.

The problem #

node-red-contrib-aws nodes are thin wrappers around the AWS JavaScript SDK — the node’s editor only exposes the shared AWS config (credentials/region), and everything specific to the actual API call is expected to already be present on msg when the message reaches the node. For SNS Publish, that means the SDK’s TopicArn parameter has to be set as msg.TopicArn before the message gets there. There’s no config field for it because the node isn’t meant to have one — the whole node category works this way, passing SDK parameters straight through from the message.

Here’s the SNS Publish node’s entire editor — AWS config, Operation, Name, Message. No topic field anywhere:

SNS Publish node editor with no Topic ARN field

That’s not obvious from the node’s editor UI, and the node’s own documentation doesn’t spell it out either, which is what made this harder to find than it should have been.

The fix: a Change node in front of SNS Publish #

Add a Change node right before SNS Publish, and set msg.TopicArn to the topic’s ARN:

Change node setting msg.TopicArn before the SNS Publish node

Set  msg.TopicArn  to the value  arn:aws:sns:us-east-1:<account-id>:<topic-name>

Flow layout:

[change: set msg.TopicArn] → [SNS Publish]

The message body to publish goes on msg.payload as usual — the SNS Publish node reads that as the SDK’s Message parameter. TopicArn is the one piece that has no equivalent editor field, so it’s the one piece that has to be injected onto the message manually.

Why this happens #

node-red-contrib-aws node docs mention that if msg.AWSConfig is set, it overrides the node’s own configured credentials — which confirms the general pattern: these nodes let the message carry SDK parameters that the node itself doesn’t expose in its editor, on top of whatever is configured statically. TopicArn for SNS Publish is just one instance of that same pattern, and in this node it happens to be the only way to set the topic — there’s no static alternative in the config panel at all.

Takeaway #

If a node-red-contrib-aws node is missing a field you’d expect from the underlying AWS API, check the AWS JavaScript SDK docs for that operation’s parameter name, then set it on msg with a Change node ahead of the AWS node — rather than assuming the parameter isn’t supported.