-
Notifications
You must be signed in to change notification settings - Fork 1k
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
[proposal] Add support for SQS event source #884
Comments
My first thought on seeing both SNS and SQS support was deployment. In a SAM template, I can add CF resources and reference them, e.g. have the queue created as part of the stack or import a value from another stack. Is this the intent of managed resources here? |
@jamesls this looks fine, especially since it looks like users will most likely get multiple messages in one event. The only other thing that I wonder is if we want the top-level |
I have an implementation of this proposal and I've noticed one thing that might be problematic. As far as I can tell, if you have a batch size of more than 1, then the entire batch succeeds (and all the messages are deleted) or the entire batch fails if an exception is raised. I don't see any way to handle partial failures of the message batch. If that's the case then I've been experimenting with abstractions that could handle partial failures but none of them are that great. It seems like we should provide some way for a user to say that an individual message was successfully handled. No matter what we still need to raise an exception to let lambda know not to delete messages which I prefer not to do. I suppose this could be an additive thing later, but I wonder how problematic this is going to be. @kadrach You are correct, creating the SNS/SQS resources is part of the managed resources proposal, which we still plan on doing but we wanted to wrap out the event source work first. EDIT: meant to say you're correct, not incorrect. |
@kyleknap both the top level event passed in and each individual record subclass from |
@jamesls sounds good about the I do think it would be nice to have an abstraction to handle partial failures so you can make sure you have seen all of your messages at least once, but I think we should be explicit about it. What abstractions have you been considering? Thinking outloud one option that may be nice to add is support for dead letter queues that way if the entire set of messages fails and gets deleted, they are not gone for good. |
No, that's not the issue I'm getting at. The default behavior now (the comes for free from lambda) is that they either all succeed if your lambda function returns successfully, or the all fail. This means that out of a batch of 10, if I have 9 that I successfully handle, and 1 that fails (and raises an exception to indicate the failure), then I will see all 10 message again. There's never a case where you won't see your messages at least once. The behavior that I want is that if 9 messages succeed and 1 fails, then I should only see the 1 failed message again. The other 9 are deleted.
Can you elaborate on how this is too implicit, my suggestion was to let the user tell us somehow which succeeded and which didn't ("It seems like we should provide some way for a user to say that an individual message was successfully handled.") If a user tells us a message was handled successfully, it seems reasonable they would expect not to see the message again. The thing that I'm not a fan of (and that we can't change) is that an exception must be raised to tell lambda not to delete any messages. I would prefer if we had a way where we didn't have to use exceptions but could let lambda know which ones succeeded and which ones failed. Essentially I want uncaught exceptions to be reserved for cases where things really went wrong. I'd like something more like dynamodb's batch write items (i.e a list of items that succeeded and a list of items that failed). Let me know if I'm still not making sense and I can try to put together a more concrete example. |
FWIW, I have a branch that's working if you want to play around with this feature: https://github.com/aws/chalice/compare/master...jamesls:sqs-events?expand=1. The only functionality missing is SAM support, which should just be a few lines. There's still some things about it that need to be fixed before it's ready for a PR, but it's enough to test out. |
Talked offline about it. The partial failures definitely seems concerning to me. Looks like there is some research we need to do here to figure out what the appropriate behavior should be before we can launch this in chalice. |
After mulling it over for a few days, I don't think we should add any built in support for partial failures just yet. The rationale being:
|
This issue proposes adding support for the newly released sqs event source.
While the implementation will be different, the user facing API is almost identical to the s3 events and sns events we recently added.
app.py changes
First, we'll add an
@app.on_sqs_message
decorator, which takes aqueue
name and an optionalbatch_size
(default is 10, which is the same in the console):Similar to the
topic
arg in the SNS PR, this allows us to eventually add support for Queue URLs and possible queue resources if needed (verified that queue urls and queue names are distinct).In terms of the event object being passed to the handler, it will still inherit from
BaseLambdaEvent
except that it will also be iterable. Because we can now get multiple records in a single event, there's no helpers for accessing just the first record. Each item we iterate over is itself aBaseLambdaEvent
and will have these values:I propose making each item a
BaseLambdaEvent
so you also get ato_dict()
method on each record.Here's what the raw event looks like (showing just a single record but there can be multiple records):
The text was updated successfully, but these errors were encountered: