brefphp / bref

Serverless PHP on AWS Lambda
https://bref.sh
MIT License
3.1k stars 367 forks source link

SNS -> SQS Fanout can't be handled by the SqsConsumer #1636

Closed robinlehrmann closed 1 year ago

robinlehrmann commented 1 year ago

Current Behavior:

The Bref\Event\Sqs\SqsRecord class expects the eventSource of an AWS SNS fanout message to be "aws:sqs," but it is set to "aws:sns" instead because the message was not initiated as part of the SQS queue.

Expected Behavior:

It would be helpful if the SqsRecord class could handle messages with an "eventSource" of "aws:sns" as well, to support AWS SNS fanout to SQS.

Steps to Reproduce:

Set up an AWS SNS topic with fanout to SQS. Send a message to the SNS topic. Attempt to process the message using the SqsRecord class in Bref.

Additional Information:

Include any other relevant information, logs, or context about the issue here.

Environment:

bref/bref: 2.0.11 bref/symfony-bridge: 0.2.2 bref/symfony-messenger: 0.5.4 aws/sdk: 3.275.9

mnapoli commented 1 year ago

Hey, thanks for opening this. That sounds very reasonable!

Happy to merge a PR that solves this 👍

robinlehrmann commented 1 year ago

Hello @mnapoli to ne honest, it was a mistake on my side 😅.

My problem was that I was confused that I received messages with the eventSource: aws:sns even if I expect aws:sqs. After taking a look in the aws console, I recognized that I attached not only the SQS queue to the SNS queue... The lambda was also attached to the SNS directly accidentally. So this exception in your code is correct.

What I maybe can do is, that I can change the exception message to a specific one if this occurs, that other developers get this as an error and don't get confused, what do you think :) ?

mnapoli commented 1 year ago

Ohh very interesting, yes that sounds like a good idea if it's doable 👍

robinlehrmann commented 1 year ago

Hi @mnapoli I created a POC merge request #1641 maybe you can take a look if you have time, two tests are still failing, but just to show you first how I thought to help other developers with it :) what do you think?