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!

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠