MonkeyBonkey
MonkeyBonkey

Reputation: 47911

example of params for publishing to an amazon sns topic using node.js

I'm trying to follow along the amazon sns publish example using the Amazon documentation site but it's vague on Message, MessageAttributes and MessageStructure.

First of all, is the Message property going to be a string even if you set MessageStructure to json? e.g. If I want to send an object instead of just a string message. If it's string - do I need to JSON.stringify my object before passing it as a Message property?

http://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/SNS.html#publish-property

Should I be doing this using MessageAttributes instead? What is that property - the amazon documentation merely states it "Message attributes for Publish action" which seems like a tautology.

http://docs.aws.amazon.com/sns/latest/APIReference/API_Publish.html

Upvotes: 3

Views: 3194

Answers (1)

Michael - sqlbot
Michael - sqlbot

Reputation: 179364

Setting MessageStructure to json is only used if you are going to send a json-formatted message structure to SNS in the specific jormat SNS understands. This is only used when you are publishing to multiple endpoint types and want to vary the message body by endpoint type. This isn't the same as "I want to send a message where the body has been serialized as JSON."

If you are sending "a JSON object," you need to stringify it, and send it just as you would any other (non-JSON) messages, because SNS messages are, fundamentally, strings.

MessageAttributes are something else entirely. They allow you to send pseudo-out-of-band key/value pairs along with your message, which can be useful for example if your message has been gzipped and base64 encoded (again, for example) you could attach an "external_id" attribute that the recipient could evaluate to decide whether it needed to unpack the whole message or could just discard it.

Upvotes: 2

Related Questions