Possible bug with SQS Lambda consumer and filters?

1

I have configured a queue with a lambda consumer. The Lambda trigger is configured with a filter to process only certain messages from the queue:

"FilterCriteria": {
  "Filters": [
    {
      "Pattern": "{\"body\":{\"action\":[\"sample1\"]}}"
    }
  ]
}

When sending a message matching the filter to the queue, no problem, the message gets comsumed by the lambda function and is removed from the queue.

When sending a message not matching the filter {"action":"testing"}, the message isn't consumed by the lambda function (this is expected), but the message is deleted from the queue and no more available for any other consumer.

This gets even worse when we configure a maxConcurrency for the Lambda function: Lambda will consume some of the message and some messages (matching the filter) won't be consumed and will still be deleted in SQS.

Did I stumble upon a bug, or did I miss something in how the filter is supposed to work?

Thanks, Daniel

profile picture
질문됨 일 년 전646회 조회
1개 답변
1
수락된 답변

First of let us understand one lambda event filters is not designed to filter same message multiple times and after every successful single/batch invocation the messages are cleared unless you explicitly delete them if there is an abrupt error handling.

This is needed to avoid reprocessing the unmatched messages again and it may clog your batch size and the lambda filter runs endlessness not finding suitable records to process in the head.

Then why do we have this filter you may ask, this is to make sure we are processing the right message saving our compute time and space. Since SQS could not filter by itself.

Also SQS is more suitable for one consumer kind architecture, if you would like to have another consumer it is better to have multiple SQS queues.

To have separate queue you could initially create an event bridge event with the same payload and then use **event bridge rule **to move the message to right SQS and them use filter pattern with single/batch invocation strategy.

profile picture
답변함 일 년 전
  • In addition to this answer, there is a little sentence in the feature announcement that I missed. It is stated an event/payload not matching any of the filtering criteria will be dropped.

    The behavior is expected and enforces the idea that the purpose of the filter is to process only the wanted messages to reduce unwanted Lambda invocations.

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

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

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

관련 콘텐츠