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 個回答
1
已接受的答案

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
已回答 2 年前
  • This answer worked! Thank you for the help!

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南