How to get AWS Lambda function to push Message Attributes SNS Topic destination

Viewed 172

Scenario: I have a Lambda with a SNS destination. If I "return" an object with property MessageAttributes it gets contained in the "responsePayloadobject which also gets contained into theMessage` object.

I want to return MessageAttributes to the SNS destination from a lambda function.

Example (remember SNS is the destination):

exports.handler =  async function(event, context) {
  
  const topicMsg = {
    Message: "abc1232",
    MessageAttributes: [
      {
        StringValue: "someval",
        DataType: "String"
      }
    ]
  }
  return topicMsg;
}

I have my SNS topic sending EmailJSON and the MessageAttributes is within Message string. I want to be able to have proper MessageAttributes so that I can filter them in the subscription to the topic correctly.

0 Answers
Related