Can we filter messages from Amazon SQS queue by message attributes?

receiveMessageRequest.MessageAttributeNames = AttributesList;

This tells SQS which message attributes you want it to return with the message if the are present on the message. It is not a message filter. If the attributes aren't present, nothing happens.

But your confusion seems understandable -- it's not actually obvious why the API even has this functionality, though it may be a holdover from when SQS supported only smaller messages than it does today, or it may be so that you can avoid spending any time parsing information from the response that you will end up discarding. I almost always just ask for All.


Please note this regarding messaging services on AWS

SQS : No filtering support ( while picking up messages)

SNS : Supports attributes-based filtering: subscriber can set a subscription attribute (a subscription filter policy) which is applied on incoming messages and only relevant messages can be sent to the subscriber.

EventBridge: Amazon EventBridge supports declarative filtering using event patterns. With event pattern content filtering you can write complex rules that only trigger under very specific conditions. For instance, you might want a rule that will trigger only when a field of the event is within a specific numeric range, if the event comes from a specific IP address, or only if a specific field does not exist in the event JSON.

Please refer my article for a detailed difference between main messaging frameworks on AWS.

https://www.linkedin.com/pulse/mastering-art-decoupling-application-architecture-aws-amit-meena/

enter image description here