1

I'm trying to filter based on metadata values of incoming SQS events, not what is in their body.

From the documentation, it is mentioned that there is a messageAttributes attribute. I want to filter based on what is inside that value. However, I can't get it to work. I've even tried something like the following to test filtering on metadata:

[
  {
    "Pattern": "{\"MessageId\":[{\"anything-but\":[\"Raining\"]}]}"
  }
]

Which should always match.

Something to note is that the documentation uses camelCase for the attribute names, but when I pull a message using the cli, I see the attribute in PascalCase. I've tried both variants and still don't get a match.

Is it possible to match based on what is inside messageAttributes? Is there an easier way to debug the filter expression?

Thanks!

1
  • Looks like it is possible to filter on metadata: docs.aws.amazon.com/lambda/latest/dg/…: "Your filter pattern can include metadata properties, data properties, or both." Commented Dec 15, 2025 at 15:05

1 Answer 1

0

You cannot filter on messageId.

AWS does not allow event source mapping filters on messageId, receiptHandle, or anything outside messageAttributes or body.

That field exists only in the delivery envelope, not the filterable payload.

If you control the producer:

SendMessage({
  MessageBody: "...",
  MessageAttributes: {
    logicalId: {
      DataType: "String",
      StringValue: "Sunny"
    }
  }
});

Then filter:

{
  "messageAttributes": {
    "logicalId": {
      "stringValue": [
        { "anything-but": "Raining" }
      ]
    }
  }
}

This is the only way to do metadata-based filtering cleanly.

Otherwise, FIFO queues may have the dedupe ID or you may have to fallback to undesirably filtering via the Lambda.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.