8000 fix message retry in lambda SQS event source mapping by thrau · Pull Request #6603 · localstack/localstack · GitHub
[go: up one dir, main page]

Skip to content

fix message retry in lambda SQS event source mapping #6603

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Aug 8, 2022

Conversation

thrau
Copy link
Member
@thrau thrau commented Aug 5, 2022

This PR fixes how the SQS event source listener deals with DLQs and retry intervals.

There was some very old code left from #1973 that implemented logic that would, for SQS triggered lambdas, put messages into a DLQ manually. This logic is not needed since SQS puts messages into a DLQ automatically when it's being polled (which the event source listener does). I removed all of that code, since it is all handled implicitly in our SQS provider.

For testing I created two new tests that test the basic behavior (which replace the defunct test i removed), and retry with a DLQ (which was the original goal for #5283). The SQS event source mapping does not support DestinationConfig, meaning you can't make async lambdas triggered by SQS messages also send lambda results to SQS queues 🤷. But I needed that to write proper tests, so I wrote a simple new lambda for testing that takes as input a destination queue URL to which the lambda will echo the incoming event.

The sqs_api() transformer was causing issue because sometimes the SenderId is the same as the account ID, but not always, so I exposed _resource_name_transformer through the transformer util so i can build some custom transformations. happy to revise that.

I'll raise a follow-up PR to move the other lambda/sqs integration tests scattered throughout different tests into the new test_lambda_sqs_integration.py.

10000
@thrau thrau temporarily deployed to localstack-ext-tests August 5, 2022 21:33 Inactive
@thrau thrau force-pushed the fix-lambda-sqs-eventsource-mapping branch from 2f4092e to 4d2095c Compare August 5, 2022 21:34
@thrau thrau temporarily deployed to localstack-ext-tests August 5, 2022 21:35 Inactive
@github-actions
Copy link
github-actions bot commented Aug 5, 2022

LocalStack integration with Pro

       3 files  ±0         3 suites  ±0   1h 21m 50s ⏱️ + 18m 37s
1 176 tests +1  1 133 ✔️ ±0  43 💤 +1  0 ±0 
1 541 runs  +5  1 467 ✔️ +4  74 💤 +1  0 ±0 

Results for commit 818d70d. ± Comparison against base commit 5c77d19.

♻️ This comment has been updated with latest results.

@thrau thrau temporarily deployed to localstack-ext-tests August 6, 2022 19:27 Inactive
@thrau thrau marked this pull request as ready for review August 6, 2022 20:01
@coveralls
Copy link
coveralls commented Aug 6, 2022

Coverage Status

Coverage decreased (-0.01%) to 91.61% when pulling 818d70d on fix-lambda-sqs-eventsource-mapping into 5c77d19 on master.

@thrau thrau temporarily deployed to localstack-ext-tests August 7, 2022 12:13 Inactive
@thrau thrau temporarily deployed to localstack-ext-tests August 7, 2022 16:18 Inactive
Copy link
Member
@dominikschubert dominikschubert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some minor nits and one remark that might at least for localstack scope not actually be an issue (long vs. short polling).

It's a pity we can't use destinations for every lambda integration to keep track of successful and failed invocations 😕
Still I think the tests seem fairly robust (though I'm not sure if ApproximateReceiveCount might be flaky against AWS?) and the pattern that the lambda itself calls the queue and sends results this way, doesn't seem too weird to me. But maybe that's also just because I was working with this in the past where that was basically the only option 😉

In the future I think it would be interesting to see if we can instrument the test lambdas via the Extensions API and setup some sort of reusable reporting architecture that works on both AWS and localstack to keep track of successful and failed invocations.

💯 for removing legacy code from the event source listeners 😁

🚀

Comment on lines +60 to +65
result = sqs_client.receive_message(
QueueUrl=queue_url,
AttributeNames=["All"],
MessageAttributeNames=["All"],
MaxNumberOfMessages=batch_size,
)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not 100% sure but I think this needs to have a value set for WaitTimeSeconds since per default the SQS poller uses long polling (for non-FIFO queues at least) according to https://docs.aws.amazon.com/lambda/latest/dg/with-sqs.html#events-sqs-scaling

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In localstack that might not be particularly relevant though because AFAIK we don't differentiate between short and long polling anyway.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

totally agree. unfortunately we can't block here because of the way the loop is structured. see comment here: #5042 (comment)

that would require a thread per event-source-mapping, which again requires a different interface for the event source listener (adding/removing mappings). i'd love to do that as part of the lambda rework.

Co-authored-by: Dominik Schubert <dominik.schubert91@gmail.com>
@thrau thrau temporarily deployed to localstack-ext-tests August 8, 2022 19:38 Inactive
@thrau thrau merged commit 7888656 into master Aug 8, 2022
@thrau thrau deleted the fix-lambda-sqs-eventsource-mapping branch August 8, 2022 21:33
@localstack localstack locked and limited conversation to collaborators Aug 8, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

bug: RedrivePolicy is not respected for SQS and Lambda integration
3 participants
0