SNS serialized JSON Message only shows "default"

0

Hi, I have a lambda that inserts a message into a SNS Topic. The topic then gets pushed to a subscribed SQS queue, and triggers a lambda to process and send out an SES email.

ISSUE: After the message goes through SNS and SQS and arrives at the lambda trigger, the "Message" property does not contain the full serialized JSON string, it gets cut/formatted. I've tried many variations of the below, including this conversation that goes back to 2014 here: https://github.com/aws/aws-sdk-js/issues/262

Topic Message Parameters being inserted into SNS:

var params = { TopicArn: "...", MessageStructure: "json", Message: JSON.stringify({ default: "I am the default", info: JSON.stringify({data: { message: "hello 123"} }) }), MessageGroupId: "PID-112" };

MESSAGE BODY AFTER GOING THROUGH SNS/QUEUE:

Records: [ { messageId: '...', receiptHandle: '...', body: '{\n' + ' "Type" : "Notification",\n' + ' "MessageId" : "...",\n' + ' "TopicArn" : "arn:aws:sns:...",\n' + ' "Message" : "I am the default",\n' + ' "Timestamp" : "2022-07-07...",\n' + ' "UnsubscribeURL" : "...' + '}', attributes: [Object], messageAttributes: {}, eventSource: 'aws:sqs', eventSourceARN: 'arn:aws:sqs:...', } ]

Thanks, TS

1 Answer
1
Accepted Answer

The Message property can be a text to send a message to all transport protocols, or a json to send different text for each transport protocol when you set the property MessageStructure to json. See the Publish API.

If you don't define a property for a specific protocol, the information in the default property is used. As you are sending to SQS, only the information in the default property is being sent and the info property doesn't map to any transport protocol, so it isn't sent.

For your use case, don't sent the MessageStructure and remove the in object JSON.stringify, as:

var params = { TopicArn: "arn:aws:sns:us-east-1:321363201397:sendNotification.fifo", Message: JSON.stringify({ default: "I am the default", info: {data: { message: "hello 123"} } }), MessageGroupId: "PID-112" };
profile pictureAWS
Eduardo
answered 2 years ago
  • This answer worked! Thank you for the help!

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions