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!

ログインしていません。 ログイン 回答を投稿する。

優れた回答とは、質問に明確に答え、建設的なフィードバックを提供し、質問者の専門分野におけるスキルの向上を促すものです。

質問に答えるためのガイドライン

関連するコンテンツ